fix(find): -mindepth N -maxdepth M with N>M now matches nothing - #821
Open
MsfPablo wants to merge 1 commit into
Open
fix(find): -mindepth N -maxdepth M with N>M now matches nothing#821MsfPablo wants to merge 1 commit into
MsfPablo wants to merge 1 commit into
Conversation
GNU/BSD find semantics: when -mindepth is greater than -maxdepth, no depth satisfies both bounds, so the walk should produce no output. Previously uutils find relied on walkdir's min_depth/max_depth setters, which silently clamp the contradiction (whichever is set last wins). Because process_dir set max_depth before min_depth, '-mindepth 2 -maxdepth 1' was clamped to min_depth=max_depth=1 and wrongly printed depth-1 entries. Add an explicit guard in process_dir that returns early (no output) when config.min_depth > config.max_depth, before constructing the walkdir builder. Fixes uutils#778
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #821 +/- ##
==========================================
+ Coverage 91.93% 91.97% +0.03%
==========================================
Files 35 35
Lines 7251 7286 +35
Branches 378 379 +1
==========================================
+ Hits 6666 6701 +35
Misses 443 443
Partials 142 142 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Commit bf2d93f has test result changes: GNU findutils testsuite: bfs testsuite: |
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.
Fixes #778.
Problem
find <dir> -mindepth N -maxdepth MwithN > Mprinted entries at the smaller depth instead of nothing. Repro (against currentmain, commit1f19cdd):GNU/BSD find print nothing here (no depth is simultaneously
>= Nand<= M):Root cause
process_dirbuilds the walker withwalkdir'smin_depth/max_depthsetters (src/find/mod.rs). Those setters silently clamp the contradiction — whichever is set last wins (walkdirsrc/lib.rs):uutils calls
.max_depth()first, then.min_depth(), so withmax_depth=1, min_depth=2the second call clampsmin_depthdown to1→ the walk yields exactly the depth-1 entries.Fix
Add an explicit guard at the top of
process_dirthat returns early (no output) whenconfig.min_depth > config.max_depth, matching GNU/BSD find. The walkdir builder is left untouched.Verification
cargo build --bin find— cleancargo test— 228 lib tests + integration suites pass (0 failures), including two new regression tests:find_mindepth_greater_than_maxdepth(-mindepth 2 -maxdepth 1)find_mindepth_greater_than_maxdepth_reversed_order(-maxdepth 1 -mindepth 2, both orderings must yield nothing)cargo fmt --check— cleancargo clippy --lib -- -D warnings— cleanfind depth-repro -mindepth 2 -maxdepth 1→ no output, exit 0The existing
find_mindepth/find_maxdepth/find_zero_maxdepthtests continue to pass unchanged.