-
Notifications
You must be signed in to change notification settings - Fork 961
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
writeFile() not truncating file contents on Android 10 #837
base: master
Are you sure you want to change the base?
Conversation
… when append is false
@SilverInfinity hello. |
Any news on that PR please ? Can you please merge it? |
@Iyoss
However, this appears to not be correct, as on android 10, passing "w" for write-only access is not in fact erasing whatever data is currently in the file. This method linked out to ContentProvider.openFile which mention's ParcelFileDescriptor.parseMode(String)
That, coupled with this android bug ticket, which mention's needing to pass 't' in the open mode is where I got the "wt" file mode. To answer your question, looking back on it, I am not entirely sure. The documentation on its own did not appear to be entirely clear on it, or contradictory in places. I am sure that it works for absolute file paths, such as files stored in RNFSDocumentDirectoryPath as is the use case for my application where i noticed the issue. Also tested on multiple versions of android. However I haven't tested it with content uris. If it is a content uri, then it looks like the Content Resolver or Content Provider could be overwritten with a custom implementation? I am not sure what to do in such a case. I can change "wt" to "rwt". "rwt" also fixes the issue, and is explicitly mentioned in the android documentation. However, that may require adding READ_EXTERNAL_STORAGE permissions where it was previously not required. I was trying to avoid that. |
As I have explained above, Would you like me to edit this PR to use "rwt" or leave it as "wt"? Both options solve the issue. I have been using a forked branch in production for 2 months now, and have seen no issues in using "wt". However our use case is very simple, only writing txt and image files to the document directory. |
Anything we can do here to find a final solution for your discussion, guys? |
I can verify that this fixes an issue I was having on an app that was using redux-persist-fs. Any time a reducers content was reduced in size and commited to disk on android 10, the app would be unable to rehydrate any data for that reducer as it left non-valid JSON in the persistors file. This patch has fixed the android 10 issue and works as expected on previous versions (physically tested on 9 and 8). It would be ideal to get this merged, currently using patch-package in my repo to apply the fix. |
I also would like to see this merged. |
Just one more person sharing that they need to use 2 forks because of this, please merge 😄 |
Hello @SilverInfinity Disclaimer: I found this issue while researching. I don't use this library or react native.
We used "wt", after sometime users reported that they can no longer save the files. This specifically happen to files from Google Drive. The error we were getting is: Again, I don't know this library but I felt like reporting it as it seemed relevant :) |
@sh-zam Thanks for the heads up about I just filed a bug for this on the Android issue tracker. Hopefully, someone will follow up with more guidance and updated documentation. FYI, I'm an Android developer, not a react native developer or user of this library. I also got here while researching this issue. |
I just spent waaaaaaay too much on a bug caused by this. Can we please have an update on gettings this approved? |
any news? |
Use "rwt" mode instead of "wt" as the "wt" seems to not work with Google Drive. See this: itinance/react-native-fs#837 (comment)
Fix for #700
As of Android 10, passing just "w" will no longer truncate the file after writing. You must also explicitly pass the truncate option. Previous versions of android treated "w" and "wt" as the same.
Changes: