Skip to content

Commit d7d0f9d

Browse files
shred: correctly print zero-byte pass in verbose mode (#7800)
Fixes #7798. Co-authored-by: Sylvestre Ledru <sylvestre@debian.org>
1 parent b5e0e23 commit d7d0f9d

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/uu/shred/src/shred.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,8 +376,8 @@ fn get_size(size_str_opt: Option<String>) -> Option<u64> {
376376
fn pass_name(pass_type: &PassType) -> String {
377377
match pass_type {
378378
PassType::Random => String::from("random"),
379-
PassType::Pattern(Pattern::Single(byte)) => format!("{byte:x}{byte:x}{byte:x}"),
380-
PassType::Pattern(Pattern::Multi([a, b, c])) => format!("{a:x}{b:x}{c:x}"),
379+
PassType::Pattern(Pattern::Single(byte)) => format!("{byte:02x}{byte:02x}{byte:02x}"),
380+
PassType::Pattern(Pattern::Multi([a, b, c])) => format!("{a:02x}{b:02x}{c:02x}"),
381381
}
382382
}
383383

tests/by-util/test_shred.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,17 @@ fn test_shred_fail_no_perm() {
209209
.stderr_contains("Couldn't rename to");
210210
}
211211

212+
#[test]
213+
fn test_shred_verbose_pass_single_0_byte_name() {
214+
let (at, mut ucmd) = at_and_ucmd!();
215+
let file = "foo";
216+
at.write(file, "non-empty");
217+
ucmd.arg("-vn200")
218+
.arg(file)
219+
.succeeds()
220+
.stderr_contains("/200 (000000)...\n");
221+
}
222+
212223
#[test]
213224
fn test_shred_verbose_no_padding_1() {
214225
let (at, mut ucmd) = at_and_ucmd!();

0 commit comments

Comments
 (0)