@@ -181,12 +181,13 @@ static dispatch_queue_t RCTGetMethodQueue()
181
181
static void RCTStorageDirectoryMigrationCheck () {
182
182
NSString *oldStorageDir = RCTCreateStorageDirectoryPath (@" RNCAsyncLocalStorage_V1" );
183
183
184
+ NSError *error;
184
185
BOOL isDir;
185
186
BOOL oldExists = [[NSFileManager defaultManager ] fileExistsAtPath: oldStorageDir isDirectory: &isDir];
186
187
187
188
// If the old directory exists, it means we need to migrate data to the new directory
188
189
if (oldExists && isDir) {
189
- NSError *error;
190
+
190
191
BOOL migrationSuccess;
191
192
// If the new storage directory already exists, then this may be caused by ever older data being left behind from previous versions.
192
193
// This old data will need to be overwritten.
@@ -196,12 +197,12 @@ static void RCTStorageDirectoryMigrationCheck() {
196
197
NSString *backupStorageDir = RCTCreateStorageDirectoryPath (@" RCTBackupAsyncLocalStorage_V1" );
197
198
// Replace any possible existing data in the new storage with old storage directory
198
199
migrationSuccess = [[NSFileManager defaultManager ] replaceItemAtURL: [[NSURL alloc ] initWithString: newStorageDir]
199
- withItemAtURL: [[NSURL alloc ] initWithString: oldStorageDir]
200
- backupItemName: backupStorageDir
201
- options: NSFileManagerItemReplacementUsingNewMetadataOnly
202
- resultingItemURL: nil
203
- error: &error];
204
- if (error || !success ) {
200
+ withItemAtURL: [[NSURL alloc ] initWithString: oldStorageDir]
201
+ backupItemName: backupStorageDir
202
+ options: NSFileManagerItemReplacementUsingNewMetadataOnly
203
+ resultingItemURL: nil
204
+ error: &error];
205
+ if (error || !migrationSuccess ) {
205
206
// Attempt to recover from failed overwriting
206
207
[[NSFileManager defaultManager ] removeItemAtPath: newStorageDir error: nil ];
207
208
[[NSFileManager defaultManager ] copyItemAtPath: backupStorageDir toPath: newStorageDir error: nil ];
@@ -222,7 +223,7 @@ static void RCTStorageDirectoryMigrationCheck() {
222
223
223
224
// If the migration was a success, remove old storage directory
224
225
if (migrationSuccess) {
225
- [[NSFileManager defaultManager ] removeItemAtPath: oldStorageDir error: error];
226
+ [[NSFileManager defaultManager ] removeItemAtPath: oldStorageDir error: & error];
226
227
if (error) {
227
228
RCTMakeError (@" Failed to remove old storage directory after migration" , error, nil );
228
229
}
0 commit comments