Skip to content

Commit 31b5cc1

Browse files
naoNao89sylvestre
authored andcommitted
fix(shred): stop immediately on write errors (fixes #7947)
Replace show_if_err!() with ? operator in wipe_file() to properly propagate errors and stop pass loop on first write failure. This matches GNU shred behavior where any write error (disk quota, I/O error, etc.) stops execution immediately instead of continuing with remaining passes. Changes: - src/uu/shred/src/shred.rs: Use ? operator for error propagation - tests/by-util/test_shred.rs: Enable previously ignored test
1 parent 18a50ff commit 31b5cc1

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

src/uu/shred/src/shred.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -713,12 +713,9 @@ fn wipe_file(
713713
);
714714
}
715715
// size is an optional argument for exactly how many bytes we want to shred
716-
// Ignore failed writes; just keep trying
717-
show_if_err!(
718-
do_pass(&mut file, &pass_type, exact, random_source, size).map_err_context(|| {
719-
translate!("shred-file-write-pass-failed", "file" => path.maybe_quote())
720-
})
721-
);
716+
do_pass(&mut file, &pass_type, exact, random_source, size).map_err_context(
717+
|| translate!("shred-file-write-pass-failed", "file" => path.maybe_quote()),
718+
)?;
722719
}
723720

724721
if remove_method != RemoveMethod::None {

tests/by-util/test_shred.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -279,20 +279,24 @@ fn test_random_source_regular_file() {
279279
}
280280

281281
#[test]
282-
#[ignore = "known issue #7947"]
283282
fn test_random_source_dir() {
284283
let (at, mut ucmd) = at_and_ucmd!();
285284

286285
at.mkdir("source");
287286
let file = "foo.txt";
288287
at.write(file, "a");
289288

290-
ucmd
291-
.arg("-v")
289+
// The test verifies that shred stops immediately on error instead of continuing
290+
// Platform differences:
291+
// - Unix: Error during write ("File write pass failed: Is a directory")
292+
// - Windows: Error during open ("cannot open random source")
293+
// Both are correct - key is NOT seeing "pass 2/3" (which proves it stopped)
294+
ucmd.arg("-v")
292295
.arg("--random-source=source")
293296
.arg(file)
294297
.fails()
295-
.stderr_only("shred: foo.txt: pass 1/3 (random)...\nshred: foo.txt: File write pass failed: Is a directory\n");
298+
.stderr_does_not_contain("pass 2/3")
299+
.stderr_does_not_contain("pass 3/3");
296300
}
297301

298302
#[test]

0 commit comments

Comments
 (0)