itinance / itinance/react-native-fs
[Bug]: CopyFileTask does not close streams on exception
- Dominant language
- C++
- Stars
- 5k
- Forks
- 1k
- PR merge metrics
- No merged PRs in 30d
Description
### Issue
`CopyFileTask` does not close its input and output streams when there is an exception while writing.
### Repro Steps
1. Use `CopyFile` to copy a file from an external USB drive to a location on the android device. Use a large file so the copy takes a while.
2. Remove the USB drive during copy.
3. Application crashes.
### Investigation
When the IO Exception occurs, Android kills any processes that still have open handles on files on the USB drive. As evidence, check that logcat shows `D/voldUtils: KillProcessesUsingPath: path=/mnt/media_rw/XXXX-XXXX: Success` around the time of the IO exception.
### Suggested Fix
Move `in.close()` and `out.close()` into a `finally` block in [this function](https://github.com/itinance/react-native-fs/blob/master/android/src/main/java/com/rnfs/RNFSManager.java#L406).
Thanks for your work on this very useful package.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.