Skip to content

Fix iCloud Drive re-optimisation bug#71

Merged
alin23 merged 1 commit intoFuzzyIdeas:mainfrom
leek:fix/icloud-re-optimisation
Feb 10, 2026
Merged

Fix iCloud Drive re-optimisation bug#71
alin23 merged 1 commit intoFuzzyIdeas:mainfrom
leek:fix/icloud-re-optimisation

Conversation

@leek
Copy link
Copy Markdown
Contributor

@leek leek commented Jan 31, 2026

Summary

  • Mark original file with xattr after copying to the -optimised path, preventing iCloud sync FSEvents from re-triggering optimisation on the original
  • Add configurable protection window (optimisedFileProtectionMs) defaulting to 3s — users on iCloud Drive can increase to 30s/60s to handle longer sync times
  • Fix memory leak where newPath was inserted into alreadyOptimisedFiles but never cleaned up
  • Add UI picker in General > Optimisation settings for the protection window
  • Include setting in SETTINGS_TO_SYNC so it syncs across Macs via iCloud

Root Cause

When OptimisedFileBehaviour is sameFolder (or specificFolder), process() copies the original to a new -optimised path and optimises the copy. The original file was never marked with an xattr, so when iCloud Drive's bird daemon syncs the new file and generates fresh FSEvents (.itemModified/.itemRenamed) on the original, it passes all checks again and gets re-optimised — creating duplicate -optimised 2.png files from iCloud conflict renames.

Changed Files

File Change
Clop/ClopApp.swift Mark oldPath with xattr, use configurable TTL, add newPath cleanup
Clop/Settings.swift Add optimisedFileProtectionMs key (default 3000ms) + add to SETTINGS_TO_SYNC
Clop/SettingsView.swift Add protection window picker in General > Optimisation section

Test plan

  • Build the project in Xcode
  • Set image behaviour to "Same folder" with default template %f-optimised
  • Save a screenshot to an iCloud-synced Desktop
  • Verify exactly ONE -optimised file is created, no " 2" duplicates
  • Wait 60s, verify no re-optimisation occurs
  • Check xattr on original: xattr -l <original> should show clop.optimisation.status
  • Verify the new picker appears in General > Optimisation settings
  • Change protection window to 30s, verify setting persists across restart

🤖 Generated with Claude Code

When OptimisedFileBehaviour is sameFolder, process() copies the original
to a new -optimised path but never marks the original with an xattr.
When iCloud's bird daemon syncs the new file and generates fresh FSEvents
on the original, it passes all checks again and gets re-optimised,
creating duplicate "-optimised 2" files.

- Mark original file with xattr after copy to prevent re-trigger
- Add configurable protection window setting (default 3s) so users on
  iCloud Drive can increase it to handle longer sync times
- Clean up newPath from alreadyOptimisedFiles to fix memory leak
- Add protection window picker in General > Optimisation settings
- Include new setting in SETTINGS_TO_SYNC for iCloud sync

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@alin23 alin23 merged commit 7cc9614 into FuzzyIdeas:main Feb 10, 2026
1 check passed
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