fix(locations): use exact match for root paths in system directory check

path.starts_with(PathBuf::from("C:\\")) returns true for every path
on drive C:, causing OneDrive and other user folders to be flagged as
system directories during location validation.

Extend the root path detection to cover Windows drive roots (C:\) in
addition to the Unix root ("/") already handled. Use d.parent().is_none()
which is true for both Unix "/" and Windows "C:\" — root paths must
match exactly, not via starts_with.
This commit is contained in:
slvnlrt
2026-03-12 22:18:07 +01:00
parent adc2147dcf
commit febe4aa0d3

View File

@@ -83,9 +83,11 @@ impl LibraryQuery for ValidateLocationPathQuery {
tracing::info!("Validating path: {} (depth: {})", path.display(), depth);
tracing::info!("System directories: {:?}", system_dirs);
let is_system_dir = system_dirs.iter().any(|d| {
// Special case: "/" should only match if path IS "/", not if it starts with "/"
// Otherwise every absolute path would be considered a system directory
let matches = if d.to_string_lossy() == "/" {
// Root paths (Unix "/" or Windows "C:\") must match exactly.
// Using starts_with() on a root dir would flag every child path as a
// system directory — e.g. "C:\" would match "C:\Users\alice\OneDrive".
let d_is_root = d.parent().is_none();
let matches = if d_is_root {
path == d
} else {
path.starts_with(d)