Skip to content

fix(find): output nothing when -mindepth exceeds -maxdepth - #857

Open
Jorge-Polanco-Roque wants to merge 1 commit into
uutils:mainfrom
Jorge-Polanco-Roque:fix/mindepth-exceeds-maxdepth
Open

fix(find): output nothing when -mindepth exceeds -maxdepth#857
Jorge-Polanco-Roque wants to merge 1 commit into
uutils:mainfrom
Jorge-Polanco-Roque:fix/mindepth-exceeds-maxdepth

Conversation

@Jorge-Polanco-Roque

Copy link
Copy Markdown

Fixes #778

Problem

When -mindepth is greater than -maxdepth, find should output nothing (no depth can be both >= mindepth and <= maxdepth), matching GNU find. uutils instead printed the max-depth entries:

$ find . -mindepth 2 -maxdepth 1     # GNU: (nothing)
$ ./find . -mindepth 2 -maxdepth 1   # uutils, before:
./a
./f0

Cause

process_dir passes both bounds to WalkDir::min_depth/max_depth. When min_depth > max_depth, WalkDir does not yield the empty set — it effectively clamps the range and still yields entries at the max depth, so they leak through.

Fix

Short-circuit in process_dir: when config.min_depth > config.max_depth, return early with no output, matching GNU find.

Tests

Adds find_mindepth_greater_than_maxdepth, which asserts empty output for -mindepth 2 -maxdepth 1. It fails without the fix (the max-depth entries are printed) and passes with it. cargo fmt --check and cargo clippy are clean; normal min/max combinations are unaffected.

`find -mindepth 2 -maxdepth 1` printed the max-depth entries instead of
nothing. No depth can satisfy both bounds when min > max, and GNU find
outputs nothing in that case; `WalkDir` clamps the range and still yields the
max-depth entries, so guard `process_dir` to return early.

Adds a regression test (fails without the fix).

Fixes uutils#778
@codecov

codecov Bot commented Sep 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.33%. Comparing base (d6ae4f9) to head (96ccd56).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #857      +/-   ##
==========================================
+ Coverage   92.31%   92.33%   +0.01%     
==========================================
  Files          35       35              
  Lines        7466     7485      +19     
  Branches      388      389       +1     
==========================================
+ Hits         6892     6911      +19     
  Misses        433      433              
  Partials      141      141              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@codspeed-hq

codspeed-hq Bot commented Sep 1, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 20 untouched benchmarks


Comparing Jorge-Polanco-Roque:fix/mindepth-exceeds-maxdepth (96ccd56) with main (d6ae4f9)

Open in CodSpeed

@sylvestre

Copy link
Copy Markdown
Contributor

please add a test in tests/test_find.rs too :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(find): when -mindepth greater than -maxdepth it outputs files, even if must not

2 participants