From 96ccd56d9c569a31026666713de9ea914c38e58a Mon Sep 17 00:00:00 2001 From: Jorge Polanco <55784702+Jorge-Polanco-Roque@users.noreply.github.com> Date: Mon, 31 Aug 2026 20:45:10 -0600 Subject: [PATCH 1/2] fix(find): output nothing when -mindepth exceeds -maxdepth `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 #778 --- src/find/mod.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/find/mod.rs b/src/find/mod.rs index ff047c82..0cab6e82 100644 --- a/src/find/mod.rs +++ b/src/find/mod.rs @@ -276,6 +276,13 @@ fn process_dir( matcher: &dyn matchers::Matcher, quit: &mut bool, ) -> i32 { + // No depth can be both >= min_depth and <= max_depth when min_depth exceeds + // max_depth, so nothing matches — the same as GNU find. `WalkDir` would + // otherwise still yield the max-depth entries, so short-circuit here. + if config.min_depth > config.max_depth { + return 0; + } + let mut walkdir = WalkDir::new(dir) .contents_first(config.depth_first) .max_depth(config.max_depth) @@ -738,6 +745,29 @@ mod tests { ); } + #[test] + fn find_mindepth_greater_than_maxdepth() { + // -mindepth greater than -maxdepth can never be satisfied, so find + // outputs nothing, matching GNU find (issue #778). + let deps = FakeDependencies::new(); + + let rc = find_main( + &[ + "find", + &fix_up_slashes("./test_data/depth"), + "-sorted", + "-mindepth", + "2", + "-maxdepth", + "1", + ], + &deps, + ); + + assert_eq!(rc, 0); + assert_eq!(deps.get_output_as_string(), ""); + } + #[test] fn find_maxdepth_depth_first() { let deps = FakeDependencies::new(); From e9e78980867c123536c477eaaaa413c6f088f1db Mon Sep 17 00:00:00 2001 From: Jorge Polanco <55784702+Jorge-Polanco-Roque@users.noreply.github.com> Date: Tue, 1 Sep 2026 18:36:08 -0600 Subject: [PATCH 2/2] test(find): add integration test for -mindepth exceeding -maxdepth Signed-off-by: Jorge Polanco <55784702+Jorge-Polanco-Roque@users.noreply.github.com> --- tests/test_find.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/test_find.rs b/tests/test_find.rs index b9c73d5f..b1cfc2b3 100644 --- a/tests/test_find.rs +++ b/tests/test_find.rs @@ -169,6 +169,16 @@ fn depth_rejects_signed_value() { } } +#[test] +fn mindepth_exceeds_maxdepth_outputs_nothing() { + // When -mindepth is greater than -maxdepth no entry can match, so find + // prints nothing and exits successfully, matching GNU find. + ucmd() + .args(&["./test_data/simple", "-mindepth", "2", "-maxdepth", "1"]) + .succeeds() + .no_stdout(); +} + #[test] fn multiple_matcher_failure() { ucmd()