Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: check directory before call delete on iOS #1066

Merged
merged 3 commits into from
Feb 23, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions packages/default-storage/ios/RNCAsyncStorage.mm
Original file line number Diff line number Diff line change
Expand Up @@ -869,8 +869,14 @@ - (BOOL)_passthroughDelegate

[_manifest removeAllObjects];
[RCTGetCache() removeAllObjects];
NSDictionary *error = RCTDeleteStorageDirectory();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be simpler if we check whether error.code == NSFileNoSuchFileError in RCTDeleteStorageDirectory() and ignore it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, it works and is also more clean, thanks for that.
I'm kinda new on Objective-C, I only return nil to ignore, if it was better to return another thing I could change again.

callback(@[RCTNullIfNil(error)]);

NSFileManager *fileManager = [NSFileManager defaultManager];
if ([fileManager fileExistsAtPath:RCTGetStorageDirectory()]) {
NSDictionary *error = RCTDeleteStorageDirectory();
callback(@[RCTNullIfNil(error)]);
} else {
callback(@[[NSNull null]]);
}
}

// clang-format off
Expand Down