Skip to content

Commit 4fc2e1c

Browse files
committed
fix: strip Windows UNC path prefix in normalize_path
On Windows, fs::canonicalize returns paths with \\?\ prefix which breaks equality comparisons with current_dir(). Strip the prefix after canonicalization.
1 parent 9445684 commit 4fc2e1c

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/smart_defaults.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,19 @@ pub fn normalize_path(path: &Path) -> Result<PathBuf> {
214214

215215
// Try to canonicalize if the path exists
216216
if cleaned.exists() {
217-
fs::canonicalize(&cleaned)
218-
.map_err(|e| anyhow!("Cannot access path {}: {}", cleaned.display(), e))
217+
let canonical = fs::canonicalize(&cleaned)
218+
.map_err(|e| anyhow!("Cannot access path {}: {}", cleaned.display(), e))?;
219+
220+
// On Windows, canonicalize returns UNC paths (\\?\C:\...) — strip the prefix
221+
#[cfg(target_os = "windows")]
222+
{
223+
let s = canonical.to_string_lossy();
224+
if let Some(stripped) = s.strip_prefix(r"\\?\") {
225+
return Ok(PathBuf::from(stripped));
226+
}
227+
}
228+
229+
Ok(canonical)
219230
} else {
220231
// For non-existent paths, just return the cleaned version
221232
Ok(cleaned)

0 commit comments

Comments
 (0)