Skip to content
Open
Show file tree
Hide file tree
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
10 changes: 10 additions & 0 deletions src/find/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,16 @@ fn process_dir(
matcher: &dyn matchers::Matcher,
quit: &mut bool,
) -> i32 {
// No depth can satisfy both bounds when -mindepth exceeds -maxdepth, so GNU
// find visits nothing at all. walkdir clamps min_depth down to max_depth
// instead (see `WalkDir::min_depth`), which would make us descend anyway, so
// handle the empty traversal ourselves.
if config.min_depth > config.max_depth {
let mut matcher_io = matchers::MatcherIO::new(deps);
matcher.finished(&mut matcher_io);
return matcher_io.exit_code();
}

let mut walkdir = WalkDir::new(dir)
.contents_first(config.depth_first)
.max_depth(config.max_depth)
Expand Down
34 changes: 34 additions & 0 deletions tests/test_find.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1130,6 +1130,40 @@ fn find_ls_unmapped_owner_renders_numeric_id() {
.stdout_contains(unmapped.to_string());
}

#[test]
fn find_mindepth_greater_than_maxdepth() {
ucmd()
.args(&["./test_data/depth", "-mindepth", "2", "-maxdepth", "1"])
.succeeds()
.no_stderr()
.no_stdout();
}

#[test]
fn find_maxdepth_less_than_mindepth_reversed_order() {
ucmd()
.args(&["./test_data/depth", "-maxdepth", "1", "-mindepth", "2"])
.succeeds()
.no_stderr()
.no_stdout();
}

#[test]
fn find_mindepth_greater_than_maxdepth_depth_first() {
ucmd()
.args(&[
"./test_data/depth",
"-mindepth",
"2",
"-maxdepth",
"1",
"-depth",
])
.succeeds()
.no_stderr()
.no_stdout();
}

#[test]
#[cfg(unix)]
fn find_slashes() {
Expand Down
Loading