Repository navigation
Conversation
As explained in mapbox#5577, it's safer to set NSURLIsExcludedFromBackupKey to the cache directory instead of the cache file. This must be done before anything is created/moved into the directory so as to prevent iCloud backup from kicking in at any point (during the legacy db move, for example).
|
@friedbunny, v3.3.0 is only a few days away, but I think we should cherry-pick this change into the release branch, given that #5124 was speculative and @dapetcu21 has provided verification steps in #5577 (comment). |
|
So there's one problem with this PR: it assumes the developer won't need to put anything else in the application's subfolder in Application Support. I don't think we can make that assumption. Perhaps we need to move the cache yet again to a subfolder within that folder that we can set the exclusion flag on. /cc @jfirebaugh |
|
This behavior has changed since v3.2.0 — see #5124. We were indeed failing to set the You can verify that cache.db exists on the first launch and that we’re setting the flag correctly in v3.3.0: NSAssert(![[NSFileManager defaultManager] fileExistsAtPath:cachePath], @"Cache database file shouldn't already exist.");
_mbglFileSource = new mbgl::DefaultFileSource(cachePath.UTF8String, [NSBundle mainBundle].resourceURL.path.UTF8String);
NSAssert([[NSFileManager defaultManager] fileExistsAtPath:cachePath], @"Cache database file should exist.");
// Avoid backing up the offline cache onto iCloud, because it can be
// redownloaded. Ideally, we’d even put the ambient cache in Caches, so
// it can be reclaimed by the system when disk space runs low. But
// unfortunately it has to live in the same file as offline resources.
[cacheURL setResourceValue:@YES forKey:NSURLIsExcludedFromBackupKey error:NULL];
NSError *error = nil;
NSNumber *exclusionFlag = nil;
[cacheURL getResourceValue:&exclusionFlag forKey:NSURLIsExcludedFromBackupKey error:&error];
NSAssert(exclusionFlag && [exclusionFlag boolValue], @"Backup exclusion flag should be set for cache database.");We don't set the backup exclusion flag on the directory because it may interfere with legitimately backup-able files that the developer also stores there. If we were to set the flag on a directory, it would need to be one that we’re certain to own exclusively — i.e., a new subdirectory and not the generic |
|
I should also say: thanks for helping out, @dapetcu21. 🙇 If you’re still seeing the backup exclusion flag not being set properly on the |
|
Wait. I'm using a precompiled When submitting this PR I made 2 assumptions: a) That the code didn't change between my build and master (which is wrong) So if b) is wrong, I guess it should work and we should't merge this. |
|
Ah, sorry for the confusion then. I just assumed a PR made against master would fix a bug in master, my bad. I don’t know whether |
Yes, in my observation it is created immediately via the call to Frankly, we’re not completely confident in when exactly cache.db is being created, but @kkaefer speculated that the SQLite database having
Apologies for the confusion, @dapetcu21 — between releases we merge changes into master, then create a short-lived branch for pre-releases and the eventual final release (currently: I’m going to close this pull request and #5577, but we’d quite appreciate if you could help to verify the fix for this issue by giving the current v3.3.0 beta release a try. Thanks for time you've put into this, @dapetcu21. |
We cannot guarantee that the offline/ambient tile cache (cache.db) will be created in a timely manner, so it's safer to set the backup exclusion key on its containing directory. But, because we placed cache.db in the base of the app's Application Support directory (where backups are expected to be allowed), we need to move cache.db into a directory that we control and can exclude from backups with impunity. This is an amalgam of #5578 (directory exclusion) and #5585 (refactored URL methods, but without the new database size method). Also: * Prefix mapbox subdirectory with dot, for extra safety * Update changelog entry with new ticket, less speculation
As explained in #5577, it's safer to set NSURLIsExcludedFromBackupKey to the cache directory instead of the cache file. This must be done before anything is created/moved into the directory so as to prevent iCloud backup from kicking in at any point (during the legacy db move, for example).