Fixed a bug where most mount directory paths didn't work on Windows

This commit is contained in:
Antoine Gersant 2016-12-17 19:53:50 -08:00
parent 6cd9f94b85
commit 87c4763cd1

View file

@ -192,19 +192,17 @@ impl Config {
}
fn clean_path_string(path_string: &str) -> path::PathBuf {
let separator = regex::Regex::new(r"\\|/").unwrap();
let components = separator.split(path_string).collect::<Vec<_>>();
let mut path = path::PathBuf::new();
for component in components {
path.push(component);
}
path
let separator_regex = regex::Regex::new(r"\\|/").unwrap();
let mut correct_separator = String::new();
correct_separator.push(path::MAIN_SEPARATOR);
let path_string = separator_regex.replace_all(path_string, correct_separator.as_str());
path::PathBuf::from(path_string)
}
#[test]
fn test_clean_path_string() {
let mut correct_path = path::PathBuf::new();
correct_path.push("C:");
correct_path.push("C:\\");
correct_path.push("some");
correct_path.push("path");
assert_eq!(correct_path, clean_path_string(r#"C:/some/path"#));