@@ -169,12 +169,13 @@ static dispatch_queue_t RCTGetMethodQueue()
169
169
static void RCTStorageDirectoryMigrationCheck () {
170
170
NSString *oldStorageDir = RCTCreateStorageDirectoryPath (@" RNCAsyncLocalStorage_V1" );
171
171
172
+ NSError *error;
172
173
BOOL isDir;
173
174
BOOL oldExists = [[NSFileManager defaultManager ] fileExistsAtPath: oldStorageDir isDirectory: &isDir];
174
175
175
176
// If the old directory exists, it means we need to migrate data to the new directory
176
177
if (oldExists && isDir) {
177
- NSError *error;
178
+
178
179
BOOL migrationSuccess;
179
180
// If the new storage directory already exists, then this may be caused by ever older data being left behind from previous versions.
180
181
// This old data will need to be overwritten.
@@ -184,12 +185,12 @@ static void RCTStorageDirectoryMigrationCheck() {
184
185
NSString *backupStorageDir = RCTCreateStorageDirectoryPath (@" RCTBackupAsyncLocalStorage_V1" );
185
186
// Replace any possible existing data in the new storage with old storage directory
186
187
migrationSuccess = [[NSFileManager defaultManager ] replaceItemAtURL: [[NSURL alloc ] initWithString: newStorageDir]
187
- withItemAtURL: [[NSURL alloc ] initWithString: oldStorageDir]
188
- backupItemName: backupStorageDir
189
- options: NSFileManagerItemReplacementUsingNewMetadataOnly
190
- resultingItemURL: nil
191
- error: &error];
192
- if (error || !success ) {
188
+ withItemAtURL: [[NSURL alloc ] initWithString: oldStorageDir]
189
+ backupItemName: backupStorageDir
190
+ options: NSFileManagerItemReplacementUsingNewMetadataOnly
191
+ resultingItemURL: nil
192
+ error: &error];
193
+ if (error || !migrationSuccess ) {
193
194
// Attempt to recover from failed overwriting
194
195
[[NSFileManager defaultManager ] removeItemAtPath: newStorageDir error: nil ];
195
196
[[NSFileManager defaultManager ] copyItemAtPath: backupStorageDir toPath: newStorageDir error: nil ];
@@ -210,7 +211,7 @@ static void RCTStorageDirectoryMigrationCheck() {
210
211
211
212
// If the migration was a success, remove old storage directory
212
213
if (migrationSuccess) {
213
- [[NSFileManager defaultManager ] removeItemAtPath: oldStorageDir error: error];
214
+ [[NSFileManager defaultManager ] removeItemAtPath: oldStorageDir error: & error];
214
215
if (error) {
215
216
RCTMakeError (@" Failed to remove old storage directory after migration" , error, nil );
216
217
}
0 commit comments