diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 3823064..9a32958 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -46,7 +46,25 @@ struct DataDirGate { } fn canon_or_raw(p: &Path) -> PathBuf { - fs::canonicalize(p).unwrap_or_else(|_| p.to_path_buf()) + let mut normalized = PathBuf::new(); + for component in p.components() { + match component { + std::path::Component::ParentDir => { + let can_pop = matches!( + normalized.components().next_back(), + Some(std::path::Component::Normal(_)) + ); + if can_pop { + normalized.pop(); + } else if !normalized.has_root() { + normalized.push(component); + } + } + std::path::Component::CurDir => {} + _ => normalized.push(component), + } + } + normalized } /// Exact match against an authorized folder, compared canonicalized so a