diff options
author | zjp <jiping_zhou@foxmail.com> | 2023-05-13 11:27:27 +0800 |
---|---|---|
committer | Denis Isidoro <denis.isidoro@uber.com> | 2023-12-10 06:25:29 -0300 |
commit | 13318c449477a7091f4239b2f2403117e33c8dee (patch) | |
tree | 620edf0abd91c12acfe0c08eeb900a3704dd8363 | |
parent | 4d077ba61283cddcf72fd868d8d8c5931313052f (diff) |
Fix multiple paths: define the platform-specific join separator
-rw-r--r-- | src/config/mod.rs | 2 | ||||
-rw-r--r-- | src/filesystem.rs | 17 |
2 files changed, 17 insertions, 2 deletions
diff --git a/src/config/mod.rs b/src/config/mod.rs index 68638cf..b652608 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -70,7 +70,7 @@ impl Config { if p.is_empty() { None } else { - Some(p.join(":")) + Some(p.join(crate::filesystem::JOIN_SEPARATOR)) } }) .or_else(|| self.yaml.cheats.path.clone()) diff --git a/src/filesystem.rs b/src/filesystem.rs index bebe1d8..a53f246 100644 --- a/src/filesystem.rs +++ b/src/filesystem.rs @@ -12,6 +12,13 @@ use std::path::MAIN_SEPARATOR; use walkdir::WalkDir; +/// Multiple paths are joint by a platform-specific separator. +/// FIXME: it's actually incorrect to assume a path doesn't containing this separator +#[cfg(target_family = "windows")] +pub const JOIN_SEPARATOR: &str = ";"; +#[cfg(not(target_family = "windows"))] +pub const JOIN_SEPARATOR: &str = ":"; + pub fn all_cheat_files(path: &Path) -> Vec<String> { WalkDir::new(path) .follow_links(true) @@ -23,7 +30,7 @@ pub fn all_cheat_files(path: &Path) -> Vec<String> { } fn paths_from_path_param(env_var: &str) -> impl Iterator<Item = &str> { - env_var.split(':').filter(|folder| folder != &"") + env_var.split(JOIN_SEPARATOR).filter(|folder| folder != &"") } fn compiled_default_path(path: Option<&str>) -> Option<PathBuf> { @@ -284,4 +291,12 @@ mod tests { assert_eq!(expected, cheats.to_string_lossy().to_string()) } + + #[test] + #[cfg(target_family = "windows")] + fn multiple_paths() { + let p = r#"C:\Users\Administrator\AppData\Roaming\navi\config.yaml"#; + let paths = &[p; 2].join(JOIN_SEPARATOR); + assert_eq!(paths_from_path_param(paths).collect::<Vec<_>>(), [p; 2]); + } } |