From a1aea067272a81a6877e54df8e89945e5cb086e6 Mon Sep 17 00:00:00 2001 From: Ackerley Tng Date: Thu, 28 Jul 2022 21:24:00 -0700 Subject: [PATCH] du: update du to use parse_glob::from_str --- src/uu/du/src/du.rs | 3 ++- tests/by-util/test_du.rs | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/uu/du/src/du.rs b/src/uu/du/src/du.rs index 70549e3348b..3b0aa248af5 100644 --- a/src/uu/du/src/du.rs +++ b/src/uu/du/src/du.rs @@ -37,6 +37,7 @@ use uucore::display::{print_verbatim, Quotable}; use uucore::error::FromIo; use uucore::error::{UError, UResult}; use uucore::format_usage; +use uucore::parse_glob; use uucore::parse_size::{parse_size, ParseSizeError}; use uucore::InvalidEncodingHandling; #[cfg(windows)] @@ -504,7 +505,7 @@ fn build_exclude_patterns(matches: &ArgMatches) -> UResult> { if matches.is_present(options::VERBOSE) { println!("adding {:?} to the exclude list ", &f); } - match Pattern::new(&f) { + match parse_glob::from_str(&f) { Ok(glob) => exclude_patterns.push(glob), Err(err) => return Err(DuError::InvalidGlob(err.to_string()).into()), } diff --git a/tests/by-util/test_du.rs b/tests/by-util/test_du.rs index b421d5e84d2..5fcd8c8cbe0 100644 --- a/tests/by-util/test_du.rs +++ b/tests/by-util/test_du.rs @@ -745,6 +745,27 @@ fn test_du_exclude_mix() { assert!(!result.stdout_str().contains("qzerty")); assert!(!result.stdout_str().contains("azeaze")); assert!(result.stdout_str().contains("xcwww")); + + // Negation in glob should work with both ^ and ! + let result = ts + .ucmd() + .arg("--exclude=azerty/*/[^q]*") + .arg("azerty") + .succeeds(); + assert!(!result.stdout_str().contains("amazing")); + assert!(result.stdout_str().contains("qzerty")); + assert!(!result.stdout_str().contains("azeaze")); + assert!(result.stdout_str().contains("xcwww")); + + let result = ts + .ucmd() + .arg("--exclude=azerty/*/[!q]*") + .arg("azerty") + .succeeds(); + assert!(!result.stdout_str().contains("amazing")); + assert!(result.stdout_str().contains("qzerty")); + assert!(!result.stdout_str().contains("azeaze")); + assert!(result.stdout_str().contains("xcwww")); } #[test]