[K/N lib] Add timeout for native dependency extraction

This commit is contained in:
Ilya Matveev
2018-08-28 08:17:37 +03:00
committed by Mikhail Glukhikh
parent db29d12c60
commit d49ff1aa2c
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.konan.util
import org.jetbrains.kotlin.konan.file.unzipTo
import java.io.File
import java.util.concurrent.TimeUnit
internal class DependencyExtractor {
private val useZip = System.getProperty("os.name").startsWith("Windows")
@@ -21,10 +22,22 @@ internal class DependencyExtractor {
val tarProcess = ProcessBuilder().apply {
command("tar", "-xzf", tarGz.canonicalPath)
directory(targetDirectory)
inheritIO()
}.start()
tarProcess.waitFor()
if (tarProcess.exitValue() != 0) {
throw RuntimeException("Cannot extract archive with dependency: ${tarGz.canonicalPath}")
val finished = tarProcess.waitFor(extractionTimeout, extractionTimeoutUntis)
when {
finished && tarProcess.exitValue() != 0 ->
throw RuntimeException(
"Cannot extract archive with dependency: ${tarGz.canonicalPath}.\n" +
"Tar exit code: ${tarProcess.exitValue()}."
)
!finished -> {
tarProcess.destroy()
throw RuntimeException(
"Cannot extract archive with dependency: ${tarGz.canonicalPath}.\n" +
"Tar process hasn't finished in ${extractionTimeoutUntis.toSeconds(extractionTimeout)} sec."
)
}
}
}
@@ -35,4 +48,9 @@ internal class DependencyExtractor {
extractTarGz(archive, targetDirectory)
}
}
companion object {
val extractionTimeout = 3600L
val extractionTimeoutUntis = TimeUnit.SECONDS
}
}