From cc4b28780bf03e086b2b634c2e6dd74c4f1622af Mon Sep 17 00:00:00 2001 From: Daniel Hofstetter Date: Fri, 15 Apr 2022 15:26:17 +0200 Subject: [PATCH] df: show error if all types are excluded Fixes #3409 --- src/uu/df/src/df.rs | 3 ++- tests/by-util/test_df.rs | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/uu/df/src/df.rs b/src/uu/df/src/df.rs index ce6804770..b4f3457c4 100644 --- a/src/uu/df/src/df.rs +++ b/src/uu/df/src/df.rs @@ -287,6 +287,7 @@ fn get_all_filesystems(opt: &Options) -> Vec { mounts .into_iter() .filter_map(|m| Filesystem::new(m, None)) + .filter(|fs| opt.show_all_fs || fs.usage.blocks > 0) .collect() } @@ -362,7 +363,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { let filesystems = get_all_filesystems(&opt); if filesystems.is_empty() { - return Err(USimpleError::new(1, "No file systems processed")); + return Err(USimpleError::new(1, "no file systems processed")); } filesystems diff --git a/tests/by-util/test_df.rs b/tests/by-util/test_df.rs index 223dc4efc..ca8296018 100644 --- a/tests/by-util/test_df.rs +++ b/tests/by-util/test_df.rs @@ -1,4 +1,6 @@ // spell-checker:ignore udev pcent iuse itotal iused ipcent +use std::collections::HashSet; + use crate::common::util::*; #[test] @@ -204,6 +206,27 @@ fn test_exclude_type_option() { new_ucmd!().args(&["-x", "ext4", "-x", "ext3"]).succeeds(); } +#[test] +fn test_exclude_all_types() { + let fs_types = new_ucmd!() + .arg("--output=fstype") + .succeeds() + .stdout_move_str(); + let fs_types: HashSet<_> = fs_types.lines().skip(1).collect(); + + let mut args = Vec::new(); + + for fs_type in fs_types { + args.push("-x"); + args.push(fs_type.trim_end()); + } + + new_ucmd!() + .args(&args) + .fails() + .stderr_contains("no file systems processed"); +} + #[test] fn test_include_exclude_same_type() { new_ucmd!()