2
0

Fixes to migration of local store from old Master Password model persistence models.

This commit is contained in:
Maarten Billemont 2013-09-16 23:18:01 -04:00
parent 40d6019f71
commit 07dd98823f
2 changed files with 7 additions and 54 deletions

@ -1 +1 @@
Subproject commit fb1b53869cee17efcc5b5a3b4232392fb006c463 Subproject commit 6707cb36233c9f6b7c2a71c8aa186ccf11bd318f

View File

@ -246,27 +246,10 @@ PearlAssociatedObjectProperty(NSManagedObjectContext*, MainManagedObjectContext,
return YES; return YES;
} }
NSError *error = nil;
NSDictionary *oldLocalStoreOptions = @{
STORE_OPTIONS
NSReadOnlyPersistentStoreOption : @YES,
NSInferMappingModelAutomaticallyOption : @YES
};
NSDictionary *newLocalStoreOptions = @{
STORE_OPTIONS
NSMigratePersistentStoresAutomaticallyOption : @YES,
NSInferMappingModelAutomaticallyOption : @YES
};
// Create the directory to hold the new local store. // Create the directory to hold the new local store.
if (![[NSFileManager defaultManager] createDirectoryAtPath:[self.storeManager URLForLocalStoreDirectory].path if (![self.storeManager migrateStore:oldLocalStoreURL withOptions:nil
withIntermediateDirectories:YES attributes:nil error:&error]) toStore:newLocalStoreURL withOptions:nil
err(@"While creating directory for new local store: %@", error); strategy:0 error:nil cause:nil context:nil]) {
if (![self.storeManager migrateStore:oldLocalStoreURL withOptions:oldLocalStoreOptions
toStore:newLocalStoreURL withOptions:newLocalStoreOptions
strategy:self.storeManager.migrationStrategy
error:nil cause:nil context:nil]) {
self.storeManager.localStoreURL = oldLocalStoreURL; self.storeManager.localStoreURL = oldLocalStoreURL;
return NO; return NO;
} }
@ -283,39 +266,9 @@ PearlAssociatedObjectProperty(NSManagedObjectContext*, MainManagedObjectContext,
} }
NSURL *newCloudStoreURL = [self.storeManager URLForCloudStore]; NSURL *newCloudStoreURL = [self.storeManager URLForCloudStore];
NSURL *newCloudContentURL = [self.storeManager URLForCloudContent]; if (![self.storeManager migrateStore:oldCloudStoreURL withOptions:nil
toStore:newCloudStoreURL withOptions:nil
NSError *error = nil; strategy:0 error:nil cause:nil context:nil])
NSDictionary *oldCloudStoreOptions = @{
STORE_OPTIONS
NSPersistentStoreUbiquitousContentNameKey : contentName,
NSPersistentStoreUbiquitousContentURLKey : oldCloudContentURL,
NSInferMappingModelAutomaticallyOption : @YES
};
NSDictionary *newCloudStoreOptions = @{
STORE_OPTIONS
NSPersistentStoreUbiquitousContentNameKey : [self.storeManager valueForKey:@"contentName"],
NSPersistentStoreUbiquitousContentURLKey : newCloudContentURL,
NSMigratePersistentStoresAutomaticallyOption : @YES,
NSInferMappingModelAutomaticallyOption : @YES
};
// Create the directory to hold the new cloud store.
// This is only necessary if we want to try to rebuild the old store. See comment above about how that failed.
if (![[NSFileManager defaultManager] createDirectoryAtPath:[oldCloudStoreURL URLByDeletingLastPathComponent].path
withIntermediateDirectories:YES attributes:nil error:&error])
err(@"While creating directory for old cloud store: %@", error);
if (![[NSFileManager defaultManager] createDirectoryAtPath:oldCloudContentURL.path
withIntermediateDirectories:YES attributes:nil error:&error])
err(@"While creating directory for old cloud content: %@", error);
if (![[NSFileManager defaultManager] createDirectoryAtPath:[self.storeManager URLForCloudStoreDirectory].path
withIntermediateDirectories:YES attributes:nil error:&error])
err(@"While creating directory for new cloud store: %@", error);
if (![self.storeManager migrateStore:oldCloudStoreURL withOptions:oldCloudStoreOptions
toStore:newCloudStoreURL withOptions:newCloudStoreOptions
strategy:self.storeManager.migrationStrategy
error:nil cause:nil context:nil])
return NO; return NO;
inf(@"Successfully migrated to new cloud store."); inf(@"Successfully migrated to new cloud store.");