mirror of
https://github.com/bootandy/dust.git
synced 2026-06-08 11:29:05 +03:00
Handle running with bad parameter
Earlier refactor caused running with: 'dust -' to crash
This commit is contained in:
@@ -12,11 +12,15 @@ fn get_block_size() -> u64 {
|
|||||||
#[cfg(target_family = "unix")]
|
#[cfg(target_family = "unix")]
|
||||||
pub fn get_metadata(d: &DirEntry, use_apparent_size: bool) -> Option<(u64, Option<(u64, u64)>)> {
|
pub fn get_metadata(d: &DirEntry, use_apparent_size: bool) -> Option<(u64, Option<(u64, u64)>)> {
|
||||||
use std::os::unix::fs::MetadataExt;
|
use std::os::unix::fs::MetadataExt;
|
||||||
let md = d.metadata().unwrap();
|
match d.metadata() {
|
||||||
if use_apparent_size {
|
Ok(md) => {
|
||||||
Some((md.len(), Some((md.ino(), md.dev()))))
|
if use_apparent_size {
|
||||||
} else {
|
Some((md.len(), Some((md.ino(), md.dev()))))
|
||||||
Some((md.blocks() * get_block_size(), Some((md.ino(), md.dev()))))
|
} else {
|
||||||
|
Some((md.blocks() * get_block_size(), Some((md.ino(), md.dev()))))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(_e) => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -275,3 +275,11 @@ pub fn test_ignore_dir() {
|
|||||||
let output = str::from_utf8(&output).unwrap();
|
let output = str::from_utf8(&output).unwrap();
|
||||||
assert!(!output.contains("dir_substring"));
|
assert!(!output.contains("dir_substring"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
pub fn test_with_bad_param() {
|
||||||
|
let mut cmd = Command::cargo_bin("dust").unwrap();
|
||||||
|
let stderr = cmd.arg("-").unwrap().stderr;
|
||||||
|
let stderr = str::from_utf8(&stderr).unwrap();
|
||||||
|
assert!(stderr.contains("Did not have permissions for all directories"));
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user