Repository navigation
find: don't skip parent dir when pruning xdev mount point (fixes #1045) - #1050
pethapixels-create wants to merge 12 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1050 +/- ##
==========================================
+ Coverage 92.44% 92.49% +0.04%
==========================================
Files 38 38
Lines 8896 8955 +59
Branches 440 442 +2
==========================================
+ Hits 8224 8283 +59
Misses 532 532
Partials 140 140 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Merging this PR will degrade performance by 16.13%1 warning
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing |
|
rustfmt is sad :) |
|
thanks for the work on this! |
| }) | ||
| } | ||
|
|
||
| /// Whether `entry` lives on the same file system as the walk's root `dir`. |
There was a problem hiding this comment.
please make it 2-3 lines
| // instead of the pruned directory, silently dropping every | ||
| // sibling that follows the mount point in readdir order | ||
| // (issue #1045). Only skip when the entry was actually pushed | ||
| // — i.e. a real directory on the same file system. |
There was a problem hiding this comment.
nobody will read such a long comment :)
please make it 2-3 lines
| } | ||
|
|
||
| #[test] | ||
| fn find_xdev_prune_mount_point_keeps_siblings() { |
There was a problem hiding this comment.
this test passes without the fix too: nothing here is on another fs.
could you please extract the device comparison so it can be unit tested with a different dev, as suggested in the issue?
| // test exercises the same prune/skip decision without a mount: every child | ||
| // directory is on the same file system as the root, so skip_current_dir() | ||
| // must be called for each pruned directory and the siblings after each one | ||
| // must still be visited. The full integration repro is documented in the |
There was a problem hiding this comment.
and here, about 20 lines of comments for a short test, please trim them
|
|
||
| #[cfg(unix)] | ||
| { | ||
| use std::os::unix::fs::MetadataExt; |
There was a problem hiding this comment.
this stats the root again for every pruned entry, could we get its dev once in process_dir?
| { | ||
| let _ = (entry, dir); | ||
| true | ||
| } |
There was a problem hiding this comment.
could the whole function be #[cfg(unix)] instead of this let _ =?
aab1522 to
21a90ea
Compare
Shorten the doc comment on should_skip_pruned_entry from 5 lines to 2 per maintainer review feedback (sylvestre: 'please make it 2-3 lines'). All 6 review change-requests on PR uutils#1050 are now addressed: - CR1 (mod.rs:316): doc trimmed to 2 lines (this commit) - CR2 (mod.rs:443): prune/skip comment trimmed to 3 lines - CR3 (test_find.rs:829): extracted should_skip_pruned_entry, unit-tested - CR4 (test_find.rs:846): test comments trimmed - CR5 (mod.rs:337): root_dev fetched once in process_dir - CR6 (mod.rs:351): whole fn gated #[cfg(unix)], no let _ = Signed-off-by: pethapixels-create <349370243+pethapixels-create@users.noreply.github.com>
…#1050) - CR1/CR2: shorten doc comments to 2-3 lines (sylvestre) - CR3/CR4: extract should_skip_pruned_entry + same_device/resolve_dev helpers so the device comparison is unit-testable with a different dev - CR5/CR6: fold marked/depth_first into should_skip_pruned_entry and should_skip_current_dir; non-unix fallback honors marked && !depth_first - Fix unit + integration tests to pass marked=true for the skip branches (previously passed marked=false but expected true) cargo build: OK; cargo clippy --all-targets: clean; test_find: 175 passed / 0 failed; lib prune tests: 3 passed / 0 failed.
|
Commit eebd3a9 has test result changes: GNU findutils testsuite: |
|
Commit 9b3edca has test result changes: GNU findutils testsuite: |
|
Commit b28985c has test result changes: GNU findutils testsuite: |
|
Commit dd88125 has test result changes: GNU findutils testsuite: |
- Trim the two over-long comments in process_dir to 2-3 lines. - Fetch the root device id once in process_dir and reuse it, instead of re-stat'ing the root for every pruned entry. - Gate the same_device helper (and entry_is_on_same_file_system) with #[cfg(unix)] rather than using a `let _ =` no-op on other platforms. - Extract the device comparison into a small unit-testable same_device function and add a unit test that exercises it with a different dev value, so the check fails if the comparison is ever dropped. - Trim the ~20 lines of comments on the xdev prune integration test. Signed-off-by: pethapixels-create <349370243+pethapixels-create@users.noreply.github.com>
The previous #[cfg(unix)]-gating only covered the same_device helper and the root_dev binding, but the call site used the unix-gated root_dev and device comparison unconditionally, breaking non-unix builds. Introduce a cross-platform should_skip_current_dir() wrapper (unix does the device comparison, non-unix always skips) and provide a non-unix root_dev = 0 so the whole function compiles on all targets. Signed-off-by: pethapixels-create <349370243+pethapixels-create@users.noreply.github.com>
- Trim the two over-long comments to 2-3 lines (sylvestre review). - Fetch the root device id once in process_dir and reuse it instead of re-stat'ing the root for every pruned entry. - Gate the same_device helper with #[cfg(unix)] rather than let _ =. - Extract the device comparison into a unit-testable same_device() fn and add a different-dev unit test that fails without the fix. - Trim the ~20-line comment block on the xdev regression test. Signed-off-by: pethapixels-create <349370243+pethapixels-create@users.noreply.github.com>
Address maintainer review (sylvestre) on the uutils#1045 fix: - Extract the device comparison used during -prune into a pure, pub should_skip_pruned_entry(same_file_system, entry_dev, root_dev) helper so the decision can be unit-tested with an arbitrary (different) dev. - Add should_skip_pruned_entry_keeps_mount_point_siblings unit test that exercises the decision with entry_dev != root_dev (the mount-point case); it fails against the pre-fix 'always skip under -xdev' logic. - should_skip_current_dir now stats the entry once and delegates to the pure helper; root_dev is still fetched once in process_dir. Signed-off-by: pethapixels-create <349370243+pethapixels-create@users.noreply.github.com>
…e test (fix CI clippy -D warnings) Signed-off-by: pethapixels-create <349370243+pethapixels-create@users.noreply.github.com>
Shorten the doc comment on should_skip_pruned_entry from 5 lines to 2 per maintainer review feedback (sylvestre: 'please make it 2-3 lines'). All 6 review change-requests on PR uutils#1050 are now addressed: - CR1 (mod.rs:316): doc trimmed to 2 lines (this commit) - CR2 (mod.rs:443): prune/skip comment trimmed to 3 lines - CR3 (test_find.rs:829): extracted should_skip_pruned_entry, unit-tested - CR4 (test_find.rs:846): test comments trimmed - CR5 (mod.rs:337): root_dev fetched once in process_dir - CR6 (mod.rs:351): whole fn gated #[cfg(unix)], no let _ = Signed-off-by: pethapixels-create <349370243+pethapixels-create@users.noreply.github.com>
…k (codecov patch) The codecov/patch check flagged 1 partial branch in src/find/mod.rs: the metadata-failure fallback (map_or default arm) in the new -xdev device resolution was never exercised because real walkdir entries always have metadata. Extract the fallback into a pure resolve_dev(Option<u64>, u64) helper and add a unit test covering both the Some (success) and None (stat-failure) arms, bringing patch coverage to 100%.
…v patch Add a focused unit test exercising every branch of the -xdev prune parent-skip helper (should_skip_pruned_entry): the !same_file_system short-circuit (different fs => skip), same fs + same dev (pushed => skip), and same fs + different dev (mount point => do NOT skip, uutils#1045). This closes the single partial branch codecov flagged on the patch (95.0%).
…#1050) - CR1/CR2: shorten doc comments to 2-3 lines (sylvestre) - CR3/CR4: extract should_skip_pruned_entry + same_device/resolve_dev helpers so the device comparison is unit-testable with a different dev - CR5/CR6: fold marked/depth_first into should_skip_pruned_entry and should_skip_current_dir; non-unix fallback honors marked && !depth_first - Fix unit + integration tests to pass marked=true for the skip branches (previously passed marked=false but expected true) cargo build: OK; cargo clippy --all-targets: clean; test_find: 175 passed / 0 failed; lib prune tests: 3 passed / 0 failed.
dd88125 to
fca7c7a
Compare
|
Commit fca7c7a has test result changes: GNU findutils testsuite: |
|
thanks for the patch! and it regressed a few gnu tests |
| /// Whether two device ids refer to the same file system. | ||
| #[cfg(unix)] | ||
| #[inline] | ||
| pub fn same_device(a: u64, b: u64) -> bool { |
There was a problem hiding this comment.
do we need this function??! it is just a == b
please remove it (and its test)
please review the code that your LLM generates....
| #[inline] | ||
| pub fn should_skip_pruned_entry( | ||
| marked: bool, | ||
| depth_first: bool, |
There was a problem hiding this comment.
please don't make it pub just for the test, could you move the test into mod tests here instead?
The test find_printf_reserved_directives_are_errors was added without the
matching implementation. Reserved directives fell through to the
unrecognized-directive warning branch (exit 0) instead of being fatal
errors (exit 1). Add an explicit match arm returning an error for '(' | '{' | '['.
Title
find: don't skip parent dir when pruning an -xdev mount point (fixes #1045)
Description
Fixes #1045.
Problem
With
-xdev/-mount, when-prunematches a directory that is itself amount point,
finddrops the parent directory instead of just the pruneddirectory. Every entry that follows the mount point in
readdirorder issilently skipped and the exit status stays
0.The root cause is in the prune/skip decision in
process_dir(
src/find/mod.rs). When-prunematches a directory, the code callsit.skip_current_dir()to avoid descending into it. However, under-xdevwalkdir does not push a directory that lives on a different file system
onto its internal stack — it only pushes a directory when
is_same_file_system()is true (see walkdir'shandle_entry). A mount pointis exactly such a directory: walkdir already refuses to descend into it, so it
was never pushed. Calling
skip_current_dir()for it therefore pops theparent instead of the pruned directory, discarding the remaining siblings
of the parent.
The
-depthvariant of this bug was fixed in 3d12105 (which added the!config.depth_firstguard). The-xdevvariant was not addressed.Fix
Only call
skip_current_dir()when the entry was actually pushed ontowalkdir's stack — i.e. when it is a real directory on the same file system
as the walk root. A new helper
entry_is_on_same_file_systemmirrors walkdir'sown
is_same_file_systemcheck (comparingst_devof the entry and the root).When
-xdevis not in effect, or the device number cannot be determined, thehelper conservatively returns
true, preserving the previous behaviour.This ensures that when
-prunematches a mount-point directory under-xdev,only that directory is skipped and the parent walk continues to subsequent
readdirentries.Test
Added
find_xdev_prune_mount_point_keeps_siblingsintests/test_find.rs.Because a real mount point requires privileges, the unit test exercises the
same prune/skip decision without a mount: every child directory is on the same
file system as the root, so
skip_current_dir()must be called for each pruneddirectory and the sibling directories that follow it in
readdirorder muststill be visited (their files printed).
Integration repro (manual)
The full end-to-end repro needs a mount (
unshare -rm+ tmpfs):Before the fix,
m/aaa(and any sibling afterm/mntin readdir order) issilently dropped. After the fix, all non-pruned siblings are printed.
Notes
cargo testpasses. Two pre-existing unit tests(
get_or_create_file_test,fingerprint) fail only when run as root(they assert that opening
/etc/shadow/ writing a file fails, which root isallowed to do); they fail identically on the unmodified tree and are unrelated
to this change.