Repository navigation
Conversation
glubsy
approved these changes
Sep 9, 2026
arsenetar
reviewed
Nov 11, 2026
| try: | ||
| os.rename(src, dest_path) | ||
| except OSError: | ||
| os.unlink(info_file) |
Owner
There was a problem hiding this comment.
So if there is an error on unlink that could surface to the user instead of the original error, possible handling could be:
with contextlib.suppress(OSError):
os.unlink(info_file)
raiseAlthough its unlikely in most cases and throwing away that error if it happens is probably better than surfacing.
glubsy
approved these changes
Nov 14, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #101.
trash_move()writes the.trashinfofile before callingos.rename(). If the rename fails withEXDEV,send2trash()retries withshutil.move(), but the first information file remains. The retry then chooses a different destination name, leaving an orphan record in the trash.Remove the information file created by the failed rename before re-raising the error. Cleanup uses the actual collision-resolved filename, so it does not delete an older trash entry with the same original name. The existing cross-device retry can then reuse that name.
This preserves the required information-file-before-move ordering in the Trash specification. The
shutil.move()branch is unchanged; this patch handles the failed initial rename, not partial-copy recovery.Tests
Four new regression cases fail before the fix and pass after it:
EXDEVandEACCESrenames leave the source intact, remove the new information record, and propagate the original exception.Validation on macOS with Python 3.14.3:
The new tests use temporary directories, stub device detection, and force
os.rename()to raiseEXDEV; the retry uses the realshutil.move()copy fallback. No real bind mounts or user's trash are required. The selected existing tests cover external-volume trash success, fallback, and permission failure. The complete platform/Python CI matrix was not run locally.AI assistance
Codex implemented the patch and ran the checks at my request. This contribution is based on reproducing the reported issue; I am not claiming production usage of Send2Trash.