mirror of
https://github.com/astro/deadnix.git
synced 2024-11-04 00:56:23 +03:00
Update --exclude
option to filter out entire subfolders
Before this change, using `--exclude foobar` would search for the exact PATH `foobar`, which always resulted in false negatives. With this change, both the file `./foobar` and the folder `./foobar/`, including its contents, are filtered out as expected.
This commit is contained in:
parent
dd2d313fde
commit
c756086198
10
src/main.rs
10
src/main.rs
@ -1,7 +1,7 @@
|
||||
use clap::{Arg, ArgAction, Command};
|
||||
#[cfg(feature = "json-out")]
|
||||
use serde_json::json;
|
||||
use std::{fs, collections::HashSet};
|
||||
use std::{fs, collections::HashSet, path::Path};
|
||||
|
||||
mod binding;
|
||||
mod dead_code;
|
||||
@ -122,7 +122,13 @@ fn main() {
|
||||
};
|
||||
let is_included: Box<dyn Fn(&String) -> bool> = if let Some(excludes) = matches.get_many("EXCLUDES") {
|
||||
let excludes = excludes.cloned().collect::<HashSet<String>>();
|
||||
Box::new(move |s| ! excludes.contains(s))
|
||||
Box::new(move |s| {
|
||||
let s = Path::new(s).canonicalize().unwrap();
|
||||
!excludes.iter().any(|exclude| {
|
||||
let exclude = Path::new(exclude).canonicalize().unwrap();
|
||||
s.starts_with(&exclude)
|
||||
})
|
||||
})
|
||||
} else {
|
||||
Box::new(|_| true)
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user