Fix windows verbatim paths (#1295)

This commit is contained in:
EgoMoose
2026-07-05 14:26:35 -04:00
committed by GitHub
parent 0289491ccb
commit 7ade19293c
8 changed files with 93 additions and 4 deletions

View File

@@ -72,7 +72,7 @@ pub struct SourcemapCommand {
impl SourcemapCommand {
pub fn run(self) -> anyhow::Result<()> {
let project_path = fs_err::canonicalize(resolve_path(&self.project)?)?;
let project_path = dunce::canonicalize(resolve_path(&self.project)?)?;
log::trace!("Constructing filesystem with StdBackend");
let vfs = Vfs::new_default()?;

View File

@@ -95,8 +95,9 @@ impl ServeSession {
/// currently loaded from the filesystem directly instead of through the
/// in-memory filesystem layer.
pub fn new<P: AsRef<Path>>(vfs: Vfs, start_path: P) -> Result<Self, ServeSessionError> {
let start_path = start_path.as_ref();
let start_time = Instant::now();
let start_path = vfs.canonicalize(start_path.as_ref())?;
let start_path = start_path.as_path();
log::trace!("Starting new ServeSession at path {}", start_path.display());
@@ -240,3 +241,39 @@ pub enum ServeSessionError {
source: anyhow::Error,
},
}
#[cfg(test)]
mod test {
use super::*;
use memofs::StdBackend;
#[test]
fn tree_is_keyed_by_canonical_paths() {
let dir = tempfile::tempdir().unwrap();
std::fs::write(
dir.path().join("default.project.json"),
r#"{ "name": "test", "tree": { "$className": "Folder" } }"#,
)
.unwrap();
// `std::fs::canonicalize` yields a verbatim path on Windows.
// On other platforms it simply resolves the path (e.g. symlinks),
// which the session must also handle.
let start_path = std::fs::canonicalize(dir.path()).unwrap();
let vfs = Vfs::new(StdBackend::new().unwrap());
let session = ServeSession::new(vfs, &start_path).unwrap();
let project_file = start_path.join("default.project.json");
let canonical = session.vfs().canonicalize(&project_file).unwrap();
assert!(
!session.tree().get_ids_at_path(&canonical).is_empty(),
"project file {} should be tracked in the tree under its canonical \
path {}, matching what the watcher reports",
project_file.display(),
canonical.display(),
);
}
}