Skip to content

Commit 2aa0c17

Browse files
committed
Minor requested changes
* Use const and RCT prefix for RCTOldStorageDirectory * Log errors instead of throwing exceptions * Disable main queue setup
1 parent 0601d5c commit 2aa0c17

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

ios/RNCAsyncStorage.m

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -175,15 +175,12 @@ static dispatch_queue_t RCTGetMethodQueue()
175175
}
176176

177177

178-
NSString *OldStorageDirectory = @"RNCAsyncLocalStorage_V1";
178+
NSString *const RCTOldStorageDirectory = @"RNCAsyncLocalStorage_V1";
179179
/**
180180
* Creates an NSException used during Storage Directory Migration.
181181
*/
182-
static NSException *RCTStorageDirectionMigrationException(NSString *reason, NSError *error) {
183-
NSMutableString *reasonString = [[NSMutableString alloc] initWithString:reason];
184-
[reasonString appendString:@" - "];
185-
[reasonString appendString:[error description]];
186-
return [[NSException alloc] initWithName:@"RCTStorageDirectoryMigrationFailure" reason:reasonString userInfo:nil];
182+
static void RCTStorageDirectoryMigrationLogError(NSString *reason, NSError *error) {
183+
NSLog(@"%@: %@", reason, error ? error.description : @"");
187184
}
188185

189186
/**
@@ -196,24 +193,24 @@ static void RCTStorageDirectoryMigrationCheck() {
196193
NSError *error;
197194
BOOL isDir;
198195
// If the old directory exists, it means we need to migrate data to the new directory
199-
if ([[NSFileManager defaultManager] fileExistsAtPath:RCTCreateStorageDirectoryPath(OldStorageDirectory) isDirectory:&isDir] && isDir) {
196+
if ([[NSFileManager defaultManager] fileExistsAtPath:RCTCreateStorageDirectoryPath(RCTOldStorageDirectory) isDirectory:&isDir] && isDir) {
200197
// Check if the new storage directory location already exists
201198
BOOL newStorageDirectoryExists = [[NSFileManager defaultManager] fileExistsAtPath:RCTGetStorageDirectory() isDirectory:&isDir];
202199
if (newStorageDirectoryExists) {
203200
// If the new storage directory location already exists, remove existing directory
204201
newStorageDirectoryExists = !([[NSFileManager defaultManager] removeItemAtPath:RCTGetStorageDirectory() error:&error]);
205202
if (newStorageDirectoryExists) {
206-
@throw RCTStorageDirectionMigrationException(@"Failed to clear pre-existing storage directory", error);
203+
RCTStorageDirectoryMigrationLogError(@"Failed to clear pre-existing storage directory", error);
207204
}
208205
}
209206
if (!newStorageDirectoryExists) {
210207
// If new storage direction doesn't exist, copy old storage directory to new location
211-
if (![[NSFileManager defaultManager] copyItemAtPath:RCTCreateStorageDirectoryPath(OldStorageDirectory) toPath:RCTGetStorageDirectory() error:&error]) {
212-
@throw RCTStorageDirectionMigrationException(@"Failed to copy old storage directory to new storage directory", error);
208+
if (![[NSFileManager defaultManager] copyItemAtPath:RCTCreateStorageDirectoryPath(RCTOldStorageDirectory) toPath:RCTGetStorageDirectory() error:&error]) {
209+
RCTStorageDirectoryMigrationLogError(@"Failed to copy old storage directory to new storage directory", error);
213210
} else {
214211
// If copying succeeds, remove old storage directory
215-
[[NSFileManager defaultManager] removeItemAtPath:RCTCreateStorageDirectoryPath(OldStorageDirectory) error:&error];
216-
if (error) @throw RCTStorageDirectionMigrationException(@"Failed to remove old storage directory after migration", error);
212+
[[NSFileManager defaultManager] removeItemAtPath:RCTCreateStorageDirectoryPath(RCTOldStorageDirectory) error:&error];
213+
if (error) RCTStorageDirectoryMigrationLogError(@"Failed to remove old storage directory after migration", error);
217214
}
218215
}
219216
}
@@ -232,7 +229,7 @@ @implementation RNCAsyncStorage
232229
}
233230

234231
+ (BOOL)requiresMainQueueSetup {
235-
return YES;
232+
return NO;
236233
}
237234

238235
- (instancetype)init
@@ -506,7 +503,7 @@ - (BOOL)_passthroughDelegate
506503
}
507504

508505
RCT_EXPORT_METHOD(multiMerge:(NSArray<NSArray<NSString *> *> *)kvPairs
509-
callback:(RCTResponseSenderBlock)callback)
506+
callback:(RCTResponseSenderBlock)callback)
510507
{
511508
if (self.delegate != nil) {
512509
NSMutableArray<NSString *> *keys = [NSMutableArray arrayWithCapacity:kvPairs.count];
@@ -640,3 +637,4 @@ - (BOOL)_passthroughDelegate
640637
}
641638

642639
@end
640+

0 commit comments

Comments
 (0)