-
Notifications
You must be signed in to change notification settings - Fork 473
[FIX] Move the storage location on iOS to Application Support #274
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] Move the storage location on iOS to Application Support #274
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
@krizzu, do you want to take a look?
Looks okay to me to. |
@krizzu, should that be a separate PR? |
@krizzu, I also just remembered that I had already done this, but it seems it was in a different file? Will we have to repeat this PR for v2? Seems to me v2 should just use this new directory right away. |
Haven't taken a look at V2, but agree that we should drop storage support in the caches and documents directories. |
Yes, I'd do that.
Yes please - v2 to have Application Support directory as default location. |
When is this scheduled to be merged? |
Thanks for your patience, been busy with other work recently. As we discussed on discord, I'll have to make another update where we don't delete the RCT* files. Will try and get that out today and can hopefully merge thereafter. |
…nto or out of deleting deprecated storage locations
Hey, do you need any help with reviewing/merging this thing? I'd love to start working on adding app storage support for iOS, but it looks like this merge would immensly help me with this. |
@Palid - A review would be great. @krizzu had some great feedback that I added in the latest iteration. Once no one's waiting on it then I'd love for someone with permissions to merge it in. |
…m/HeyImChris/async-storage into heyImChris/storageLocationFix_iOS
ios/RNCAsyncStorage.m
Outdated
RCTStorageDirectoryMigrationCheck(RCTCreateStorageDirectoryPath_deprecated(RCTOldStorageDirectory), RCTCreateStorageDirectoryPath_deprecated(RCTStorageDirectory), YES, YES); | ||
|
||
// Then migrate what's in "Documents/.../RCTAsyncLocalStorage_V1" to "Application Support/[bundleID]/RCTAsyncLocalStorage_V1" | ||
RCTStorageDirectoryMigrationCheck(RCTCreateStorageDirectoryPath_deprecated(RCTStorageDirectory), RCTCreateStorageDirectoryPath(RCTStorageDirectory), NO, NO); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you're passing YES, YES
to first migration, then NO, NO
to the second one, you can actually use one parameter for that, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could, but they represent pretty different actions. Also it sounds like we're going to drop RNC* migration support soon anyway so this leads us to a pretty easy plan there (drop the last parameter and keep the other one)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tido64 Do you mind giving a second look on this?
Thanks for the reviews. If it looks good, does one of you have permissions to merge? Doesn't look like I can. |
# Why react-native 0.71 removed the builtin async storage, to keep the backward compatibility, we should now vendor the *@react-native-async-storage/async-storage* close ENG-7190 # How - [tools] add @react-native-async-storage/async-storage to vendoring config - to support expo-go's scoped async storage, we should further patch react-native-async-storage. they are now in the vendoring patch. - previously on ios, we had the patch [in our fork](expo/react-native@c7d3f6d) - previously on android, we did this from [the transform tool for our fork](https://github.com/expo/expo/blob/9047ecfbe233924e4848722b518d8ce1fa8b7173/android/tools/src/main/java/host/exp/exponent/tools/ReactAndroidCodeTransformer.java#L215-L216) - the new react-native-async-storage saves data in a different storage, so they have the migration steps. to keep backward compatibility for existing expo-go. i skip the migrations and read the storage data from previous expo-go paths. - the new react-native-async-storage saves ios data in [*Application Support* rather than *Documents*](react-native-async-storage/async-storage#274). i don't want to follow the design. the reason is, besides backward compatibility, expo-go as a developer tool, it's good for developers to view the storage in *Documents*. - [ios] migrate the AsyncStorage native module from `RCTAsyncLocalStorage` to `RNCAsyncStorage` - [android] migrate `ExponentAsyncStorageModule` parent class to the new `AsyncStorageModule` - the new react-native-async-storage doesn't support turbo module, we have to move our integration from *ExpoTurboPackage* to *ExponentPackage* - the classic native module system respects the `@ReactMethod` annotation, we should add all of them in the `ExponentAsyncStorageModule`. # Test Plan - [ncl] AsyncStorage test case before this pr and after. makes sure the AsyncStorage value is kept after the changes.
# Why react-native 0.71 removed the builtin async storage, to keep the backward compatibility, we should now vendor the *@react-native-async-storage/async-storage* close ENG-7190 # How - [tools] add @react-native-async-storage/async-storage to vendoring config - to support expo-go's scoped async storage, we should further patch react-native-async-storage. they are now in the vendoring patch. - previously on ios, we had the patch [in our fork](expo/react-native@c7d3f6d) - previously on android, we did this from [the transform tool for our fork](https://github.com/expo/expo/blob/9047ecfbe233924e4848722b518d8ce1fa8b7173/android/tools/src/main/java/host/exp/exponent/tools/ReactAndroidCodeTransformer.java#L215-L216) - the new react-native-async-storage saves data in a different storage, so they have the migration steps. to keep backward compatibility for existing expo-go. i skip the migrations and read the storage data from previous expo-go paths. - the new react-native-async-storage saves ios data in [*Application Support* rather than *Documents*](react-native-async-storage/async-storage#274). i don't want to follow the design. the reason is, besides backward compatibility, expo-go as a developer tool, it's good for developers to view the storage in *Documents*. - [ios] migrate the AsyncStorage native module from `RCTAsyncLocalStorage` to `RNCAsyncStorage` - [android] migrate `ExponentAsyncStorageModule` parent class to the new `AsyncStorageModule` - the new react-native-async-storage doesn't support turbo module, we have to move our integration from *ExpoTurboPackage* to *ExponentPackage* - the classic native module system respects the `@ReactMethod` annotation, we should add all of them in the `ExponentAsyncStorageModule`. # Test Plan - [ncl] AsyncStorage test case before this pr and after. makes sure the AsyncStorage value is kept after the changes.
Summary:
Right now on iOS, the data is stored in the Documents directory (NSDocumentDirectory) on iOS and the caches directory (NSCachesDirectory) on tvOS.
These are not the best locations for the following reasons:
This fix moves the location to the Application Support directory (NSApplicationSupportDirectory). This directory is documented by Apple as "[containing] all app-specific data and support files" and it can safely contain user data. There is not risk of this purging in low memory situations and this isn't visible to iOS users.
This is not a breaking change as we are able to maintain fidelity with the one-time data migration code to our new location.
The general fix is this:
Please see https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/MacOSXDirectories/MacOSXDirectories.html#//apple_ref/doc/uid/TP40010672-CH10-SW1 and https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemOverview/FileSystemOverview.html#//apple_ref/doc/uid/TP40010672-CH2-SW1 for more documentation on this.
Test Plan: