[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 java.io.File
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
|
||||
class DependencyExtractor {
|
||||
@@ -33,10 +34,21 @@ 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.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,4 +59,10 @@ class DependencyExtractor {
|
||||
extractTarGz(archive, targetDirectory)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
val extractionTimeout = 3600L
|
||||
val extractionTimeoutUntis = TimeUnit.SECONDS
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user