mirror of
https://github.com/denisidoro/navi
synced 2024-11-21 19:13:07 +00:00
Fix multiple paths: define the platform-specific join separator
This commit is contained in:
parent
4d077ba612
commit
13318c4494
2 changed files with 17 additions and 2 deletions
|
@ -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())
|
||||
|
|
|
@ -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]);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue