Skip to content

Commit 5579873

Browse files
author
Factory Bot
committed
fix: canonicalize_path for non-existent files
The path canonicalization was inconsistent when a file didn't exist at snapshot time but was created later. Now we canonicalize the parent directory and append the filename, ensuring consistent path lookups across macOS/Windows/Linux.
1 parent 771ba8f commit 5579873

3 files changed

Lines changed: 9614 additions & 1 deletion

File tree

cortex-engine/src/turn_diff_tracker.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,23 @@ impl TurnDiffTracker {
653653
}
654654

655655
fn canonicalize_path(&self, path: &Path) -> PathBuf {
656-
dunce::canonicalize(path).unwrap_or_else(|_| path.to_path_buf())
656+
// Try to canonicalize the full path first
657+
if let Ok(canonical) = dunce::canonicalize(path) {
658+
return canonical;
659+
}
660+
661+
// If that fails (file doesn't exist), canonicalize the parent and append filename
662+
// This ensures consistent paths even for non-existent files
663+
if let Some(parent) = path.parent() {
664+
if let Ok(canonical_parent) = dunce::canonicalize(parent) {
665+
if let Some(filename) = path.file_name() {
666+
return canonical_parent.join(filename);
667+
}
668+
}
669+
}
670+
671+
// Fallback to the original path
672+
path.to_path_buf()
657673
}
658674

659675
/// Find the git worktree root for a path.

0 commit comments

Comments
 (0)