Handle running with bad parameter

Earlier refactor caused running with: 'dust -' to crash
This commit is contained in:
andy.boot
2020-03-28 15:40:33 +00:00
parent 402a8f8249
commit c0048b2ae4
2 changed files with 17 additions and 5 deletions
+9 -5
View File
@@ -12,11 +12,15 @@ fn get_block_size() -> u64 {
#[cfg(target_family = "unix")]
pub fn get_metadata(d: &DirEntry, use_apparent_size: bool) -> Option<(u64, Option<(u64, u64)>)> {
use std::os::unix::fs::MetadataExt;
let md = d.metadata().unwrap();
if use_apparent_size {
Some((md.len(), Some((md.ino(), md.dev()))))
} else {
Some((md.blocks() * get_block_size(), Some((md.ino(), md.dev()))))
match d.metadata() {
Ok(md) => {
if use_apparent_size {
Some((md.len(), Some((md.ino(), md.dev()))))
} else {
Some((md.blocks() * get_block_size(), Some((md.ino(), md.dev()))))
}
}
Err(_e) => None,
}
}