Skip to content
Merged
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
9 changes: 3 additions & 6 deletions src/uu/shred/src/shred.rs
Original file line number Diff line number Diff line change
Expand Up @@ -542,12 +542,9 @@ fn wipe_file(
);
}
// size is an optional argument for exactly how many bytes we want to shred
// Ignore failed writes; just keep trying
show_if_err!(
do_pass(&mut file, &pass_type, exact, random_source, size).map_err_context(|| {
translate!("shred-file-write-pass-failed", "file" => path.maybe_quote())
})
);
do_pass(&mut file, &pass_type, exact, random_source, size).map_err_context(
|| translate!("shred-file-write-pass-failed", "file" => path.maybe_quote()),
)?;
}

if remove_method != RemoveMethod::None {
Expand Down
12 changes: 8 additions & 4 deletions tests/by-util/test_shred.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,20 +279,24 @@ fn test_random_source_regular_file() {
}

#[test]
#[ignore = "known issue #7947"]
fn test_random_source_dir() {
let (at, mut ucmd) = at_and_ucmd!();

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

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

#[test]
Expand Down
Loading