Should we not avoid manually purging iOS tmp and Caches folders? - ios

Use this directory to write temporary files that do not need to persist between launches of your app. Your app should remove files from this directory when they are no longer needed; however, the system may purge this directory when your app is not running.
https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemOverview/FileSystemOverview.html
There are conflicting answers about the need to manually clear the tmp folder. There is no API for clearing it, it must be performed manually file by file (which says something). More importantly, we should always avoid unnecessarily overworking the disk because it will wear out the SSD (Apple's Data Storage Guidelines mentions this also), and purging a folder file by file that's designed to be purged by the OS routinely seems counterintuitive.
Would it not be best practice then to delete what we know for certain isn't needed anymore as it comes our way (on-the-spot cleaning) and let the rest be purged by the OS and avoid manual purging altogether?
And should we not apply this strategy to the Library/Caches folder as well, since that folder's cleaning policy is the same as the tmp folder's?

You said:
Would it not be best practice then to delete what we know for certain isn't needed anymore as it comes our way (on-the-spot cleaning) and let the rest be purged by the OS and avoid manual purging altogether?
Yes, the documentation is telling you that when you create a temporary file, that you should just remove it as soon as you’re done with it. There’s no “manual purging” or sweeping of this folder needed. Just delete the individual files when you’re done with them.
And should we not apply this strategy to the Library/Caches folder as well, since that folder's cleaning policy is the same as the tmp folder’s?
If you know for certainty that you don’t need a particular cached file anymore, then absolutely delete it.
But often with caches, you don’t know when a particular file isn’t needed anymore, so we often resort to LRU-style logic based up the quantity, size, or cost of the assets.
But in both cases, you want to clean up as appropriate, to prevent unbridled growth in storage. You want to avoid using persistent storage for assets that are no longer needed

Related

Is it safe to delete SymStore's deleted transaction files?

We are using a SymStore on a fileshare and I recently noticed, that there are over 100k transaction files in the 000admin folder. About 95 % of these files have an .deleted extension, because they have been already deleted.
So is it safe to delete those files to save some space and make life easier for NTFS?
TLDR: no, in general it is not safe to delete these files.
Long answer: SymStore can do different operations, main of which are "add" and "delete". On every operation it changes files in 000Admin folder, adding there information about what was added or what was deleted. Later this information can be used by other SymStore commands, like "symstore query" command, for example. If you delete some of the transaction files from 000Admin folder - it means history of commands will not be accurate anymore and "symstore query" can't work properly.
Of course, if you are 100% sure you don't use such commands and you just need to store pdb files - you can delete files in 000Admin. However, you should understand some functionality of SymStore will not be available to you anymore.

Should I commit ios/Runner.xcworkspace/xcshareddata/?

After running my new Flutter app for a first time on iOS, git status is reporting untracked files
ios/Runner.xcworkspace/xcshareddata/
Should I add this to version control or add them to .gitignore?
The xcshareddata folder does not contain any user sensitive data, or even machine sensitive data.
That directory, as the name implies, is used to store shared settings, e.g: Schemes. In my experience, it is best to add it to version control, as there seems to be no good reason to keep it from being versioned.

Removing certain files on startup

How do you, on startup, remove certain files from the computer. I guess you use stdlib but I can't find any functions for deleting files.
So. How do you delete files when the computer boots up ?

Using File.applicationStorageDirectory across versions

I am using File.applicationStorageDirectory to store user data, specifically purchased items from iOS store.
I noticed that when users upgrade their version the data is lost and users need to restore their purchases (on ios items) , is it a bug on my side or is the File.applicationStorageDirectory not the correct place to store that kind of data.
Thanks!
applicationStorageDirectory is also known as the "temporary files" of the system. Regardless of the platform (desktop or mobile) or OS, when something drastic is done (such as installing a new version of the system), those temporary files are (generally) wiped out in the process.
Furthermore, uninstalling your application and reinstalling it (or, indeed, updating it) may (in some cases, dunno about iOS) delete those temporary files, or simply create a NEW directory for them, ignoring the old one.
Third, some cache-cleaning apps will also wipe out this data.
So, to answer your question, yes, you're going to want to store things you want to persist despite major changes, such as in-app purchases, in a new, dedicated folder in the userDirectory or the documentsDirectory.

Forcing or "encouraging" iCloud to upload changes to a file

I have a Mac and iOS application that is sharing data using iCloud, via a single "shoebox" file.
Most of the time, changes are properly synchronized in an efficient and prompt manner. However, every once in a while (particularly, right now) changes that I make on one device simply sit there.
I have made changes on my Mac to the shared data file, and the data has been saved to disk. However, I don't know whether it's the system's failure to upload the data to iCloud, or the iOS device's failure to check for the new data, but I'm twiddling my thumbs.
The 5KB file below is the one that should be changing. No matter how many changes I make in the Mac app, every once in a while during testing, iCloud will just stop syncing changes. If I walk away for 20 minutes and come back, it might start up again.
Further: If I run the Mac application in Xcode and keep an eye on the same file, even though I make changes to the file and can confirm that the file on disk (in the Finder/Terminal) is actually changing, the iCloud panel in Xcode does not pick up these changes very quickly either:
Note the same 5KB file has changed on my local filesystem on my Mac (at 9:01), but iCloud just isn't picking it up. There are actual content changes in this file, not just a modification date change.
So, I would like to find a way to either:
Trigger the sync programmatically, or even using Xcode. I know that the iCloud sync can be triggered using the simulator, but this only works when testing on iOS, and I much prefer to do my testing on the actual hardware anyway. Or,
Determine who (or what) is "at fault" for the data not being shared. I have followed the iCloud documents from the beginning, ensuring that I'm using coordinated writes to save changes, etc. It's just a very intermittent thing where iCloud will doze off, and makes testing very frustrating.
I don't think you can trigger synchronization of selected files, but you can use this tool "brctl" to see what is going on under the hood (or diagnose) (on OSX), to diagnose what it might be about.
commant line command:
$ brctl
for example use it like this
brctl log --wait --shorten
or
brctl diagnose
I realized when you migrate any store to your existing iCloud store, the iCloud store adds those data and forces sync to the version in the iCloud. So I migrate an empty store to my existing iCloud store, and I forced the sync!

Resources