Skip to content

Added the ability to set the storage location on iOS #18

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

Closed

Conversation

adamivancza
Copy link

#13

Moved my changes from this PR: https://github.com/facebook/react-native/pull/20904/files
I didn't find any tests in the repo atm so I wasn't able to add those. I can see a PR with detox tests though - if that's merged I can add some tests.

@krizzu
Copy link
Member

krizzu commented Feb 23, 2019

Hey @adamivancza, thank you for your input!

I'm going to hold off merging this PR till I finish #15 - I'd love to have some tests on new functionality, hope you don't mind waiting.

@adamivancza
Copy link
Author

sure thing @krizzu - could you ping me here once you've finished with #15?

@krizzu
Copy link
Member

krizzu commented Feb 25, 2019

@adamivancza Hey,
Detox is merged, so you can rebase your branch. Would be nice if you could add some tests for storage directory changes.

Also, we don't have generated docs from comments yet, so could you please add this method to docs, mark it as iOS only and describe its functionality and purpose?

Thanks a lot

@krizzu krizzu added enhancement New feature or request platform: iOS This is iOS specific labels Feb 26, 2019
@adamivancza
Copy link
Author

thx @krizzu - will do those over the weekend.

@@ -16,9 +16,25 @@
#import "RCTLog.h"
#import "RCTUtils.h"

typedef NS_ENUM(NSInteger, RCTStorageLocation) {
Documents,
ApplicationSupport

Choose a reason for hiding this comment

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

@krizzu Is this what we want? only support Documents and ApplicationSupport directories?

Copy link
Member

Choose a reason for hiding this comment

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

It's been discussed in #13, where ApplicationSupport is more safe to store app-specific data.

Do you have any suggestion if there should be more/less options to choose from?

Choose a reason for hiding this comment

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

@krizzu Oh, I scan those things, so now I think we may need to handle two things:

  1. Provide options for user to save data. (I suppose support three options, Documents,Library,tmp, https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemOverview/FileSystemOverview.html#//apple_ref/doc/uid/TP40010672-CH2-SW1, tmp is also meaningful IMO, provide temp storage).
  2. Not backed up by iTunes. (For the Application Support directory, it would backed up by iTunes and iCloud, so if we use that, we need use NSURLIsExcludedFromBackupKey for files we stored includes manifest file.

Copy link
Author

Choose a reason for hiding this comment

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

  1. not sure about tmp - do you have any use cases where it might be helpful? I think that would just cause confusion as tmp dir can be deleted deleted by OS at any time.
  2. maybe we can add a flag to control that? it could be useful to have this file backed up.

@@ -455,4 +489,10 @@ - (NSDictionary *)_writeEntry:(NSArray<NSString *> *)entry changedManifest:(BOOL
}
}

RCT_EXPORT_METHOD(setStorageLocation:(RCTStorageLocation)location)
{
storageLocation = location;

Choose a reason for hiding this comment

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

We can have equal check in here.

@@ -16,9 +16,25 @@
#import "RCTLog.h"
#import "RCTUtils.h"

typedef NS_ENUM(NSInteger, RCTStorageLocation) {
Documents,

Choose a reason for hiding this comment

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

Can we conform Apple naming style?
image

@adamivancza
Copy link
Author

Sorry about this but I still haven't got time to finish up the tests - will try to find some time to do them.

@adamivancza
Copy link
Author

hey @krizzu - finally finished with the PR! :)

Copy link
Member

@krizzu krizzu left a comment

Choose a reason for hiding this comment

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

This looks great 👏 I left two comments regarding some functionality. Please let me know what you think.

Also, I believe it'd be nice to document this feature and explain reasons why we added it.

thanks.

* Call this set the storage location.
* @param storageLocation The storage location. Can be 'documents' or 'applicationSupport'.
*
* **Note**: changing this only sets the location for future actions and does not migrate
Copy link
Member

Choose a reason for hiding this comment

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

This bit is bit worrying. We had similar issue #55, where storage location was changed and devs were losing data. Maybe we could come up with migration plan for data?

Copy link
Author

Choose a reason for hiding this comment

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

The default locations is still the same, imo devs can only loose data once updated to a new version which contains this change AND change the storage location specifically without copying their data.

Copy link
Member

Choose a reason for hiding this comment

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

I see, thanks. We should provide a note in docs that this can happen, so they know upfront.

},

StorageLocationIOS: {
documents: 'documents',
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 we could export constants to be used in JS, what do you think?

Copy link
Author

Choose a reason for hiding this comment

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

oh yeah that's a great shout! will do that

@krizzu
Copy link
Member

krizzu commented Apr 11, 2019

Hey @adamivancza, thank you for your work so far 👏

We merged another PR which contains some native iOS code, I hope this won't give you much trouble.

@reilem
Copy link
Contributor

reilem commented Apr 14, 2019

@krizzu There are some conflicting changes with my fix, mainly with RCTGetStorageDirectory and RCTGetManifestFilePath. This branch makes some changes to those functions (that I don't entirely agree with). In current master I have made RCTCreateManifestFilePath and RCTCreateStorageDirectoryPath specifically in case you need a location that isn't the default. I would use these Create functions in conjunction with the already existing RCTGetManifestFilePath and RCTGetStorageDirectory. Otherwise the dispatch_once functionality might cause unpredictable behaviour.

@krizzu
Copy link
Member

krizzu commented Jun 18, 2019

Hey @adamivancza,

Thank you so much for work you put into this PR, but I'm sorry to say that I'm going to close it. We're moving into Async Storage v2, where we do a lot of breaking changes.

There's a plan to still support the current implementation of AS as another Backend Storage in v2 - maybe you'd like to take part in it? We plan to create it from the ground up, so I believe it'd best time to add additional functionality (not preset in AS before)

thanks.

@krizzu krizzu closed this Jun 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request platform: iOS This is iOS specific
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants