Skip to content

Add support to prevent overwriting existing files #103

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

Merged
merged 4 commits into from
Jan 26, 2019
Merged

Add support to prevent overwriting existing files #103

merged 4 commits into from
Jan 26, 2019

Conversation

julianschiavo
Copy link
Contributor

I noticed that if I re-saved a CreamAsset with the same object (so same object id) files could get duplicated. This avoids that by adding a property to the create/save methods.

This PR also adds support to create a CreamAsset with an object id (useful if you want to save an image for an id, but you haven't created the object yet)

@caiyue1993 caiyue1993 self-assigned this Dec 8, 2018
@julianschiavo
Copy link
Contributor Author

Hey @caiyue1993, any update on this? thanks!

@caiyue1993
Copy link
Owner

Hi @justjs , sorry for the delayed reply as the daily work is quite busy.
The changes looks good to me. But since lots of apps have been using IceCream, I have one concern. If a developer has modified binary value of an image related property(which is stored as CreamAsset) and our default overwriteExistingFile value is false, the newly updated image will not be saved. Right?

@julianschiavo
Copy link
Contributor Author

Fair enough. I made these changes to try and fix the realm database getting tons of duplicate CreamAsset ids, and this seems to fix it for me. Is these a better way?

@caiyue1993
Copy link
Owner

I've retested the different cases and changed the default shouldOverwrite value from false to true. We really need to consider the compatibility.

If the default shouldOverwrite is false, the newly updated asset will not be saved. So that's unacceptable for the already-used developers. You could have a try on the example project:

dog.avatar = CreamAsset.create(object: dog, propName: Dog.AVATAR_KEY, data: imageData)

After my tweaks, you need to explicitly set the shouldOverwrite value to false where using CreamAsset if you don't want to update the existing file.

This pr is gonna ready to be merged. Thanks again @justjs !

@julianschiavo
Copy link
Contributor Author

Fair enough, that makes sense. Happy to hear we can merge this 🙂

@caiyue1993 caiyue1993 merged commit 999f3be into caiyue1993:master Jan 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants