Page MenuHomePhabricator

[native] Unlink files as necessary in `useUploadSelectedMedia`
ClosedPublic

Authored by atul on May 2 2023, 12:59 PM.
Tags
None
Referenced Files
F3398672: D7704.diff
Sun, Dec 1, 11:59 PM
Unknown Object (File)
Sun, Nov 3, 8:18 PM
Unknown Object (File)
Oct 28 2024, 10:23 AM
Unknown Object (File)
Oct 28 2024, 10:23 AM
Unknown Object (File)
Oct 28 2024, 10:23 AM
Unknown Object (File)
Oct 28 2024, 10:23 AM
Unknown Object (File)
Oct 28 2024, 10:23 AM
Unknown Object (File)
Oct 28 2024, 10:23 AM
Subscribers

Details

Summary

expo-image-picker will always copy the contents of image into cache and provide a URL to cached image:

3a90ca.png (220×1 px, 48 KB)

ed2cb6.png (528×1 px, 124 KB)

As a result we'll ALWAYS need to unlink the selection.uri. We also clean up processedMedia.uploadURI if necessary.

Test Plan

Tested small images which weren't processed and large images which were processed. Logged the contents of selection, processedMedia, and urisToBeDisposed. When I commented out the unlink line (159), I was able to open all of the images in Finder. When I uncommented the unlink line, all of the images were inaccessible because they'd been removed:

b0aa05.png (590×1 px, 141 KB)

Before:

020492.png (2×3 px, 2 MB)

After:

b07830.png (1×2 px, 550 KB)

Tested Android by ensuring that files remained in caches when unlink was commented out and weren't in caches when unlink was uncommented:

Selected an image avatar and ensured contents were as before:

8e30ed.png (208×1 px, 52 KB)

Selected an image avatar with unlink left out and observed that new files were added:

50b63b.png (330×1 px, 78 KB)

Diff Detail

Repository
rCOMM Comm
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

atul attached a referenced file: F519774: ed2cb6.png. (Show Details)
atul attached a referenced file: F519773: 3a90ca.png. (Show Details)
atul published this revision for review.May 2 2023, 1:02 PM
atul edited the test plan for this revision. (Show Details)
atul added inline comments.
native/avatars/avatar-hooks.js
155–158 ↗(On Diff #26017)

So these unlink calls totally could be in a finally block based on what I read/verified:

e5e484.png (962×1 px, 215 KB)

However, it's probably not intuitive that the finally executes before the return in the catch block?

Please amend test plan to include testing Android as well as iOS.

Also, can we not pass filesystem.unlink in directly, without needing an extra lambda?

native/avatars/avatar-hooks.js
125 ↗(On Diff #26017)

Is it always safe to unset here? Did you test on Android?

This revision is now accepted and ready to land.May 2 2023, 1:12 PM

Also, can we not pass filesystem.unlink in directly, without needing an extra lambda?

Yeah, had some temporary logging within the forEach, will pass in filesystem.unlink directly.

native/avatars/avatar-hooks.js
125 ↗(On Diff #26017)

I'm not sure I understand?

pass filesystem.unlink directly into forEach

native/avatars/avatar-hooks.js
156 ↗(On Diff #26023)

I think you forgot to remove this console.log

125 ↗(On Diff #26017)

Meant to say "unlink". Wondering if unlinking the selection.uri we get from earlier could potentially lead to issues

native/avatars/avatar-hooks.js
156 ↗(On Diff #26023)

Oh dang, I think I added it in the last update

125 ↗(On Diff #26017)

Yeah tested on Android + read the expo code and it's good.

rebase before addressing feedback

This revision was landed with ongoing or failed builds.May 3 2023, 6:53 AM
This revision was automatically updated to reflect the committed changes.