diff --git a/Cargo.lock b/Cargo.lock index 5242917c02..ad2c783681 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1519,6 +1519,12 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "path-slash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e91099d4268b0e11973f036e885d652fb0b21fedcf69738c627f94db6a44f42" + [[package]] name = "pem" version = "0.8.3" @@ -1964,6 +1970,7 @@ dependencies = [ "num_cpus", "opener", "openssl", + "path-slash", "pulldown-cmark", "rand 0.8.5", "regex", diff --git a/Cargo.toml b/Cargo.toml index 92de5b2882..03a1f849d5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -66,6 +66,7 @@ url = "2.1" wait-timeout = "0.2" xz2 = "0.1.3" zstd = "0.11" +path-slash = "0.2.1" [dependencies.retry] default-features = false diff --git a/src/dist/component/components.rs b/src/dist/component/components.rs index 3d4cc5c3b9..3e93a6d28c 100644 --- a/src/dist/component/components.rs +++ b/src/dist/component/components.rs @@ -5,6 +5,7 @@ use std::path::{Path, PathBuf}; use anyhow::{bail, Result}; +use path_slash::PathBufExt; use crate::dist::component::package::{INSTALLER_VERSION, VERSION_FILE}; use crate::dist::component::transaction::Transaction; @@ -150,8 +151,12 @@ impl ComponentPart { format!("{}:{}", &self.0, &self.1.to_string_lossy()) } pub(crate) fn decode(line: &str) -> Option { - line.find(':') - .map(|pos| Self(line[0..pos].to_owned(), PathBuf::from(&line[(pos + 1)..]))) + line.find(':').map(|pos| { + Self( + line[0..pos].to_owned(), + PathBuf::from_slash(&line[(pos + 1)..]), + ) + }) } } @@ -316,3 +321,18 @@ impl Component { Ok(tx) } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn decode_component_part() { + let part = ComponentPart::decode("dir:share/doc/rust/html").unwrap(); + assert_eq!(part.0, "dir"); + #[cfg(target_os = "windows")] + assert_eq!(part.1, Path::new(r"share\doc\rust\html")); + #[cfg(not(target_os = "windows"))] + assert_eq!(part.1, Path::new("share/doc/rust/html")); + } +}