Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,29 @@ class IdeArchiveServiceImpl(
val buffered = BufferedInputStream(NonClosingInputStream(source))
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)
Comment thread
jomen-adfa marked this conversation as resolved.
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()
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}
}
ArchiveFormat.XZ -> extractSingleStream(
Expand Down Expand Up @@ -286,7 +301,6 @@ class IdeArchiveServiceImpl(
}
}


private companion object {
const val COPY_BUFFER_SIZE = 64 * 1024
const val PROGRESS_REPORT_INTERVAL = 1L * 1024 * 1024
Expand All @@ -298,4 +312,4 @@ class IdeArchiveServiceImpl(
)
private val logger = LoggerFactory.getLogger(IdeArchiveServiceImpl::class.java)
}
}
}
Loading