Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/uu/du/locales/en-US.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions src/uu/du/locales/fr-FR.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 6 additions & 1 deletion src/uu/du/src/du.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1395,8 +1395,13 @@ fn parse_time_style(s: Option<&String>) -> UResult<String> {
fn parse_depth(max_depth_str: Option<&str>, summarize: bool) -> UResult<Option<usize>> {
let max_depth = max_depth_str.as_ref().and_then(|s| s.parse::<usize>().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),
}
}
Expand Down
33 changes: 33 additions & 0 deletions tests/by-util/test_du.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down