My app started to delete it’s own data and files randomly for some users. They swear they used the program for years and then one day everything was gone.
Took a long time to work out what’s wrong. Here’s what I’m sure is happening -
On startup my app checks to see if an output folder exists in the users Documents.
If it doesn’t find the folder it creates one as it is the location for it to store it’s file output (documents and images eg. pdf, jpg).
Somewhere along the line the user decides to allow iCloud to backup Documents, Desktop etc.
All is fine until a period of time passes where they don’t modify or access the output files. iCloud now deletes the output folder from their Mac and shows the download icon (cloud) next to the folder name in Finder.
If you double-click it in Finder it will download again, but that’s not how the program works.
After a time the user opens my app as usual.
The app uses this code on startup to check for the folder -
'Create an output folder outputFolder = DocFolder.child("output") if not outputFolder.Exists then outputFolder.CreateAsFolder
This doesn’t see the folder (with the cloud icon which is visible in Finder) and creates a new output folder which uploads overwriting the one on iCloud with an empty folder.
Disaster - all previously created files gone!!!
(not even visible online in iCloud > Deleted files).
Note: Please leave conversations about where I should be storing program output for another post. That’s not relevant here as a user can choose any folder to sync with iCloud.