mirror of
https://github.com/bootandy/dust.git
synced 2025-12-12 15:49:58 -08:00
Merge pull request #59 from Celti/exclude-multiple
Allow multiple --ignore-directory flags
This commit is contained in:
@@ -59,6 +59,8 @@ fn main() {
|
|||||||
.short("X")
|
.short("X")
|
||||||
.long("ignore-directory")
|
.long("ignore-directory")
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
|
.number_of_values(1)
|
||||||
|
.multiple(true)
|
||||||
.help("Exclude any file or directory with contains this substring."),
|
.help("Exclude any file or directory with contains this substring."),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
@@ -135,12 +137,12 @@ fn main() {
|
|||||||
|
|
||||||
let use_apparent_size = options.is_present("display_apparent_size");
|
let use_apparent_size = options.is_present("display_apparent_size");
|
||||||
let limit_filesystem = options.is_present("limit_filesystem");
|
let limit_filesystem = options.is_present("limit_filesystem");
|
||||||
let ignore_directory = options.value_of("ignore_directory");
|
let ignore_directories = options.values_of("ignore_directory").map(|r| r.collect());
|
||||||
|
|
||||||
let simplified_dirs = simplify_dir_names(target_dirs);
|
let simplified_dirs = simplify_dir_names(target_dirs);
|
||||||
let (permissions, nodes) = get_dir_tree(
|
let (permissions, nodes) = get_dir_tree(
|
||||||
&simplified_dirs,
|
&simplified_dirs,
|
||||||
ignore_directory,
|
ignore_directories,
|
||||||
use_apparent_size,
|
use_apparent_size,
|
||||||
limit_filesystem,
|
limit_filesystem,
|
||||||
threads,
|
threads,
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ pub fn simplify_dir_names(filenames: Vec<&str>) -> HashSet<String> {
|
|||||||
|
|
||||||
pub fn get_dir_tree(
|
pub fn get_dir_tree(
|
||||||
top_level_names: &HashSet<String>,
|
top_level_names: &HashSet<String>,
|
||||||
ignore_directory: Option<&str>,
|
ignore_directories: Option<Vec<&str>>,
|
||||||
apparent_size: bool,
|
apparent_size: bool,
|
||||||
limit_filesystem: bool,
|
limit_filesystem: bool,
|
||||||
threads: Option<usize>,
|
threads: Option<usize>,
|
||||||
@@ -88,7 +88,7 @@ pub fn get_dir_tree(
|
|||||||
&b,
|
&b,
|
||||||
apparent_size,
|
apparent_size,
|
||||||
&restricted_filesystems,
|
&restricted_filesystems,
|
||||||
&ignore_directory,
|
&ignore_directories,
|
||||||
&mut data,
|
&mut data,
|
||||||
&mut permissions,
|
&mut permissions,
|
||||||
threads,
|
threads,
|
||||||
@@ -118,7 +118,7 @@ fn examine_dir(
|
|||||||
top_dir: &str,
|
top_dir: &str,
|
||||||
apparent_size: bool,
|
apparent_size: bool,
|
||||||
filesystems: &Option<HashSet<u64>>,
|
filesystems: &Option<HashSet<u64>>,
|
||||||
ignore_directory: &Option<&str>,
|
ignore_directories: &Option<Vec<&str>>,
|
||||||
data: &mut HashMap<String, u64>,
|
data: &mut HashMap<String, u64>,
|
||||||
file_count_no_permission: &mut u64,
|
file_count_no_permission: &mut u64,
|
||||||
threads: Option<usize>,
|
threads: Option<usize>,
|
||||||
@@ -130,12 +130,14 @@ fn examine_dir(
|
|||||||
if let Some(threads_to_start) = threads {
|
if let Some(threads_to_start) = threads {
|
||||||
iter = iter.num_threads(threads_to_start);
|
iter = iter.num_threads(threads_to_start);
|
||||||
}
|
}
|
||||||
for entry in iter {
|
'entry: for entry in iter {
|
||||||
if let Ok(e) = entry {
|
if let Ok(e) = entry {
|
||||||
let maybe_size_and_inode = get_metadata(&e, apparent_size);
|
let maybe_size_and_inode = get_metadata(&e, apparent_size);
|
||||||
if let Some(d) = ignore_directory {
|
if let Some(d) = ignore_directories {
|
||||||
if e.path().to_string_lossy().contains(*d) {
|
for s in d {
|
||||||
continue;
|
if e.path().to_string_lossy().contains(*s) {
|
||||||
|
continue 'entry;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user