summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsharkdp <davidpeter@web.de>2018-11-04 20:50:10 +0100
committersharkdp <davidpeter@web.de>2018-11-04 20:50:10 +0100
commitf783674682169c4961364acd77912d9acb434844 (patch)
tree9c12c68dbea40ec60535c53d3946fc7dea72a4bc
parent85ba887a9ce56c94861cfc60cce6eae90b9f3a79 (diff)
Get size for each path
-rw-r--r--src/main.rs14
-rw-r--r--src/walk.rs20
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
@@ -31,6 +31,11 @@ fn main() {
.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")
.short("j")
@@ -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<PathBuf> = 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<Message>, 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()
+ );
}
}
}