Skip to content

Commit

Permalink
Avoid skipping the entire directory if a file hits -prune
Browse files Browse the repository at this point in the history
This matches up with the behavior of GNU findutils, as documented in its
man page:

> **if the file is a directory**, do not descend into it

Signed-off-by: Ryan Gonzalez <[email protected]>
  • Loading branch information
refi64 committed Jan 31, 2022
1 parent 78eba7e commit 5f05435
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/find/matchers/prune.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ impl PruneMatcher {
}

impl Matcher for PruneMatcher {
fn matches(&self, _: &DirEntry, matcher_io: &mut MatcherIO) -> bool {
matcher_io.mark_current_dir_to_be_skipped();
fn matches(&self, file_info: &DirEntry, matcher_io: &mut MatcherIO) -> bool {
if file_info.file_type().is_dir() {
matcher_io.mark_current_dir_to_be_skipped();
}

true
}
}
Expand All @@ -46,4 +49,16 @@ mod tests {
assert!(matcher.matches(&dir, &mut matcher_io));
assert!(matcher_io.should_skip_current_dir());
}

#[test]
fn only_skips_directories() {
let abbbc = get_dir_entry_for("test_data/simple", "abbbc");
let deps = FakeDependencies::new();

let mut matcher_io = deps.new_matcher_io();
assert!(!matcher_io.should_skip_current_dir());
let matcher = PruneMatcher::new();
assert!(matcher.matches(&abbbc, &mut matcher_io));
assert!(!matcher_io.should_skip_current_dir());
}
}

0 comments on commit 5f05435

Please sign in to comment.