Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/find/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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();
Expand Down
Loading