clean up orphan temp files on android share failure paths
createFile writes to the cache dir before the copy/compress attempt, so
the bail-out paths left a temp file behind. Delete the file on each
failure path (no input stream, copy/write throws, getVideoInfo returns
null). Also wraps the image write in a use {} block so the stream is
closed if compress throws. The success path still keeps the file, since
its path is passed to the compose intent downstream.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
(cherry picked from commit 9d62588a2739d7eb1f12164d0f2c4ae7d5be4e38)
This commit is contained in:
+20
-4
@@ -164,15 +164,25 @@ class ExpoReceiveAndroidIntentsModule : Module() {
|
|||||||
// app, since this runs synchronously on the module init path.
|
// app, since this runs synchronously on the module init path.
|
||||||
try {
|
try {
|
||||||
FileOutputStream(file).use { out ->
|
FileOutputStream(file).use { out ->
|
||||||
val input = appContext.currentActivity?.contentResolver?.openInputStream(uri) ?: return
|
val input =
|
||||||
|
appContext.currentActivity?.contentResolver?.openInputStream(uri)
|
||||||
|
?: run {
|
||||||
|
file.delete()
|
||||||
|
return
|
||||||
|
}
|
||||||
input.use { it.copyTo(out) }
|
input.use { it.copyTo(out) }
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.w(TAG, "Failed to copy shared video to cache", e)
|
Log.w(TAG, "Failed to copy shared video to cache", e)
|
||||||
|
file.delete()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val info = getVideoInfo(uri) ?: return
|
val info =
|
||||||
|
getVideoInfo(uri) ?: run {
|
||||||
|
file.delete()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
val encodedText = text?.let { URLEncoder.encode(it, "UTF-8") }
|
val encodedText = text?.let { URLEncoder.encode(it, "UTF-8") }
|
||||||
|
|
||||||
@@ -198,10 +208,16 @@ class ExpoReceiveAndroidIntentsModule : Module() {
|
|||||||
// We have to save this so that we can access it later when uploading the image.
|
// We have to save this so that we can access it later when uploading the image.
|
||||||
// createTempFile will automatically place a unique string between "img" and "temp.jpeg"
|
// createTempFile will automatically place a unique string between "img" and "temp.jpeg"
|
||||||
val file = createFile("jpeg")
|
val file = createFile("jpeg")
|
||||||
val out = FileOutputStream(file)
|
try {
|
||||||
|
FileOutputStream(file).use { out ->
|
||||||
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out)
|
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out)
|
||||||
out.flush()
|
out.flush()
|
||||||
out.close()
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.w(TAG, "Failed to write shared image to cache", e)
|
||||||
|
file.delete()
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
return mapOf(
|
return mapOf(
|
||||||
"width" to bitmap.width,
|
"width" to bitmap.width,
|
||||||
|
|||||||
Reference in New Issue
Block a user