[TECHNICAL] Stream handling and double-close in UploadFileFromContentUriWorker#4799
Conversation
hey, @CLAassistant |
|
Thanks for the contribution @dataCenter430 . I'll give you some tips that you will also find in our CONTRIBUTING file:
Any question about the process, @joragua or myself will be happy to help you!! |
da774d8 to
d53c1de
Compare
|
hi, @jesmrec |
|
that's good @dataCenter430 . Just an extra small change regarding:
i suggest you the following text:
As soon as it is done, @joragua will review your contribution as soon as he is available. A code review first, and a QA stage later would suggest also changes or improvements in the contribution. Keep tuned! |
|
I will take care of this as soon as possible 🙌🏻 I will ping you when it's ready |
UploadFileFromContentUriWorker
joragua
left a comment
There was a problem hiding this comment.
Good job @dataCenter430! 🙌🏻 Some comments here.
NOTE: Regarding the first commit, I'd use refactor: prefix since the code you added is a change in the code but not a fix.
655c645 to
5de0791
Compare
|
Hi, @joragua thanks for your review. |
|
Thanks for the changes @dataCenter430! Just two comments before doing the second CR round:
Let us know if you have any question and we will help you! 😄 |
3c4f828 to
bcf4a73
Compare
Hi, @joragua |
joragua
left a comment
There was a problem hiding this comment.
One more comment and it's ready @dataCenter430
bcf4a73 to
20c1564
Compare
joragua
left a comment
There was a problem hiding this comment.
LGTM now! ✅ Let's move it to QA
|
Approved on my side 🚀 @dataCenter430 please rebase the branch and we will merge your contribution. Thanks a lot for your patience!! |
|
Hi, @jesmrec |
|
@dataCenter430 we use Could you remove the merge commit and rebase? Here: you'll find how to do it, anyway, if you have any question let us know. Thanks!! |
e33c1ba to
2bf00d9
Compare
|
Thanks again @dataCenter430 . Merging, the contribution will be available in 4.8.0 🚀 |
|
I'm so happy to contribute to Android! |
Related Issues
In
copyFileToLocalStorage():Double-close:
outputStreamwas closed insideoutputStream.use { ... }, thenoutputStream.close()was called again. Closing an already-closed stream is redundant and can cause issues on some implementations.Leak on error:
inputStreamwas not managed withuse. IfinputStream?.copyTo(fileOut)threw, the input stream was never closed, leaking the underlying content resolver stream.App: #4798
Solution
Both streams are now managed with
use: the content resolver input withopenInputStream(contentUri)?.use { ... }, and the file output withFileOutputStream(cachePath).use { ... }. Both are closed when the block exits, including on exception.The explicit
inputStream?.close()andoutputStream.close()calls were removed so onlyuseis responsible for closing; no double-close.Nested
useblocks ensure the output stream is closed first, then the input stream; any exception duringcopyTostill closes both.Add changelog files for the fixed issues in folder changelog/unreleased. More info here