From e18dee22427027a5decccc631bb06d0b04068156 Mon Sep 17 00:00:00 2001 From: Maarten Billemont Date: Thu, 30 Oct 2014 00:18:01 -0400 Subject: [PATCH] Also try upgrading to V2 if migrationlevel is unset but a store is available. --- MasterPassword/ObjC/MPAppDelegate_Store.m | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/MasterPassword/ObjC/MPAppDelegate_Store.m b/MasterPassword/ObjC/MPAppDelegate_Store.m index 13109376..cb7a7074 100644 --- a/MasterPassword/ObjC/MPAppDelegate_Store.m +++ b/MasterPassword/ObjC/MPAppDelegate_Store.m @@ -314,11 +314,11 @@ PearlAssociatedObjectProperty( NSNumber*, StoreCorrupted, storeCorrupted ); return; inf( @"Local store migration level: %d (current %d)", (signed)migrationLevel, (signed)MPStoreMigrationLevelCurrent ); - if (migrationLevel == MPStoreMigrationLevelV1 && ![self migrateV1LocalStore]) { + if (migrationLevel <= MPStoreMigrationLevelV1 && ![self migrateV1LocalStore]) { inf( @"Failed to migrate old V1 to new local store." ); return; } - if (migrationLevel == MPStoreMigrationLevelV2 && ![self migrateV2LocalStore]) { + if (migrationLevel <= MPStoreMigrationLevelV2 && ![self migrateV2LocalStore]) { inf( @"Failed to migrate old V2 to new local store." ); return; } @@ -342,6 +342,11 @@ PearlAssociatedObjectProperty( NSNumber*, StoreCorrupted, storeCorrupted ); inf( @"Migrating V1 local store" ); NSURL *newLocalStoreURL = [self localStoreURL]; + if (![[NSFileManager defaultManager] fileExistsAtPath:newLocalStoreURL.path isDirectory:NULL]) { + inf( @"New local store already exists." ); + return YES; + } + NSError *error = nil; if (![NSPersistentStore migrateStore:oldLocalStoreURL withOptions:@{ STORE_OPTIONS } toStore:newLocalStoreURL withOptions:@{ STORE_OPTIONS } @@ -378,6 +383,11 @@ PearlAssociatedObjectProperty( NSNumber*, StoreCorrupted, storeCorrupted ); inf( @"Migrating V2 local store" ); NSURL *newLocalStoreURL = [self localStoreURL]; + if ([[NSFileManager defaultManager] fileExistsAtPath:newLocalStoreURL.path isDirectory:NULL]) { + inf( @"New local store already exists." ); + return YES; + } + NSError *error = nil; if (![NSPersistentStore migrateStore:oldLocalStoreURL withOptions:@{ NSMigratePersistentStoresAutomaticallyOption : @YES,