@@ -215,12 +215,32 @@ static void RCTStorageDirectoryCleanupOld(NSString *oldDirectoryPath)
215
215
}
216
216
}
217
217
218
+ static void _createStorageDirectory (NSString *storageDirectory, NSError **error)
219
+ {
220
+ [[NSFileManager defaultManager ] createDirectoryAtPath: storageDirectory
221
+ withIntermediateDirectories: YES
222
+ attributes: nil
223
+ error: error];
224
+ }
225
+
218
226
static void RCTStorageDirectoryMigrate (NSString *oldDirectoryPath, NSString *newDirectoryPath, BOOL shouldCleanupOldDirectory)
219
227
{
220
228
NSError *error;
221
229
// Migrate data by copying old storage directory to new storage directory location
222
230
if (![[NSFileManager defaultManager ] copyItemAtPath: oldDirectoryPath toPath: newDirectoryPath error: &error]) {
223
- RCTStorageDirectoryMigrationLogError (@" Failed to copy old storage directory to new storage directory location during migration" , error);
231
+ // the new storage directory "Application Support/[bundleID]/RCTAsyncLocalStorage_V1" seems unable to migrate
232
+ // because folder "Application Support/[bundleID]" doesn't exist.. create this folder and attempt folder copying again
233
+ if (error != nil && error.code == 4 && [newDirectoryPath isEqualToString: RCTGetStorageDirectory ()]) {
234
+ NSError *error = nil ;
235
+ _createStorageDirectory (RCTCreateStorageDirectoryPath (@" " ), &error);
236
+ if (error == nil ) {
237
+ RCTStorageDirectoryMigrate (oldDirectoryPath, newDirectoryPath, shouldCleanupOldDirectory);
238
+ } else {
239
+ RCTStorageDirectoryMigrationLogError (@" Failed to create storage directory during migration." , error);
240
+ }
241
+ } else {
242
+ RCTStorageDirectoryMigrationLogError (@" Failed to copy old storage directory to new storage directory location during migration" , error);
243
+ }
224
244
} else if (shouldCleanupOldDirectory) {
225
245
// If copying succeeds, remove old storage directory
226
246
RCTStorageDirectoryCleanupOld (oldDirectoryPath);
@@ -356,10 +376,7 @@ - (NSDictionary *)_ensureSetup
356
376
357
377
NSError *error = nil ;
358
378
if (!RCTHasCreatedStorageDirectory) {
359
- [[NSFileManager defaultManager ] createDirectoryAtPath: RCTGetStorageDirectory ()
360
- withIntermediateDirectories: YES
361
- attributes: nil
362
- error: &error];
379
+ _createStorageDirectory (RCTGetStorageDirectory (), &error);
363
380
if (error) {
364
381
return RCTMakeError (@" Failed to create storage directory." , error, nil );
365
382
}
0 commit comments