Skip to content

Commit

Permalink
Merge pull request #139 from refi64/prune-dirs-only
Browse files Browse the repository at this point in the history
Avoid skipping the entire directory if a file hits -prune
  • Loading branch information
sylvestre authored Jan 31, 2022
2 parents 78eba7e + 5f05435 commit 58070d6
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 58070d6

Please sign in to comment.