[dependencies] Add timeout for dependency extraction (#1947)
This commit is contained in:
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.konan.util
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.konan.file.unzipTo
|
import org.jetbrains.kotlin.konan.file.unzipTo
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
|
|
||||||
class DependencyExtractor {
|
class DependencyExtractor {
|
||||||
@@ -33,10 +34,21 @@ class DependencyExtractor {
|
|||||||
val tarProcess = ProcessBuilder().apply {
|
val tarProcess = ProcessBuilder().apply {
|
||||||
command("tar", "-xzf", tarGz.canonicalPath)
|
command("tar", "-xzf", tarGz.canonicalPath)
|
||||||
directory(targetDirectory)
|
directory(targetDirectory)
|
||||||
|
inheritIO()
|
||||||
}.start()
|
}.start()
|
||||||
tarProcess.waitFor()
|
val finished = tarProcess.waitFor(extractionTimeout, extractionTimeoutUntis)
|
||||||
if (tarProcess.exitValue() != 0) {
|
when {
|
||||||
throw RuntimeException("Cannot extract archive with dependency: ${tarGz.canonicalPath}")
|
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.")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,4 +59,10 @@ class DependencyExtractor {
|
|||||||
extractTarGz(archive, targetDirectory)
|
extractTarGz(archive, targetDirectory)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
val extractionTimeout = 3600L
|
||||||
|
val extractionTimeoutUntis = TimeUnit.SECONDS
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user