coreutils icon indicating copy to clipboard operation
coreutils copied to clipboard

shred: Continues after encountering an error

Open BenWiederhake opened this issue 6 months ago • 0 comments

After encountering an error in do_pass, our implementation continues, and tries again to overwrite the file:

$ cargo build && LC_ALL=C fiu-run -x -c "enable_random name=posix/io/rw/write,probability=0.01" cargo run shred -vn3 foo
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.14s
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.17s
     Running `target/debug/coreutils shred -vn3 foo`
shred: foo: pass 1/3 (random)...
shred: foo: File write pass failed: Invalid input
shred: foo: pass 2/3 (random)...
shred: foo: pass 3/3 (random)...
[$? = 1]

However, the GNU implementation doesn't do that:

$ LC_ALL=C fiu-run -x -c "enable_random name=posix/io/rw/write,probability=0.01" shred -vn3 foo
shred: foo: pass 1/3 (random)...
shred: foo: error writing at offset 917504: Disk quota exceeded
[$? = 1]
$ LC_ALL=C fiu-run -x -c "enable_random name=posix/io/rw/write,probability=0.02" shred -vn3 foo
shred: foo: pass 1/3 (random)...
shred: foo: error writing at offset 131072: Interrupted system call
[$? = 1]
$ LC_ALL=C fiu-run -x -c "enable_random name=posix/io/rw/write,probability=0.02" shred -vn3 foo
shred: foo: pass 1/3 (random)...
shred: foo: pass 2/3 (random)...
shred: foo: error writing at offset 786432: Interrupted system call
[$? = 1]

This seems to be due to the following code in fn wipe_file:

        // Ignore failed writes; just keep trying
        show_if_err!(
            do_pass(&mut file, &pass_type, exact, size)
                .map_err_context(|| format!("{}: File write pass failed", path.maybe_quote()))
        );

So apparently we do that intentionally, for some reason? But we shouldn't?

Ping @forticulous, do you know whether there was a good reason that we should do it like this? (In this case, we should probably document it in extensions.md.) Or maybe it should be changed to a regular error instead? (I'm pinging you because of eb6453013e2bd13c3a8155eb60ce2cbbeaf6327f)

Found while working on #5711

BenWiederhake avatar May 17 '25 16:05 BenWiederhake