Skip to content

Commit c62ea84

Browse files
committed
Fix RCTStorageDirectoryMigrationCheck build errors & styling
1 parent 9b29ae1 commit c62ea84

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

ios/RNCAsyncStorage.m

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,13 @@ static dispatch_queue_t RCTGetMethodQueue()
169169
static void RCTStorageDirectoryMigrationCheck() {
170170
NSString *oldStorageDir = RCTCreateStorageDirectoryPath(@"RNCAsyncLocalStorage_V1");
171171

172+
NSError *error;
172173
BOOL isDir;
173174
BOOL oldExists = [[NSFileManager defaultManager] fileExistsAtPath:oldStorageDir isDirectory:&isDir];
174175

175176
// If the old directory exists, it means we need to migrate data to the new directory
176177
if (oldExists && isDir) {
177-
NSError *error;
178+
178179
BOOL migrationSuccess;
179180
// If the new storage directory already exists, then this may be caused by ever older data being left behind from previous versions.
180181
// This old data will need to be overwritten.
@@ -184,12 +185,12 @@ static void RCTStorageDirectoryMigrationCheck() {
184185
NSString *backupStorageDir = RCTCreateStorageDirectoryPath(@"RCTBackupAsyncLocalStorage_V1");
185186
// Replace any possible existing data in the new storage with old storage directory
186187
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) {
193194
// Attempt to recover from failed overwriting
194195
[[NSFileManager defaultManager] removeItemAtPath:newStorageDir error:nil];
195196
[[NSFileManager defaultManager] copyItemAtPath:backupStorageDir toPath:newStorageDir error:nil];
@@ -210,7 +211,7 @@ static void RCTStorageDirectoryMigrationCheck() {
210211

211212
// If the migration was a success, remove old storage directory
212213
if (migrationSuccess) {
213-
[[NSFileManager defaultManager] removeItemAtPath:oldStorageDir error:error];
214+
[[NSFileManager defaultManager] removeItemAtPath:oldStorageDir error:&error];
214215
if (error) {
215216
RCTMakeError(@"Failed to remove old storage directory after migration", error, nil);
216217
}

0 commit comments

Comments
 (0)