diff --git a/src/args.rs b/src/args.rs index cc7642b..1801879 100644 --- a/src/args.rs +++ b/src/args.rs @@ -5,6 +5,7 @@ use rayon::ThreadPoolBuilder; use crate::unit::Unit; use std::fs::{symlink_metadata, Metadata}; +use std::os::unix::fs::MetadataExt; use std::path::{Component, Path}; use std::slice::Iter; use std::iter::once_with; @@ -31,7 +32,7 @@ pub struct Args { #[arg( short, long, help = "minimize output", - long_help = "print nothing but the total size for all directories, without a newline. Also supresses all error messages", + long_help = "print nothing but the total size for all directories, without a newline or units. Also supresses all error messages", conflicts_with = "total", default_value_t = false, )] @@ -72,7 +73,7 @@ pub struct Args { #[arg( short, long, help = "unit to print in", - long_help = "printing unit (case insensitive): b = bytes, kb = kilobytes, ki = kibibytes, gb = gigabytes, gi = gibibytes, tb = terabytes, ti = tibibytes", + long_help = "printing unit (case insensitive): b = bytes, kb = kilobytes, ki = kibibytes, gb = gigabytes, gi = gibibytes, tb = terabytes, ti = tibibytes, blk/blks/blck/blcks/block/blocks = file system blocks", value_parser = Unit::parse, default_value_t = Unit::Byte, conflicts_with_all = ["base_two","si"], @@ -129,7 +130,7 @@ pub struct Args { help = "items to summate", action = ArgAction::Append, )] - path: Vec, + paths: Vec, } impl Args { /// utility method to chuck default values on the end. @@ -146,8 +147,8 @@ impl Args { self.exclude_print.clear(); } - if self.path.is_empty() { - self.path = vec![ ".".to_owned() ]; + if self.paths.is_empty() { + self.paths = vec![ ".".to_owned() ]; } ThreadPoolBuilder::new() @@ -158,6 +159,13 @@ impl Args { self } + pub fn len(&self, meta: &Metadata) -> u64 { + match self.unit { + Unit::Blocks => meta.blocks(), + _ => meta.len(), + } + } + pub fn should_exclude(&self, path: &Path, file: &Metadata) -> bool { if !self.follow_links && file.is_symlink() @@ -202,7 +210,7 @@ impl Args { } pub fn paths(&self) -> Iter<'_, String> { - self.path.iter() + self.paths.iter() } } @@ -228,7 +236,7 @@ fn any_pattern_matches_any_component(patterns: &[Pattern], path: &Path) -> bool continue }; let Some(s) = cmp.to_str() else { - // this is a code smell + // TODO: this is a code smell // I don't believe it, but I can't think // of anything worthwhile to do when // you can't get a usable &str