Skip to content

fix: relative path handling in canonicalize_path_maybe_not_exists#20

Merged
dsherret merged 5 commits into
mainfrom
canonicalize-relpath
Oct 16, 2025
Merged

fix: relative path handling in canonicalize_path_maybe_not_exists#20
dsherret merged 5 commits into
mainfrom
canonicalize-relpath

Conversation

@magurotuna
Copy link
Copy Markdown
Member

This fixes an issue where canonicalize_path_maybe_not_exists with RealSys failed to handle relative paths when traversing ancestors.

Fixes #19

Changes

  • When a relative path reaches an empty parent during ancestor traversal, now correctly defaults to current directory (.)
  • Removed unnecessary normalize_path preprocessing step
  • Added tests for both in-memory and real filesystem scenarios

Testing

  • Added test_canonicalize_path_maybe_not_exists_in_memory with various relative path cases
  • Added test_canonicalize_path_maybe_not_exists_real using temporary directories and symlinks
  • All tests verify correct path resolution for relative paths not prefixed with ., like d, c/d/e, etc.

@magurotuna magurotuna requested a review from dsherret October 9, 2025 07:15
Comment thread src/fs.rs
path: &Path,
mut path: &Path,
) -> std::io::Result<PathBuf> {
let path = normalize_path(Cow::Borrowed(path));
Copy link
Copy Markdown
Contributor

@dsherret dsherret Oct 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is not normalizing the path anymore going to cause issues? Maybe it should still be normalized when not starting with a .?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think path normalization is done by fs_canonicalize anyway, so doing it would just be a duplicate work. Also as you can see we have tests confirming that paths not starting with . are handled expectedly.
I might be overlooking something though

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you try running all the tests in the CLI repo with this change?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I'll do a CI run and test it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks David!

Copy link
Copy Markdown
Contributor

@dsherret dsherret left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@dsherret dsherret merged commit ef761b3 into main Oct 16, 2025
4 checks passed
@dsherret dsherret deleted the canonicalize-relpath branch October 16, 2025 22:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

canonicalize_path_maybe_not_exists returns NotFound when relative path is given

2 participants