From 3eaf912597827058779fe828499e0dbd4766c619 Mon Sep 17 00:00:00 2001 From: Nadir Ali <36660597+Xnadir@users.noreply.github.com> Date: Wed, 18 Nov 2026 20:11:20 +0500 Subject: [PATCH 1/2] du: only warn when -s is given with --max-depth=0 Refs #16646 --- src/uu/du/locales/en-US.ftl | 1 + src/uu/du/locales/fr-FR.ftl | 1 + src/uu/du/src/du.rs | 7 ++++++- tests/by-util/test_du.rs | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/uu/du/locales/en-US.ftl b/src/uu/du/locales/en-US.ftl index cf69ccdbb99..b01d8826255 100644 --- a/src/uu/du/locales/en-US.ftl +++ b/src/uu/du/locales/en-US.ftl @@ -76,3 +76,4 @@ du-verbose-ignored = { $path } ignored du-verbose-adding-to-exclude-list = adding { $pattern } to the exclude list du-total = total du-warning-apparent-size-ineffective-with-inodes = options --apparent-size and -b are ineffective with --inodes +du-warning-summarize-same-as-depth-zero = summarizing is the same as using --max-depth=0 diff --git a/src/uu/du/locales/fr-FR.ftl b/src/uu/du/locales/fr-FR.ftl index 27bed339a41..02f168c4907 100644 --- a/src/uu/du/locales/fr-FR.ftl +++ b/src/uu/du/locales/fr-FR.ftl @@ -76,3 +76,4 @@ du-verbose-ignored = { $path } ignoré du-verbose-adding-to-exclude-list = ajout de { $pattern } à la liste d'exclusion du-total = total du-warning-apparent-size-ineffective-with-inodes = les options --apparent-size et -b sont inefficaces avec --inodes +du-warning-summarize-same-as-depth-zero = la synthèse équivaut à utiliser --max-depth=0 diff --git a/src/uu/du/src/du.rs b/src/uu/du/src/du.rs index 42d9d3a9b86..f4dff907846 100644 --- a/src/uu/du/src/du.rs +++ b/src/uu/du/src/du.rs @@ -1395,8 +1395,13 @@ fn parse_time_style(s: Option<&String>) -> UResult { fn parse_depth(max_depth_str: Option<&str>, summarize: bool) -> UResult> { let max_depth = max_depth_str.as_ref().and_then(|s| s.parse::().ok()); match (max_depth_str, max_depth) { - (Some(s), _) if summarize => Err(DuError::SummarizeDepthConflict(s.into()).into()), (Some(s), None) => Err(DuError::InvalidMaxDepthArg(s.into()).into()), + // Like GNU, -s with a depth of 0 only says they are the same thing. + (Some(_), Some(0)) if summarize => { + show_warning!("{}", translate!("du-warning-summarize-same-as-depth-zero")); + Ok(max_depth) + } + (Some(s), Some(_)) if summarize => Err(DuError::SummarizeDepthConflict(s.into()).into()), (Some(_), Some(_)) | (None, _) => Ok(max_depth), } } diff --git a/tests/by-util/test_du.rs b/tests/by-util/test_du.rs index 8c0005ca28a..786facc22d4 100644 --- a/tests/by-util/test_du.rs +++ b/tests/by-util/test_du.rs @@ -2818,6 +2818,39 @@ fn test_du_negative_max_depth_is_rejected() { .stderr_contains("du: invalid maximum depth '-3'"); } +#[test] +fn test_du_summarize_with_max_depth() { + let ts = TestScenario::new(util_name!()); + let at = &ts.fixtures; + at.mkdir("deep"); + at.mkdir("deep/deeper"); + + // A depth of 0 is what -s means anyway: GNU only warns. + for args in [&["-s", "--max-depth=0"][..], &["-d", "0", "-s"][..]] { + ts.ucmd() + .args(args) + .arg("deep") + .succeeds() + .stdout_contains("deep") + .stdout_does_not_contain("deeper") + .stderr_is("du: warning: summarizing is the same as using --max-depth=0\n"); + } + + // Any other depth conflicts with -s. + ts.ucmd() + .args(&["-s", "--max-depth=1", "deep"]) + .fails_with_code(1) + .no_stdout() + .stderr_contains("du: summarizing conflicts with --max-depth="); + + // An invalid depth is reported as such, -s or not. + ts.ucmd() + .args(&["-s", "--max-depth=abc", "deep"]) + .fails_with_code(1) + .no_stdout() + .stderr_contains("du: invalid maximum depth 'abc'"); +} + #[test] fn test_du_repeated_v() { new_ucmd!().args(&["-s", "-v", "-v"]).succeeds(); From 6f0cf93943bfb21e87443e1e9d0ab6fc01d4f56c Mon Sep 17 00:00:00 2001 From: Nadir Ali <36660597+Xnadir@users.noreply.github.com> Date: Fri, 20 Nov 2026 03:53:26 +0500 Subject: [PATCH 2/2] du: check the whole -s/--max-depth conflict message in the test --- tests/by-util/test_du.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/by-util/test_du.rs b/tests/by-util/test_du.rs index 786facc22d4..5fd58a7cf88 100644 --- a/tests/by-util/test_du.rs +++ b/tests/by-util/test_du.rs @@ -2820,6 +2820,7 @@ fn test_du_negative_max_depth_is_rejected() { #[test] fn test_du_summarize_with_max_depth() { + use uucore::display::Quotable; let ts = TestScenario::new(util_name!()); let at = &ts.fixtures; at.mkdir("deep"); @@ -2841,7 +2842,10 @@ fn test_du_summarize_with_max_depth() { .args(&["-s", "--max-depth=1", "deep"]) .fails_with_code(1) .no_stdout() - .stderr_contains("du: summarizing conflicts with --max-depth="); + .stderr_contains(format!( + "du: summarizing conflicts with --max-depth={}\n", + "1".maybe_quote() + )); // An invalid depth is reported as such, -s or not. ts.ucmd()