-
Notifications
You must be signed in to change notification settings - Fork 122
Make offline database path configurable #298
Conversation
b7e3ddd
to
696a99d
Compare
add or remove custom parameters, or reroute certain requests to other servers | ||
or endpoints. | ||
*/ | ||
@property(nonatomic, weak, nullable) IBOutlet id<MGLOfflineStorageDelegate> delegate; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn’t new; I just moved it up above the database merging methods.
The subdirectory-less cache was located at: | ||
~/Library/Application Support/tld.app.bundle.id/cache.db | ||
*/ | ||
+ (NSURL *)cacheURLIncludingSubdirectory:(BOOL)useSubdirectory { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously these class methods were sandwiched below certain methods related to +sharedOfflineStorage
and above -init
. I’ve consolidated them down where the other database-related methods are implemented and renamed them for consistency, but otherwise I haven’t changed them.
// Move the offline cache from v3.2.0-beta.1 to a location that can also | ||
// be used for ambient caching. | ||
if (![[NSFileManager defaultManager] fileExistsAtPath:cachePath]) { | ||
NSString *legacyCachePath = [[self class] legacyCachePath]; | ||
[[NSFileManager defaultManager] moveItemAtPath:legacyCachePath toPath:cachePath error:NULL]; | ||
} | ||
|
||
// Move the offline file cache from v3.2.x path to a subdirectory that | ||
// can be reliably excluded from backups. | ||
if (![[NSFileManager defaultManager] fileExistsAtPath:cachePath]) { | ||
NSURL *subdirectorylessCacheURL = [[self class] cacheURLIncludingSubdirectory:NO]; | ||
[[NSFileManager defaultManager] moveItemAtPath:subdirectorylessCacheURL.path toPath:cachePath error:NULL]; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These preflight steps have been moved into a lazily initialized -offlineURL
getter.
[NSFileManager.defaultManager createDirectoryAtURL:directoryURL | ||
withIntermediateDirectories:YES | ||
attributes:nil | ||
error:nil]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As with the default code path in -defaultDatabaseURLIncludingSubdirectory:
, this custom path code path results in the containing directory being created if it doesn’t already exist. However, this code path doesn’t exclude the containing directory from iCloud backups. Info.plist could’ve specified a path in the same folder as other resources. Besides, the developer might decide that the database won’t be so large and that they don’t want to regenerate the database in case the application gets restored from a backup.
} | ||
|
||
NSDictionary *attributes = [[NSFileManager defaultManager] attributesOfItemAtPath:cachePath error:NULL]; | ||
NSDictionary *attributes = [[NSFileManager defaultManager] attributesOfItemAtPath:self.databasePath error:NULL]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When run from within a unit test bundle before iOS SDK 12.2, -cacheURLIncludingSubdirectory:
happened to return a stable result only because of a special case in +[NSBundle mgl_applicationBundleIdentifier]
. Now we can rely on the fact that databasePath
is memoized.
Added getters for the path and URL of the offline database file and made use of the getter in places where the code had previously called -cacheURLIncludingSubdirectory: (which technically could’ve returned a different path each time it was called). Also reformatted some MGLOfflineStorage documentation comments.
696a99d
to
ceb5bce
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏼
Added the
MGLOfflineStorage.databasePath
andMGLOfflineStorage.databaseURL
properties to obtain the path of the database that contains offline packs and the ambient cache, as well as anMGLOfflineStorageDatabasePath
Info.plist key to customize this path.Fixes #297.
/cc @mapbox/maps-ios