Skip to content

Fix sync for folders synced by earlier versions - #130

Merged
const-cloudinary merged 1 commit into
masterfrom
fix/sync-stale-cld-sync-entries
Oct 4, 2026
Merged

const-cloudinary merged 1 commit into
masterfrom
fix/sync-stale-cld-sync-entries

Conversation

@const-cloudinary

@const-cloudinary const-cloudinary commented Oct 4, 2026 •

Copy link
Copy Markdown
Member

Since #124, sync adds the extension to the remote name of a raw file in dynamic folder mode (notes → notes.txt). Local folders synced by earlier versions still use the old names, so sync --push treated those remote files as unique and deleted them.

Use cases fixed

Case Before this PR After
Raw file pushed by an earlier version (.cld-sync has notes.txt → notes) Every second push deletes the remote file and uploads nothing In sync
Raw files with the same base name pushed by an earlier version (notes.txt, notes.csv) Push deletes both remote files and uploads nothing In sync
Raw file pulled by an earlier version (local notes, no extension) Push deletes the remote file and uploads the local file again, without the extension and with a new public ID In sync
Raw duplicates pulled by an earlier version (notes (1), notes (2), ...), including after a remote copy was deleted Push deletes all remote copies and uploads them again with new public IDs Matched by content, nothing deleted
Any .cld-sync entry that points to a remote file that no longer exists, for images too (e.g. a.png → zzz.png while a.png is on Cloudinary) Push deletes a.png and uploads nothing In sync

Brief Summary of Changes

  • SyncDir._verify_diverse_file_names (cloudinary_cli/modules/sync.py), applied when .cld-sync is read:
    • Drops entries whose remote file does not exist.
    • In dynamic folder mode, maps an unmatched remote raw file to a local file named after its display name without the extension (notes, notes (1), ...), only when the content (etag) is the same.
  • delete_cld_folder_if_exists (test/helper_test.py) deletes test assets of all resource types. It deleted only images before.
  • 4 integration tests in TestCLISync, dynamic folder mode only. One per row above, except the last, plus one for a new push and pull of a raw file.

What does this PR address?

  • GitHub issue (Add reference - #XX)
  • Refactoring
  • New feature
  • Bug fix
  • Adds more tests

Are tests included?

  • Yes
  • No

Reviewer, please note:

  • No change for images and videos, or in fixed folder mode, other than dropping .cld-sync entries that point to missing files. When the target is missing, keeping the entry and dropping it give the same result for push and pull.
  • A local file is matched with a remote raw file only when the content is the same. Otherwise sync works as on master.
  • Checked against a test cloud on master and on this branch, with the same results for images and videos:
    • the image test folder in dynamic and fixed folder mode (push, push, pull into an empty folder, push);
    • videos with duplicate names;
    • an image and a raw file with the same base name;
    • the jpeg alias.

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I ran the full test suite before pushing the changes and all the tests pass.

Ran the sync tests only: test/test_modules/test_cli_sync.py, 13 existing integration tests, 4 new ones, and 6 offline ones, all passing.

🤖 Generated with Claude Code

Ignore `.cld-sync` entries whose remote file does not exist. In dynamic
folder mode, match remote raw files with local files of the same content
that were saved without the extension, e.g. `notes` or `notes (1)`.

Delete test assets of all resource types in `delete_cld_folder_if_exists`.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@const-cloudinary const-cloudinary changed the title Fix sync deleting raw files synced by earlier versions Fix sync --push deleting files synced by earlier versions Oct 4, 2026
@const-cloudinary const-cloudinary changed the title Fix sync --push deleting files synced by earlier versions Fix sync for folders synced by earlier versions Oct 4, 2026
@const-cloudinary
const-cloudinary merged commit 4a9de72 into master Oct 4, 2026
8 checks passed
@const-cloudinary
const-cloudinary deleted the fix/sync-stale-cld-sync-entries branch October 4, 2026 12:10
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.

1 participant