fix: a relative root ending in .. is mis-resolved - #373
Open
VXNCXNX wants to merge 1 commit into
Open
Conversation
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.
A relative root whose last component is
..or.is mis-resolved into a paththat does not exist, so it reports an I/O error and a directory-stat size instead
of traversing.
cwd containing
sub/f(100 b) andg(200 b):Cause
Entry::from_pathsplits a root into the two fieldsEntry::path()laterrejoins, using a different fallback for each half:
Path::file_namereturnsNoneexactly when the last component is.or..,but
Path::parentstill returnsSome. Forsub/..that gives parentsubandfile name
sub/.., and rejoining them producessub/sub/...Two things kept this hidden. An absolute root is unaffected, because
Path::joindiscards the left side when the right side is absolute. And asingle directory root is unaffected, because
duachanges into it beforewalking. It needs a relative root, ending in
..or., alongside anotherroot.
The fix
Split through one helper that keeps the two halves consistent: if the path has
no separable file name, keep it whole as the file name with an empty parent,
which is what the
file_namefallback was already reaching for. Theplatform-specific
from_pathinmacos/mod.rsandwindows.rscarry the sametwo lines and get the same substitution.
Verification
split_root_path_round_trips_through_entry_pathasserts the property directly,that the split rejoins into the original path, over
sub/..,..,.,sub/childandchild, plus an explicit check that an ordinary path stillsplits into parent and name so children stay correctly named.
Reverting only the helper body fails it:
The end-to-end case is in
tests/stateless-journey.shrather than a unit test,deliberately: it needs a working directory, and a test that calls
set_current_dirraces the suite's own helpers. The journey suite runs the realbinary in a
mktemp -dsandbox, and it catches the same mutation independently:cargo test --allis 26 + 73 + 6 + 3 passed, 0 failed. Also green:--no-default-features --features trash-move,cargo check --all-features,cargo check --no-default-features,cargo fmt --check, and the journey suiteexits 0.
Two things worth saying plainly:
cargo clippy -D warningsfails oncrates/dua-lib/src/lib.rswithclippy::err_expect. I verified by stashing that it fails identically onmain, so I left it alone.substitution of the same two expressions, and the helper and its test are
platform-independent, but the platform paths themselves are unexercised by me.
Disclosure: written with AI assistance (Claude Code). I produced the before and after above by running binaries built from each tree, and ran the mutation check and the journey suite myself.