Skip to content

Keep the newer cache copy when Move to Array finds an older array copy - #222

Merged
Brandon-Haney merged 1 commit into
StudioNirin:mainfrom
Brandon-Haney:fix/sync-to-array-trust-cache
Oct 2, 2026
Merged

Brandon-Haney merged 1 commit into
StudioNirin:mainfrom
Brandon-Haney:fix/sync-to-array-trust-cache

Conversation

@Brandon-Haney

Copy link
Copy Markdown
Collaborator

Move to Array in Maintenance → Untracked Files handled files marked Has backup or Has copy by restoring the array version and deleting the cache copy. It only checked that the array file existed, not whether it matched. When the cache copy is the newer one (a Sonarr/Radarr in-place upgrade, or a Tdarr pass as described in #221), the old version was kept and the new one removed.

The caching run already handles this case: when restoring a watched file whose cache copy differs in size from its backup, it treats it as an in-place upgrade and copies the cache version across. This brings Move to Array in line with that rule.

Change

  • If the array already holds a copy of the same size (the .plexcached backup or the same-name file), it is restored as before and the cache copy is deleted. No copy needed.
  • Otherwise the cache copy is kept: it is copied to a .pc-part name next to the target, the size is verified, it is renamed into place, and only then are the old backup and the cache copy removed. A copy that fails or comes out the wrong size leaves both versions where they were.
  • The sequential and parallel paths now share one helper (_sync_one_to_array) instead of two copies of the same logic.
  • The confirm dialog describes the new behaviour for files with an existing backup/copy.

This also covers a smaller case in the "Cache only" path: a copy that came out the wrong size used to leave the truncated file on the array under the real filename. It now only ever lands under the partial name.

Tests

  • tests/test_sync_to_array_newer_cache.py: real files, sequential and parallel paths, cache copy newer than the backup / array copy, and the identical fast paths.
  • tests/test_maintenance_service.py: the existing TestSyncToArray cases now use real files, plus a copy that fails part-way over an older backup.

How to test

  1. Pick a file that is on the cache with a .plexcached backup on the array (or the same-name file on the array).
  2. Replace the cache copy with a different file of a different size, keeping the name.
  3. Run an audit, select the file under Untracked Files and use Move to Array.
  4. The array now holds the replaced (cache) version, the .plexcached backup is gone, and the cache copy is removed.
  5. Repeat with an unchanged file: it is restored from the backup without a copy, as before.

Move to Array restored the .plexcached backup or kept the same-name array
file whenever one existed, and deleted the cache copy without comparing
them. When the cache copy is newer (a Sonarr/Radarr upgrade or a Tdarr
pass), the old version was kept and the new one removed.

It now follows the same rule as the caching run's in-place upgrade check:
an array copy of the same size is restored as before, otherwise the cache
version is copied to a partial name, verified, renamed into place, and
only then are the old backup and the cache copy removed. A copy that
fails or comes out the wrong size leaves both versions where they were.
Both the sequential and parallel paths share one helper.
@Brandon-Haney
Brandon-Haney merged commit e2010d6 into StudioNirin:main Oct 2, 2026
2 checks passed
@Brandon-Haney
Brandon-Haney deleted the fix/sync-to-array-trust-cache branch October 2, 2026 22:42
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