@@ -75,37 +75,39 @@ - (NSPersistentStore *) MR_addSqliteStoreNamed:(id)storeFileName withOptions:(__
75
75
options: options
76
76
error: &error];
77
77
78
- if (!store && [MagicalRecord shouldDeleteStoreOnModelMismatch ] )
78
+ if (!store)
79
79
{
80
- BOOL isMigrationError = [error code ] == NSPersistentStoreIncompatibleVersionHashError || [error code ] == NSMigrationMissingSourceModelError;
81
- if ([[error domain ] isEqualToString: NSCocoaErrorDomain ] && isMigrationError)
80
+ if ([MagicalRecord shouldDeleteStoreOnModelMismatch ])
82
81
{
83
- // Could not open the database, so... kill it!
84
- NSFileManager *manager = [NSFileManager defaultManager ];
85
- BOOL deletionResult = [NSPersistentStore MR_deleteFilesForSqliteStoreAtURL: url
86
- withFileManager: manager];
87
-
88
- if (deletionResult) {
89
- MRLogInfo (@" Removed SQLite store %@ to resolve incompatible model version" ,
90
- [url lastPathComponent ]);
91
- } else {
92
- MRLogWarn (@" Unable to fully remove SQLite store %@ to resolve incompatible model version; will try to create store one more time anyway" ,
93
- [url lastPathComponent ]);
94
- }
95
-
96
- // Try one more time to create the store
97
- store = [self addPersistentStoreWithType: NSSQLiteStoreType
98
- configuration: nil
99
- URL: url
100
- options: options
101
- error: &error];
102
- if (store)
82
+ BOOL isMigrationError = [error code ] == NSPersistentStoreIncompatibleVersionHashError || [error code ] == NSMigrationMissingSourceModelError;
83
+ if ([[error domain ] isEqualToString: NSCocoaErrorDomain ] && isMigrationError)
103
84
{
104
- // If we successfully added a store, remove the error that was initially created
105
- error = nil ;
85
+ // Could not open the database, so... kill it!
86
+ NSFileManager *manager = [NSFileManager defaultManager ];
87
+ BOOL deletionResult = [NSPersistentStore MR_deleteFilesForSqliteStoreAtURL: url
88
+ withFileManager: manager];
89
+
90
+ if (deletionResult) {
91
+ MRLogInfo (@" Removed SQLite store %@ to resolve incompatible model version" ,
92
+ [url lastPathComponent ]);
93
+ } else {
94
+ MRLogWarn (@" Unable to fully remove SQLite store %@ to resolve incompatible model version; will try to create store one more time anyway" ,
95
+ [url lastPathComponent ]);
96
+ }
97
+
98
+ // Try one more time to create the store
99
+ store = [self addPersistentStoreWithType: NSSQLiteStoreType
100
+ configuration: nil
101
+ URL: url
102
+ options: options
103
+ error: &error];
104
+ if (store)
105
+ {
106
+ // If we successfully added a store, remove the error that was initially created
107
+ error = nil ;
108
+ }
106
109
}
107
110
}
108
-
109
111
[MagicalRecord handleErrors: error];
110
112
}
111
113
return store;
0 commit comments