From f783674682169c4961364acd77912d9acb434844 Mon Sep 17 00:00:00 2001 From: sharkdp Date: Sun, 4 Nov 2018 20:50:10 +0100 Subject: Get size for each path --- src/main.rs | 14 +++++++++++--- src/walk.rs | 20 +++++++++++++++----- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index 1a17a51..61cf6ee 100644 --- a/src/main.rs +++ b/src/main.rs @@ -30,6 +30,11 @@ fn main() { .setting(AppSettings::UnifiedHelpMessage) .version(crate_version!()) .about("Compute disk usage for the current directory") + .arg( + Arg::with_name("path") + .multiple(true) + .help("List of filesystem paths"), + ) .arg( Arg::with_name("threads") .long("threads") @@ -51,9 +56,12 @@ fn main() { .and_then(|t| t.parse().ok()) .unwrap_or(3 * num_cpus::get()); - let root = PathBuf::from("."); - let paths = &[root]; - let walk = Walk::new(paths, num_threads); + let paths: Vec = matches + .values_of("path") + .map(|paths| paths.map(PathBuf::from).collect()) + .unwrap_or(vec![PathBuf::from(".")]); + + let walk = Walk::new(&paths, num_threads); let size = walk.run(); print_result(size); } diff --git a/src/walk.rs b/src/walk.rs index 28a1059..714026d 100644 --- a/src/walk.rs +++ b/src/walk.rs @@ -43,15 +43,19 @@ fn walk(tx: channel::Sender, entries: &[PathBuf]) { } } } - Err(err) => { - tx_ref.send(Message::CouldNotReadDir(entry.clone())).unwrap(); + Err(_) => { + tx_ref + .send(Message::CouldNotReadDir(entry.clone())) + .unwrap(); } } walk(tx_ref.clone(), &children[..]); }; } else { - tx_ref.send(Message::NoMetadataForPath(entry.clone())).unwrap(); + tx_ref + .send(Message::NoMetadataForPath(entry.clone())) + .unwrap(); }; }); } @@ -88,10 +92,16 @@ impl<'a> Walk<'a> { } } Message::NoMetadataForPath(path) => { - eprintln!("diskus: could not metadata for path '{}'", path.to_string_lossy()); + eprintln!( + "diskus: could not metadata for path '{}'", + path.to_string_lossy() + ); } Message::CouldNotReadDir(path) => { - eprintln!("diskus: could not contents of directory '{}'", path.to_string_lossy()); + eprintln!( + "diskus: could not contents of directory '{}'", + path.to_string_lossy() + ); } } } -- cgit v1.2.3