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
10 changes: 9 additions & 1 deletion src/uu/shred/src/shred.rs
Original file line number Diff line number Diff line change
Expand Up @@ -626,8 +626,16 @@ fn wipe_file(
verbose: bool,
force: bool,
) -> UResult<()> {
// Get these potential errors out of the way first
#[cfg(unix)]
let path = if path_str == "-" {
Path::new("/dev/fd/1")
} else {
Path::new(path_str)
};

#[cfg(not(unix))]
let path = Path::new(path_str);

if !path.exists() {
return Err(USimpleError::new(
1,
Expand Down
15 changes: 15 additions & 0 deletions tests/by-util/test_shred.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,3 +420,18 @@ fn test_gnu_shred_passes_different_counts() {
result.stderr_contains("pass 1/19 (random)");
result.stderr_contains("pass 19/19 (random)");
}

#[test]
#[cfg(unix)]
fn test_shred_dash_wipes_stdout_file() {
let (at, mut ucmd) = at_and_ucmd!();
let file = "secret.txt";
at.write(file, "secret data");

ucmd.arg("-n1")
.arg("-")
.set_stdout(at.make_file(file))
.succeeds();

assert_ne!(at.read(file), "secret data");
}
Loading