Feature/Bugfix: Allow multiple regexs to be used

The -e and -v flags allow multiple values. Before values after the first
were ignored. This change allows the user to specify multiple regexs and
have them all applied.
This commit is contained in:
andy.boot
2021-10-24 10:13:12 +01:00
parent 1b07c3c4f3
commit 9f91d446c1
4 changed files with 40 additions and 32 deletions
+5 -5
View File
@@ -20,8 +20,8 @@ use crate::platform::get_metadata;
pub struct WalkData {
pub ignore_directories: HashSet<PathBuf>,
pub filter_regex: Option<Regex>,
pub invert_filter_regex: Option<Regex>,
pub filter_regex: Vec<Regex>,
pub invert_filter_regex: Vec<Regex>,
pub allowed_filesystems: HashSet<u64>,
pub use_apparent_size: bool,
pub by_filecount: bool,
@@ -90,15 +90,15 @@ fn ignore_file(entry: &DirEntry, walk_data: &WalkData) -> bool {
}
}
// Keeping `walk_data.filter_regex.is_some()` is important for performance reasons, it stops unnecessary work
if walk_data.filter_regex.is_some()
// Keeping `walk_data.filter_regex.is_empty()` is important for performance reasons, it stops unnecessary work
if !walk_data.filter_regex.is_empty()
&& entry.path().is_file()
&& is_filtered_out_due_to_regex(&walk_data.filter_regex, &entry.path())
{
return true;
}
if walk_data.invert_filter_regex.is_some()
if !walk_data.invert_filter_regex.is_empty()
&& entry.path().is_file()
&& is_filtered_out_due_to_invert_regex(&walk_data.invert_filter_regex, &entry.path())
{