Skip to content

Rename to a Free Name on Collision and Pad Odd GIF Dimensions - #286

Merged
ptr727 merged 5 commits into
developfrom
fix/process-collision-and-odd-gif
Nov 18, 2026
Merged

ptr727 merged 5 commits into
developfrom
fix/process-collision-and-odd-gif

Conversation

@ptr727

@ptr727 ptr727 commented Nov 18, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Rename collisions (Process With --skipbackup Deletes a Different File When an Extension Rename Collides #280). The mixed-case and MIME extension renames in ProcessTask no longer delete (--skipbackup) or back up (default) a file that already holds the target name. The renamed file takes the next free _N name from MediaUtilities.GetUniqueFileName, the way import does, and a warning names both files. A case-only rename on a case-insensitive filesystem is not treated as a collision with itself. The old MoveFile displacement is gone.
  • Why the deferral did not help. ProcessCommand's "Deferring N extension conflict(s)" only keeps same-stem files out of one parallel pass, so two tasks never race on one stem. It reserves no name on disk. The deferred file ran in the next pass, while the other file still held the name. No change to ProcessCommand.cs was needed.
  • Conversion under --skipbackup. The original used to stay on disk while the output name was chosen. So a PCM .mp4 collided with its own name and its output became _1.mp4. The original now moves to its .bak name in both modes. --skipbackup deletes that .bak once its metadata is copied and writes no .bak.out.
  • Undo. A rename that takes a free name touches no other file and writes no .bak, so undo has nothing to restore for it. Before this change, the default mode moved the unrelated file to .bak. undo then deleted the renamed file in its place. Conversion .bak / .bak.out handling in the default mode is unchanged.
  • Odd GIF dimensions (Process Fails to Convert an Animated GIF With an Odd Width or Height #281). The re-encode tier now passes -vf pad=ceil(iw/2)*2:ceil(ih/2)*2, the maintainer's recorded answer on Process Fails to Convert an Animated GIF With an Odd Width or Height #281. The filter sits on the shared re-encode branch (.asf, .wmv, .avi, .3gp, .gif). It does nothing to even dimensions, and an odd-dimension AVI or WMV hit the same libx264 failure.
  • Docs. GUIDE.md drops its "Known Issues" section and its two issue link definitions. Its cloud-export checklist now says a taken name gets the next free name. ARCHITECTURE.md and README.md describe the free-name rule, the padding, the --skipbackup behaviour, and the undo limitation.

Tests

  • ExecuteAsync_MismatchedMimeExtensionNameTaken_RenamesToFreeName, with and without --skipbackup: JPEG bytes in photo.dng beside a different photo.jpg. Asserts that photo_1.jpg holds the renamed bytes and photo.jpg is untouched. Also asserts there are no .bak files and that the warning is logged.
  • ExecuteAsync_MixedCaseExtensionNameTaken_RenamesToFreeName, with and without --skipbackup, case-sensitive filesystems only.
  • ExecuteAsync_MixedCaseExtensionCaseInsensitive_KeepsName, with and without --skipbackup, case-insensitive filesystems only.
  • ExecuteAsync_GifFileOddDimensions_PadsToEvenDimensions: generates 25x70 and 64x33 GIFs with ffmpeg. Asserts that ffprobe reads the MP4 as 26x70 and 64x34.
  • ExecuteAsync_Mp4WithPcmAudio_SkipBackup_KeepsSameName: the output keeps pcm.mp4 and no other file is left.
  • Full suite locally on Linux at e72be90: 402 total, 395 passed, 7 skipped, 0 failed. The skips are the five Docker-dependent verify tests and the two case-insensitive cases.

Not executed on Windows or macOS. The case-insensitive branch of IsNameTaken, which stops photo.Jpg counting as a collision with itself, is covered only by ExecuteAsync_MixedCaseExtensionCaseInsensitive_KeepsName. That test skips on Linux, and CI runs on Ubuntu only, so the branch has not been run on Windows or macOS.

Local-pass findings handed to this pull request (pass 3, edit budget spent)

  • ARCHITECTURE.md "Even Dimensions", class introduced. Fixed in e72be90. "Every source pixel is kept unscaled" holds for a GIF but not for an odd-sized yuv420p source in the same re-encode tier. Checked locally: a 25x70 GIF padded with this filter keeps every pixel. A 25x70 yuv420p FFV1 AVI loses its last column to the pad color. The bullet and the code comment now say so.
  • PhotoCleaner/ProcessTask.cs IsNameTaken / RenameToFreeName, class introduced. Declined under "Trust Boundaries and Hardening Effort". A free name whose <name>.bak still holds an earlier run's backup counts as free. A later undo would then delete the renamed file and restore that backup in its place. Reaching it needs several things at once. A backup from an earlier run must still sit at exactly the chosen name. Only video steps write .bak, so that name is a video's. Then undo must run after the later run. The input is the maintainer's own tree, and the case is not realistic in this deployment. The same gap exists for the canonical target name and the conversion output name, and that predates this change. It is declined on the same reasoning rather than filed.

Pre-existing findings, not filed

  • README.md lines 102-104 and the opening of "Undo Flow": class pre-existing, false statement. They say every process modification or deletion creates a .bak. Extension renames never did, as the section's own "Known limitation" states.

Dropped findings

  • PhotoCleanerTests/ProcessTaskTests.cs, the skip message of ExecuteAsync_MixedCaseExtension_RenamesFile: wording, on text this change did not touch.

Closes on promotion: #280, #281

🤖 Generated with Claude Code

ptr727 and others added 4 commits November 18, 2026 11:21
An extension rename in `process` no longer deletes or backs up a file
already holding its target name. The renamed file takes the next free
`_N` name, the way `import` does, and a warning names both files. This
holds with and without `--skipbackup`. The extension-conflict deferral in
ProcessCommand only kept same-stem files out of one parallel pass, so it
never reserved the name on disk.

The re-encode tier pads to even dimensions with
`pad=ceil(iw/2)*2:ceil(ih/2)*2`, since libx264 at yuv420p rejects an odd
width or height.

GUIDE.md drops both known-issue entries, and ARCHITECTURE.md describes
the new behaviour.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
With `--skipbackup` the original stayed on disk while the output name
was chosen, so a PCM `.mp4` collided with itself and its output became
`_1.mp4`. The original now moves to its `.bak` name in both modes, and
`--skipbackup` deletes that `.bak` once its metadata is copied.

BackupFile's rename now goes through RenameFile, and the padding comment
names a column as well as a row. A test covers a case-only rename on a
case-insensitive filesystem, skipped where the filesystem is
case-sensitive.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The README now says a renamed file takes the next free name when its
target is taken, that `--skipbackup` leaves no `.bak` behind, and that
the re-encode pads to even dimensions.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Only an extension mixing upper and lower case is lowercased, so `.Jpg`
becomes `.jpg` and an all-uppercase `.JPG` is kept.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ptr727 ptr727 added the comments Permits the comment lines the pull request adds or edits, which the prose gate otherwise refuses label Nov 18, 2026
Copilot AI lite review requested due to automatic review settings November 18, 2026 19:52
@coderabbitai

coderabbitai Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

@ptr727

ptr727 commented Nov 18, 2026

Copy link
Copy Markdown
Owner Author

A recorded local strict-review pass covers head 61693e590e2514d6dab01443d69c067fffcf046f, the content this pull request carries at that commit against develop, and it recorded 2 findings.

A GIF keeps every pixel under the pad. An odd-sized subsampled source,
such as a yuv420p AVI, loses its last odd row or column to the pad
color, so the docs and the comment no longer claim every pixel is kept.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@codecov

codecov Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 36 lines in your changes missing coverage. Please review.
✅ Project coverage is 41.15%. Comparing base (a3158ce) to head (e72be90).
⚠️ Report is 116 commits behind head on develop.

Files with missing lines Patch % Lines
PhotoCleaner/ProcessTask.cs 0.00% 36 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #286      +/-   ##
===========================================
- Coverage    43.37%   41.15%   -2.23%     
===========================================
  Files           28       27       -1     
  Lines         3896     4148     +252     
  Branches       306      362      +56     
===========================================
+ Hits          1690     1707      +17     
- Misses        2154     2371     +217     
- Partials        52       70      +18     
Flag Coverage Δ
dotnet 41.15% <0.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Active issues remain: the filename-generation logic can reuse stale backup paths and race with parallel renames, risking data loss, while the documentation overstates pixel preservation.

3 open issues
What changed in this PR

This PR makes process safer when renaming colliding media files, improves conversion handling under --skipbackup, and pads odd video dimensions before re-encoding.

Changes:

  • Renames colliding extension variants to the next available _N filename without displacing existing files.
  • Stages conversion sources through backup paths consistently and updates related undo behavior.
  • Pads odd-width or odd-height video frames in the shared re-encode path.
  • Updates documentation and adds coverage for collisions, filesystem case behavior, odd dimensions, and PCM conversion.
File Description
README.md Documents free-name collision handling, padded dimensions, and revised backup and --skipbackup behavior.
PhotoCleanerTests/​ProcessTaskTests.cs Adds tests for rename collisions, case-sensitive and case-insensitive filesystems, odd GIF dimensions, and PCM conversion.
PhotoCleaner/​ProcessTask.cs Implements free-name renames, unified conversion backup handling, and even-dimension padding.
GUIDE.md Updates cloud-export guidance and removes resolved known-issue documentation.
ARCHITECTURE.md Describes the revised rename, conversion, backup, undo, and dimension-padding behavior.

Review effort: Lite

Comment thread PhotoCleaner/ProcessTask.cs Resolved
Comment thread PhotoCleaner/ProcessTask.cs Resolved
Comment thread ARCHITECTURE.md Resolved
@ptr727

ptr727 commented Nov 18, 2026

Copy link
Copy Markdown
Owner Author

A recorded local strict-review pass covers head e72be905e6fdc30ed0f2e369e71679bef58eeb48, the content this pull request carries at that commit against develop, and it recorded 0 findings.

@ptr727
ptr727 merged commit d3906ab into develop Nov 18, 2026
23 checks passed
@ptr727
ptr727 deleted the fix/process-collision-and-odd-gif branch November 18, 2026 20:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comments Permits the comment lines the pull request adds or edits, which the prose gate otherwise refuses

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants