Skip to content

shred: keep going when a rename fails during --remove - #16044

Merged
sylvestre merged 1 commit into
uutils:mainfrom
fixfon:fix/shred-remove-unwritable-dir
Nov 2, 2026
Merged

sylvestre merged 1 commit into
uutils:mainfrom
fixfon:fix/shred-remove-unwritable-dir

Conversation

@fixfon

@fixfon fixfon commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Closes #16073

When shred -u couldn't rename a file, for example in an unwritable directory, it printed "Couldn't rename to ..." and exited, so the file was never unlinked and later operands were skipped.

Now renaming stops at the first failure and the last name that worked is unlinked. If that fails too, the error is shred: shr/f: failed to remove: Permission denied and the run goes on with the next operand, still exiting 1. The WipeSync path returns the I/O error instead of panicking. The unused shred-couldnt-rename string is removed and failed to remove file is now failed to remove in en-US and fr-FR. Two existing tests that checked the old rename message are updated.

The new test test_shred_remove_in_unwritable_dir_keeps_going fails on main and passes with this change.

@xtqqczze

This comment was marked as resolved.

@fixfon

fixfon commented Oct 31, 2026

Copy link
Copy Markdown
Contributor Author

Opened #16073 for this and updated the description.

Comment thread src/uu/shred/src/shred.rs Outdated
@@ -843,7 +843,7 @@ fn do_pass(

/// Repeatedly renames the file with strings of decreasing length (most likely all 0s)
/// Return the path of the file after its last renaming or None in case of an error

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please update this doc, it never returns None and now stops at the first failed rename

Comment thread src/uu/shred/src/shred.rs
// TODO: replace with our error management
std::process::exit(1);
}
Err(_) => return Ok(last_path),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe add a short comment why the error is ignored here (the unlink reports it)

Comment thread tests/by-util/test_shred.rs Outdated

#[test]
#[cfg(unix)]
fn test_shred_remove_in_unwritable_dir_keeps_going() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

almost the same as test_shred_fail_no_perm above, could you just add the second operand there? :)

A failed rename made shred exit immediately, so with -u a file in a
directory without write permission aborted the run and later operands
were never processed. Stop renaming at the first failure and let the
unlink report the error as "failed to remove: <error>".
@fixfon
fixfon force-pushed the fix/shred-remove-unwritable-dir branch from 129510c to fae3152 Compare November 2, 2026 08:17
@fixfon

fixfon commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review. I updated the wipe_name doc comment and added a short note on why the rename error is ignored, since the unlink reports it. I also dropped the separate test and added a second operand to test_shred_fail_no_perm instead, which now checks that the first file stays and the second one gets removed.

@sylvestre
sylvestre merged commit d0ad00e into uutils:main Nov 2, 2026
137 of 138 checks passed
@sylvestre

Copy link
Copy Markdown
Contributor

Thanks for your PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

shred: --remove exits on the first failed rename and skips remaining files

3 participants