[TECHNICAL] Stream handling and double-close in `UploadFileFromContentUriWorker`
In copyFileToLocalStorage(), streams are not closed safely and the output stream is closed twice.
- Double-close:
outputStreamis closed insideoutputStream.use { ... }, thenoutputStream.close()is called again. The second close is redundant and can cause issues. - Leak on error:
inputStreamis not used inside auseblock. IfinputStream?.copyTo(fileOut)throws, the input stream is never closed.
Suggested fix: Use inputStream?.use { it.copyTo(fileOut) } so the input stream is always closed, and remove the explicit inputStream?.close() and outputStream.close() calls so only use is responsible for closing.
Hi @joragua, hope you're doing well! I'm new here and recently discovered this repository. I really enjoy Android development and would love the opportunity to contribute. If this issue is still available, I'd be happy to work on it. Thanks! 😊
Please submit a pull request right away. Thank you!
okay, I got it, thanks
Hey, @DeepDiver1975 I've created the PR for this issue. could you pls review it, when you have a chance? thank you.
@dataCenter430 thanks for your engagements and contributions. We'll review the code, give you some tips and then, test and QA it. Please keep tuned