Repository navigation
Fail a Rename Onto an Existing File and Undo a Partial Rename - #1119
Conversation
A lowercase rename or a remux to .mkv that would replace a different existing file fails the file and keeps both, on case-sensitive and case-insensitive file systems alike. The kept file is not deleted by DeleteInvalidFiles, since the collision says nothing about the media. A lowercase rename whose second move fails moves the file back to its original name, or reports the temp name it is left at. A remux or reencode whose input delete fails after the move still reports the output and the modification. Fixes #1073 Fixes #1109 Co-Authored-By: Claude Opus 5.5 <[email protected]>
A file created at the output name during a remux or reencode fails the final move, which now deletes the temp file before rethrowing. A failed undo of the lowercase rename reports the modification with the temp path. The lowercase and remux steps call the same Convert check, so the collision is logged in one place. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 42 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
|
A recorded local strict-review pass covers head |
PR Summary by QodoPrevent rename collisions and recover from partial moves
AI Description
Diagram
High-Level Assessment
Files changed (3)
|
Code Review by Qodo
1. A new input can be deleted during remux
|
There was a problem hiding this comment.
🟡 Changes recommended
Four critical findings remain around case-only replacement, collision-state propagation, and overwriting temporary targets, including paths that can delete or destroy the original input.
4 open issues
What changed in this PR
This PR hardens rename and remux operations against file collisions and improves recovery from partial multi-step moves.
Changes:
- Adds collision detection for lowercase renames, conversions, and remuxes.
- Preserves colliding files and restores files after failed rename steps where possible.
- Retains remux output when input deletion fails and adds focused regression tests.
- Unresolved issues remain around collision-state propagation and protection of temporary rename targets.
This pull request requires changes.
| File | Description |
|---|---|
PlexCleanerTests/RenameCollisionTests.cs |
Adds regression coverage for collision detection, rollback, output races, and partial remux behavior. |
PlexCleaner/ProcessFile.cs |
Tracks rename collisions, guards temporary and lowercase renames, restores failed moves, and protects colliding inputs from deletion. |
PlexCleaner/Convert.cs |
Adds collision detection and shared replacement and cleanup logic for conversion and remux operations. |
Review effort: Lite
The collision check lives in the ProcessFile steps alone, so a file created at the output name afterwards fails the non-overwriting final move, and the thrown step keeps the file rather than reaching DeleteFailedFile. The lowercase rename does not overwrite an existing temp name, and a failed temp cleanup no longer masks the move failure. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
A recorded local strict-review pass covers head |
Declined, per GOVERNANCE.md "Trust Boundaries and Hardening Effort". The full reasoning is in the reply on its thread at Convert.cs:240 (#1119 (comment)). The case needs another process to replace the input file during a case-only conversion. The |

Summary
Handles rename collisions (#1073) and partial two-step moves (#1109) together, since both live in the same rename and move code.
Rename collisions (#1073)
Convert.WouldReplaceOtherFile()reports whether a rename or move onto a target would replace an existing entry other than the source itself. A case-only rename names the file itself unless the directory lists the exact target name. So a lowercase rename of the same file is not a collision on a case-insensitive file system, and a real siblingname.mkvbesidename.MKVis a collision on a case-sensitive one.MakeExtensionLowercase()andRemuxByExtension()check before renaming and fail the file when the target is another file. Each logs the target and the source.DeleteFailedFile()keeps a file failed by a rename collision, since the collision says nothing about the media. Without this,DeleteInvalidFileswould delete the media the check just protected.Convertoverwrites only when the output is the input itself. So a file created at the output name after the check fails the move instead of being replaced, and the thrown step keeps the file..tmp7does not overwrite either, so a leftovername.tmp7, which may be media stranded by an earlier run, fails the step and is kept.Recoverable two-step moves (#1109)
MakeExtensionLowercase()moves the file back to its original name when the second move throws, then rethrows. If that move back fails too, the step reports the.tmp7path the media is at, with the modification.Convert.ConvertToMkv()and bothConvert.ReMuxToMkv()overloads share oneReplaceInput()step. A failed input delete after the move is logged and the step still returns the output, so the caller records the new path and the modification. A failed final move deletes the temp file and rethrows, so the step fails without deleting the input. A failed temp cleanup is logged so that the move failure is the exception that propagates.A collision fails the file without deleting it. The collision is found before any tool runs.
Process.csis outside this change, soProcessFilekeeps the file through its own_renameCollisionflag, whichDeleteFailedFile()honors. That is the same outcome theskippedpath gives an exception or a read-only file.Residual case: a rename whose second move and move back both fail leaves the media at
name.tmp7, and the row reports that path. A later run withDeleteUnwantedExtensionson deletes it as a non-MKV file, which is unchanged from before this change. The undo makes that a double failure, where the base code reached it after a single one.Trade-off: the standalone
reencodeanddeinterlacecommands do not run the lowercase step. On a case-sensitive file system holding bothname.MKVand a separatename.mkv, they find the collision only at the final move, after the encode. The move does not overwrite, the temp file is deleted, and nothing is lost, so only the encode time is spent.Docs deferred
ARCHITECTURE.md(the S6 suspect-branch entry and the process diagrams) andHISTORY.mdare not updated here. The maintainer chose to defer every doc update from this round to one final docs pull request, so review findings asking for those edits are declined with that reason.Testing
PlexCleanerTests/RenameCollisionTests.cscovers the collision helper (same name, missing target, other file, case-only rename of itself, case-only rename onto another file), a lowercase rename and a remux onto an existing file failing throughProcess.ProcessFile()withDeleteInvalidFileson and both files kept, a lowercase rename with no sibling, a failed second lowercase move restoring the original name, a file created at the output name during a remux failing the file with both kept and the temp file deleted, a taken.tmp7name failing the lowercase step with both kept, and a failed input delete after a remux reporting the output and the modification..NET Formatchain is clean.Closes on promotion: #1073, #1109
🤖 Generated with Claude Code