From a043b7c0491edf4e4d3330752455271a703c856e Mon Sep 17 00:00:00 2001 From: Maarten Billemont Date: Tue, 16 Sep 2014 07:53:31 -0400 Subject: [PATCH] Fixes to new store loading if not migrated. --- MasterPassword/ObjC/MPAlgorithmV0.m | 2 +- MasterPassword/ObjC/MPAppDelegate_Store.m | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/MasterPassword/ObjC/MPAlgorithmV0.m b/MasterPassword/ObjC/MPAlgorithmV0.m index 46d11bfc..8ad590a1 100644 --- a/MasterPassword/ObjC/MPAlgorithmV0.m +++ b/MasterPassword/ObjC/MPAlgorithmV0.m @@ -423,7 +423,7 @@ case MPElementTypeGeneratedShort: case MPElementTypeGeneratedPIN: case MPElementTypeGeneratedName: { - NSAssert( NO, @"Cannot save content to element with generated type %lu.", (long)element.type ); + wrn( @"Cannot save content to element with generated type %lu.", (long)element.type ); return NO; } diff --git a/MasterPassword/ObjC/MPAppDelegate_Store.m b/MasterPassword/ObjC/MPAppDelegate_Store.m index 24b0d96c..d0245312 100644 --- a/MasterPassword/ObjC/MPAppDelegate_Store.m +++ b/MasterPassword/ObjC/MPAppDelegate_Store.m @@ -146,10 +146,17 @@ PearlAssociatedObjectProperty( NSManagedObjectContext*, MainManagedObjectContext [self migrateStore]; // Create a new store coordinator. - self.persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel: - [NSManagedObjectModel mergedModelFromBundles:nil]]; + if (!self.persistentStoreCoordinator) + self.persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel: + [NSManagedObjectModel mergedModelFromBundles:nil]]; NSError *error = nil; - [self.persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:[self localStoreURL] + NSURL *localStoreURL = [self localStoreURL]; + if (![[NSFileManager defaultManager] createDirectoryAtURL:[localStoreURL URLByDeletingLastPathComponent] + withIntermediateDirectories:YES attributes:nil error:&error]) { + err( @"Couldn't create our application support directory: %@", [error fullDescription] ); + return; + } + [self.persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:localStoreURL options:@{ NSMigratePersistentStoresAutomaticallyOption : @YES, NSInferMappingModelAutomaticallyOption : @YES,