mirror of
https://github.com/bootandy/dust.git
synced 2026-01-16 14:53:36 -08:00
Feature: Adding file types filter & F flag changed
-t = Show summary of types -e = Filter by regex allows you to specify a file type like -e "\.txt$" Change behaviour of '-f' flag - it now counts only files. Before it counted files & directories. This was needed for compatibility with the new '-e' filter flag
This commit is contained in:
20
src/utils.rs
20
src/utils.rs
@@ -3,12 +3,7 @@ use std::collections::HashSet;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use crate::platform;
|
||||
|
||||
fn is_a_parent_of<P: AsRef<Path>>(parent: P, child: P) -> bool {
|
||||
let parent = parent.as_ref();
|
||||
let child = child.as_ref();
|
||||
child.starts_with(parent) && !parent.starts_with(child)
|
||||
}
|
||||
use regex::Regex;
|
||||
|
||||
pub fn simplify_dir_names<P: AsRef<Path>>(filenames: Vec<P>) -> HashSet<PathBuf> {
|
||||
let mut top_level_names: HashSet<PathBuf> = HashSet::with_capacity(filenames.len());
|
||||
@@ -62,6 +57,19 @@ pub fn normalize_path<P: AsRef<Path>>(path: P) -> PathBuf {
|
||||
path.as_ref().components().collect::<PathBuf>()
|
||||
}
|
||||
|
||||
pub fn is_filtered_out_due_to_regex(filter_regex: &Option<Regex>, dir: &Path) -> bool {
|
||||
match filter_regex {
|
||||
Some(fr) => !fr.is_match(&dir.as_os_str().to_string_lossy()),
|
||||
None => false,
|
||||
}
|
||||
}
|
||||
|
||||
fn is_a_parent_of<P: AsRef<Path>>(parent: P, child: P) -> bool {
|
||||
let parent = parent.as_ref();
|
||||
let child = child.as_ref();
|
||||
child.starts_with(parent) && !parent.starts_with(child)
|
||||
}
|
||||
|
||||
mod tests {
|
||||
#[allow(unused_imports)]
|
||||
use super::*;
|
||||
|
||||
Reference in New Issue
Block a user