Skip to content

Commit 49c7e65

Browse files
Carbrexsylvestre
authored andcommitted
Use time-style only if time is provided
1 parent ffda2a4 commit 49c7e65

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/uu/du/src/du.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,12 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
721721
excludes: build_exclude_patterns(&matches)?,
722722
};
723723

724+
let time_format = if time.is_some() {
725+
parse_time_style(matches.get_one::<String>("time-style").map(|s| s.as_str()))?.to_string()
726+
} else {
727+
"%Y-%m-%d %H:%M".to_string()
728+
};
729+
724730
let stat_printer = StatPrinter {
725731
max_depth,
726732
size_format,
@@ -737,8 +743,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
737743
.transpose()?,
738744
apparent_size: matches.get_flag(options::APPARENT_SIZE) || matches.get_flag(options::BYTES),
739745
time,
740-
time_format: parse_time_style(matches.get_one::<String>("time-style").map(|s| s.as_str()))?
741-
.to_string(),
746+
time_format,
742747
line_ending: LineEnding::from_zero_flag(matches.get_flag(options::NULL)),
743748
};
744749

tests/by-util/test_du.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,3 +1116,13 @@ fn test_du_files0_from_combined() {
11161116

11171117
assert!(stderr.contains("file operands cannot be combined with --files0-from"));
11181118
}
1119+
1120+
#[test]
1121+
fn test_invalid_time_style() {
1122+
let ts = TestScenario::new(util_name!());
1123+
ts.ucmd()
1124+
.arg("-s")
1125+
.arg("--time-style=banana")
1126+
.succeeds()
1127+
.stdout_does_not_contain("du: invalid argument 'banana' for 'time style'");
1128+
}

0 commit comments

Comments
 (0)