Compare commits

...

3 Commits

Author SHA1 Message Date
Aria Desires
8e12163754 more narrow 2025-10-31 11:21:33 -04:00
Aria Desires
5473636256 fix latent bug in MdtestSystem::canonicalize_path 2025-10-23 19:40:58 -04:00
Aria Desires
b96e1b9759 Do not crash if a FileRoot is a symlink 2025-10-23 18:20:39 -04:00
2 changed files with 18 additions and 7 deletions

View File

@@ -190,6 +190,7 @@ impl Files {
let roots = self.inner.roots.read().unwrap();
let absolute = SystemPath::absolute(path, db.system().current_directory());
roots.at(&absolute)
}
@@ -211,7 +212,10 @@ impl Files {
let mut roots = self.inner.roots.write().unwrap();
let absolute = SystemPath::absolute(path, db.system().current_directory());
roots.try_add(db, absolute, kind)
// We need to resolve away symlinks here to avoid getting confused about subdirectories.
let canonicalized = db.system().canonicalize_path(&absolute).unwrap_or(absolute);
roots.try_add(db, canonicalized, kind)
}
/// Updates the revision of the root for `path`.

View File

@@ -1,4 +1,4 @@
use camino::{Utf8Component, Utf8PathBuf};
use camino::{Utf8Component, Utf8PathBuf, Utf8Prefix};
use ruff_db::Db as SourceDb;
use ruff_db::diagnostic::Severity;
use ruff_db::files::{File, Files};
@@ -180,11 +180,18 @@ impl System for MdtestSystem {
.canonicalize_path(&self.normalize_path(path))?;
if let MdtestSystemInner::Os { os_system, .. } = &*self.0 {
// Make the path relative to the current directory
Ok(canonicalized
.strip_prefix(os_system.current_directory())
.unwrap()
.to_owned())
// Make the path relative to the current directory if the path doesn't require
// UNC gunk (`//?/`) to be valid (`strip_prefix` gets really messy otherwise).
if let Some(Utf8Component::Prefix(prefix)) = canonicalized.components().next()
&& let Utf8Prefix::VerbatimDisk(_) = prefix.kind()
{
Ok(canonicalized)
} else {
Ok(canonicalized
.strip_prefix(os_system.current_directory())
.unwrap()
.to_owned())
}
} else {
Ok(canonicalized)
}