From 4dc9dd5848c6331b5ec61edbcb8263733d4a238f Mon Sep 17 00:00:00 2001 From: Joel Menchavez Date: Tue, 5 May 2026 10:46:48 -0700 Subject: [PATCH 1/2] ensure temporary file deletion after install --- .../manager/services/IdeArchiveServiceImpl.kt | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/plugin-manager/src/main/kotlin/com/itsaky/androidide/plugins/manager/services/IdeArchiveServiceImpl.kt b/plugin-manager/src/main/kotlin/com/itsaky/androidide/plugins/manager/services/IdeArchiveServiceImpl.kt index a5acfe6c0c..115b3610e2 100644 --- a/plugin-manager/src/main/kotlin/com/itsaky/androidide/plugins/manager/services/IdeArchiveServiceImpl.kt +++ b/plugin-manager/src/main/kotlin/com/itsaky/androidide/plugins/manager/services/IdeArchiveServiceImpl.kt @@ -40,14 +40,19 @@ class IdeArchiveServiceImpl( val buffered = BufferedInputStream(NonClosingInputStream(source)) when (format) { ArchiveFormat.TAR_XZ -> { + ensureDirectory(destination) val tempFile = File.createTempFile("archive", ".tar.xz", destination.parentFile) + tempFile.deleteOnExit() try { - tempFile.outputStream().use { source.copyTo(it) } + tempFile.outputStream().use { buffered.copyTo(it) } val ok = extractTarXzViaTermux(tempFile, destination) if (ok) ExtractResult.Success(0, 0) else ExtractResult.Failure(Exception("Termux tar extraction failed")) } finally { - tempFile.delete() + if (tempFile.exists() && !tempFile.delete()) { + logger.warn("Failed to delete temporary archive: ${tempFile.absolutePath}") + tempFile.deleteOnExit() + } } } ArchiveFormat.XZ -> extractSingleStream( @@ -286,7 +291,6 @@ class IdeArchiveServiceImpl( } } - private companion object { const val COPY_BUFFER_SIZE = 64 * 1024 const val PROGRESS_REPORT_INTERVAL = 1L * 1024 * 1024 @@ -298,4 +302,4 @@ class IdeArchiveServiceImpl( ) private val logger = LoggerFactory.getLogger(IdeArchiveServiceImpl::class.java) } -} \ No newline at end of file +} From 0cedb61cebb99854c9a11cd761a8fdde40262567 Mon Sep 17 00:00:00 2001 From: Joel Menchavez Date: Tue, 5 May 2026 11:07:32 -0700 Subject: [PATCH 2/2] added pre-install cleanup of previous archive*.tar.xz files --- .../plugins/manager/services/IdeArchiveServiceImpl.kt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/plugin-manager/src/main/kotlin/com/itsaky/androidide/plugins/manager/services/IdeArchiveServiceImpl.kt b/plugin-manager/src/main/kotlin/com/itsaky/androidide/plugins/manager/services/IdeArchiveServiceImpl.kt index 115b3610e2..36b3b47230 100644 --- a/plugin-manager/src/main/kotlin/com/itsaky/androidide/plugins/manager/services/IdeArchiveServiceImpl.kt +++ b/plugin-manager/src/main/kotlin/com/itsaky/androidide/plugins/manager/services/IdeArchiveServiceImpl.kt @@ -41,6 +41,16 @@ class IdeArchiveServiceImpl( when (format) { ArchiveFormat.TAR_XZ -> { ensureDirectory(destination) + + // Clean up any stale temp archives left by a previously killed process. + destination.parentFile?.listFiles { f -> + f.name.startsWith("archive") && f.name.endsWith(".tar.xz") + }?.forEach { stale -> + if (!stale.delete()) { + logger.warn("Could not delete stale archive: ${stale.absolutePath}") + } + } + val tempFile = File.createTempFile("archive", ".tar.xz", destination.parentFile) tempFile.deleteOnExit() try {