Use absolute instead of canonicalize for relative root-dir#2008
Merged
thomas-zahner merged 3 commits intolycheeverse:masterfrom Jan 27, 2026
Merged
Use absolute instead of canonicalize for relative root-dir#2008thomas-zahner merged 3 commits intolycheeverse:masterfrom
thomas-zahner merged 3 commits intolycheeverse:masterfrom
Conversation
it's a rare thing but canonicalise replaces all symbolic links with their destinations. this can unexpectedly change the root-dir location, which is a problem given relative link resolution works very much based on location, and users will be expecting that the root-dir they give is the root-dir that is used. in this change, we just have to do a separate check for file existence - canonicalize did that implicitly.
thomas-zahner
approved these changes
Jan 27, 2026
Member
thomas-zahner
left a comment
There was a problem hiding this comment.
Thank you, that's better!
Comment on lines
+78
to
+84
| Some(root_dir) => { | ||
| let root_dir_exists = root_dir.read_dir().map(|_| ()); | ||
| let root_dir = root_dir_exists | ||
| .and_then(|()| std::path::absolute(&root_dir)) | ||
| .map_err(|e| ErrorKind::InvalidRootDir(root_dir, e))?; | ||
| Some(root_dir) | ||
| } |
Member
There was a problem hiding this comment.
Very nitpicky, but I find the mapping to () a bit weird, though I'd also be fine with it.
If you agree we could use the following, otherwise I'm fine with your version.
Suggested change
| Some(root_dir) => { | |
| let root_dir_exists = root_dir.read_dir().map(|_| ()); | |
| let root_dir = root_dir_exists | |
| .and_then(|()| std::path::absolute(&root_dir)) | |
| .map_err(|e| ErrorKind::InvalidRootDir(root_dir, e))?; | |
| Some(root_dir) | |
| } | |
| Some(root_dir) => Some( | |
| root_dir | |
| .read_dir() | |
| .and_then(|_| std::path::absolute(&root_dir)) | |
| .map_err(|e| ErrorKind::InvalidRootDir(root_dir, e))?, | |
| ), |
Member
Author
There was a problem hiding this comment.
Ya it's a bit weird. I like it, though, because it makes it clear that we're ignoring the value of read_dir aside from the error. So the reader of the code doesn't think we're actually reading the directory at this point.
If you chain read_dir directly into and_then, it looks like it's doing something with the result of read_dir.
Member
There was a problem hiding this comment.
True it might be more explicit and obvious
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
it's a rare thing but canonicalise replaces all symbolic links with their destinations. this can unexpectedly change the root-dir location, which is a problem given relative link resolution works very much based on location, and users will be expecting that the root-dir they give is the root-dir that is used.
in this change, we have to do a separate check for file existence - canonicalize did that implicitly.