Fix panic on inspecting small files

This commit is contained in:
Kevin Liu 2016-10-23 19:10:27 -07:00
parent e0d48f5aca
commit b5cd8615c7
2 changed files with 8 additions and 4 deletions

View file

@ -183,8 +183,9 @@ Send files to the graveyard (/tmp/.graveyard) instead of unlinking them.")
// Print the first few top-level files in the directory
for entry in WalkDir::new(source)
.min_depth(1).max_depth(1).into_iter()
.filter_map(|entry| entry.ok())
.take(FILES_TO_INSPECT) {
println!("{}", entry.unwrap().path().display());
println!("{}", entry.path().display());
}
} else {
println!("{}: file, {}", target,

View file

@ -35,7 +35,10 @@ fn humanize_bytes(bytes: u64) -> String {
let pair = values.iter()
.enumerate()
.take_while(|x| bytes as usize / (1000 as usize).pow(x.0 as u32) > 10)
.last()
.unwrap();
format!("{} {}", bytes as usize / (1000 as usize).pow(pair.0 as u32), pair.1)
.last();
if let Some(p) = pair {
format!("{} {}", bytes as usize / (1000 as usize).pow(p.0 as u32), p.1)
} else {
format!("{} {}", bytes, values[0])
}
}