Skip to content

Leave both copies alone when the array copy is newer than the cache copy - #226

Merged
Brandon-Haney merged 1 commit into
StudioNirin:mainfrom
Brandon-Haney:pr/move-to-array-newer-array
Oct 6, 2026
Merged

Brandon-Haney merged 1 commit into
StudioNirin:mainfrom
Brandon-Haney:pr/move-to-array-newer-array

Conversation

@Brandon-Haney

Copy link
Copy Markdown
Collaborator

Follow-up to #222, from @DeLo1585's point on #221.

#222 made Move to Array keep the cache copy whenever it differs in size from the array copy, which is right when a tool rewrote the cache side (a Sonarr/Radarr in-place upgrade, a Tdarr pass through /mnt/user). When a tool rewrote the array side directly, the cache copy is the stale one, and Move to Array copied it over the newer array file.

Change

Caching keeps the original modification time on both sides: the cache copy is written with copystat, and the .plexcached backup is a rename of the original. So an untouched pair has matching mtimes, and whichever side a tool rewrote ends up newer.

  • If the array copy (the same-name file or the .plexcached backup) is newer than the cache copy by more than 2 seconds, Move to Array skips that file and reports "Array copy is newer than the cache copy, left both in place for review". Nothing is copied, renamed or deleted.
  • Matching mtimes, including tools that preserve the original mtime, keep Keep the newer cache copy when Move to Array finds an older array copy #222's behaviour: the cache copy wins when the sizes differ.
  • The 2-second tolerance covers filesystems that store modification times coarsely.
  • The Move to Array confirm dialog mentions the new case, and the parallel path's byte total leaves skipped files out.

Tests

tests/test_sync_to_array_newer_cache.py gains 10 cases (sequential and parallel): a newer same-name array file and a newer backup are both left untouched, a newer cache copy still replaces the array copy, and same-mtime / within-tolerance pairs keep the cache version. Without the guard, the four "array copy is newer" cases fail.

How to test

  1. Pick a file on cache with a .plexcached backup on the array.
  2. Replace the backup with a different file and touch it so it is newer than the cache copy.
  3. Run an audit and use Move to Array on that file: it is skipped with "Array copy is newer…", and both copies are unchanged.
  4. Repeat with the cache copy changed instead (newer than the backup): the cache version is copied across as before.

Move to Array keeps the cache copy whenever it differs in size from the
array copy, which is right when a tool rewrote the cache side. When a tool
rewrote the array side directly, the cache copy is the stale one and was
copied over the newer array file.

Caching keeps the original modification time on both sides, so an
untouched pair has matching mtimes and whichever side was rewritten is
newer. If the array copy (same-name file or .plexcached backup) is newer
than the cache copy by more than 2 seconds, the file is skipped and
reported for review with both copies left in place. Matching mtimes keep
the existing behaviour.
@Brandon-Haney
Brandon-Haney merged commit 3f6064a into StudioNirin:main Oct 6, 2026
2 checks passed
@Brandon-Haney
Brandon-Haney deleted the pr/move-to-array-newer-array branch October 6, 2026 21:52
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.

2 participants