Open a file from a directory listing named by a relative path - #15
Merged
Conversation
Folding treated a `..` with nothing above it as an error, so `../notes/a.md` did not parse at all -- and a path that will not parse is contained by nothing. Opening a directory the way a person names a sibling, `tread ../notes/`, therefore refused every entry of the listing for escaping a root those entries were plainly inside. A `..` with nothing above it now depends on who is asking. A relative path keeps it, because that is part of what the path names. A rooted one drops it, because nothing is above the root and `/a/../..` is `/`. Joining a link onto a base still refuses outright: walking off the front of the base is exactly what a link leaving the corpus does, and that is the one caller the error was written for.
The climb to a project marker started at the path's parent and walked up with Path::parent, whose answer for `..` is the empty path -- the working directory. So `tread ../thing/` looked for a marker in the directory it had just left, found this project's own, and rooted the listing's corpus at a project the listing was not in. The walk now runs on the path resolved against the cwd, and folded rather than merely joined: `<cwd>/../thing` still holds `<cwd>` as a component, so climbing it arrives back where it started.
A path with no parent fell back to `.`, so `tread /` rooted its corpus at wherever the reader happened to be standing and then refused every entry of `/` for escaping it. Nothing is above a filesystem root: the directory holding it is itself.
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.
tread ../ww-marketing-website/lists the directory, and then every entry ofit fails to open with
link escapes the index root-- with no--indexanywhere in sight.
tread /fails the same way. Three defects stack up toproduce it, and each is a commit.
1. A relative path with
..did not parseplat::pathfolded.and..and treated a..with nothing above it asan error, because that is how a link escaping the corpus is caught. But the
same fold is used to parse a path that is merely written relatively, and
../notes/a.mdnames a real file. It returnedNone,containssaid no, andevery entry of the listing was judged outside a root it was inside.
A
..with nothing above it now depends on who is asking: a relative pathkeeps it, a rooted path drops it (
/a/../..is/), and joining a link ontoa base still refuses -- that caller is the one the error was written for.
2. The project search walked into the working directory
corpus_rootclimbed from the path's parent withPath::parent, whose answerfor
..is""-- the working directory, which is not an ancestor of../elsewhereat all. Run from a project,tread ../thing/found thisproject's
.gitand rooted the listing's corpus at a project the listing wasnot in. The climb now runs on the path resolved against the cwd, folded rather
than joined, since
<cwd>/../thingstill holds<cwd>as a component.3. A filesystem root fell back to
.Path::new("/").parent()isNone, and the fallback wasPathBuf::from("."),so
tread /rooted its corpus at wherever the reader was standing. Nothing isabove a filesystem root: the directory holding it is itself.
Verification
Reproduced first, from the reported command, through a pty:
clippy --all-targets -D warningsclean; all five cross-targets check.src/source/dir/tests.rs(with the cwd deliberately a different project,which is what pins defect 2), and the
..rules per platform insrc/plat/path_tests.rs.walking_off_the_front_is_an_error_not_a_clamppinned the old behaviour and isrewritten rather than deleted: it now asserts that
joinstill refuses anescape, that a rooted path clamps, and that a relative one keeps its
...Found while reading agent trajectories on another branch; this predates that
work and is independent of it.