1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 19:47:45 +00:00

df: show error if specified type doesn't exist

Fixes #3252. As a side effect, "df -H -total" will now fail, too, as
expected.
This commit is contained in:
Daniel Hofstetter 2022-03-21 16:45:30 +01:00
parent 5425b7744e
commit a5477960a5
2 changed files with 36 additions and 10 deletions

View file

@ -358,15 +358,20 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
}
let opt = Options::from(&matches).map_err(DfError::OptionsError)?;
// Get the list of filesystems to display in the output table.
let filesystems: Vec<Filesystem> = match matches.values_of(OPT_PATHS) {
None => get_all_filesystems(&opt),
None => {
let filesystems = get_all_filesystems(&opt);
if filesystems.is_empty() {
return Err(USimpleError::new(1, "No file systems processed"));
}
filesystems
}
Some(paths) => {
let paths: Vec<&str> = paths.collect();
get_named_filesystems(&paths)
}
};
let filesystems = get_named_filesystems(&paths);
// This can happen if paths are given as command-line arguments
// but none of the paths exist.
@ -374,6 +379,10 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
return Ok(());
}
filesystems
}
};
// The running total of filesystem sizes and usage.
//
// This accumulator is computed in case we need to display the

View file

@ -42,6 +42,13 @@ fn test_df_output() {
assert_eq!(actual, expected);
}
#[test]
fn test_total_option_with_single_dash() {
// These should fail because `-total` should have two dashes,
// not just one.
new_ucmd!().arg("-total").fails();
}
/// Test that the order of rows in the table does not change across executions.
#[test]
fn test_order_same() {
@ -89,7 +96,17 @@ fn test_output_option_without_equals_sign() {
#[test]
fn test_type_option() {
new_ucmd!().args(&["-t", "ext4", "-t", "ext3"]).succeeds();
let fs_types = new_ucmd!()
.arg("--output=fstype")
.succeeds()
.stdout_move_str();
let fs_type = fs_types.lines().nth(1).unwrap().trim();
new_ucmd!().args(&["-t", fs_type]).succeeds();
new_ucmd!()
.args(&["-t", fs_type, "-t", "nonexisting"])
.succeeds();
new_ucmd!().args(&["-t", "nonexisting"]).fails();
}
#[test]