Merge pull request #2 from fungos/linux

Fix broken player if mounted path had a trailing slash.
This commit is contained in:
Antoine Gersant 2017-01-25 21:12:09 -08:00 committed by GitHub
commit 4503ab1ed7
3 changed files with 10 additions and 4 deletions

View file

@ -82,7 +82,7 @@ pub fn get_api_handler(collection: Arc<Collection>) -> Mount {
}
fn path_from_request(request: &Request) -> Result<PathBuf> {
let path_string = request.url.path().join("\\");
let path_string = request.url.path().join(&::std::path::MAIN_SEPARATOR.to_string());
let decoded_path = percent_decode(path_string.as_bytes()).decode_utf8()?;
Ok(PathBuf::from(decoded_path.deref()))
}

View file

@ -196,7 +196,7 @@ fn clean_path_string(path_string: &str) -> path::PathBuf {
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)
path::Path::new(&path_string).iter().collect()
}
#[test]
@ -213,10 +213,14 @@ fn test_clean_path_string() {
assert_eq!(correct_path, clean_path_string(r#"C:/some/path"#));
assert_eq!(correct_path, clean_path_string(r#"C:\some\path"#));
assert_eq!(correct_path, clean_path_string(r#"C:\some\path\"#));
assert_eq!(correct_path, clean_path_string(r#"C:\some\path\\\\"#));
assert_eq!(correct_path, clean_path_string(r#"C:\some/path//"#));
} else {
assert_eq!(correct_path, clean_path_string(r#"/usr/some/path"#));
assert_eq!(correct_path, clean_path_string(r#"/usr\some\path"#));
assert_eq!(correct_path, clean_path_string(r#"/usr\some\path\"#));
assert_eq!(correct_path, clean_path_string(r#"/usr\some\path\\\\"#));
assert_eq!(correct_path, clean_path_string(r#"/usr\some/path//"#));
}
}

View file

@ -7,7 +7,8 @@ use errors::*;
pub fn get_config_root() -> Result<PathBuf> {
if let Ok(mut root) = data_root(AppDataType::SharedConfig) {
root.push("Polaris");
fs::create_dir_all(&root)?;
fs::create_dir_all(&root)
.chain_err(|| format!("opening shared config: {}", root.display()))?;
return Ok(root);
}
bail!("Could not retrieve config directory root");
@ -16,7 +17,8 @@ pub fn get_config_root() -> Result<PathBuf> {
pub fn get_cache_root() -> Result<PathBuf> {
if let Ok(mut root) = data_root(AppDataType::SharedData) {
root.push("Polaris");
fs::create_dir_all(&root)?;
fs::create_dir_all(&root)
.chain_err(|| format!("opening shared data: {}", root.display()))?;
return Ok(root);
}
bail!("Could not retrieve cache directory root");