make vcs command timeout configurable

Sat, 22 Jul 2023 11:32:27 +0200

author
Mike Becker <universe@uap-core.de>
date
Sat, 22 Jul 2023 11:32:27 +0200
changeset 281
c15b9555ecf3
parent 280
12b898531d1a
child 282
c112fad21bf6

make vcs command timeout configurable

relates to #274

src/main/kotlin/de/uapcore/lightpit/vcs/HgConnector.kt file | annotate | diff | comparison | revisions
src/main/kotlin/de/uapcore/lightpit/vcs/VcsConnector.kt file | annotate | diff | comparison | revisions
     1.1 --- a/src/main/kotlin/de/uapcore/lightpit/vcs/HgConnector.kt	Tue Jul 18 18:05:49 2023 +0200
     1.2 +++ b/src/main/kotlin/de/uapcore/lightpit/vcs/HgConnector.kt	Sat Jul 22 11:32:27 2023 +0200
     1.3 @@ -27,7 +27,6 @@
     1.4  package de.uapcore.lightpit.vcs
     1.5  
     1.6  import java.nio.file.Files
     1.7 -import java.nio.file.Path
     1.8  import kotlin.io.path.ExperimentalPathApi
     1.9  import kotlin.io.path.deleteRecursively
    1.10  
    1.11 @@ -42,7 +41,7 @@
    1.12       * Checks, if the specified binary is available and executable.
    1.13       */
    1.14      fun checkAvailability(): Boolean {
    1.15 -        return when (val versionInfo = invokeCommand(Path.of("."), "--version")) {
    1.16 +        return when (val versionInfo = invokeCommand("--version")) {
    1.17              is VcsConnectorResult.Success -> versionInfo.content.contains("Mercurial")
    1.18              else -> false
    1.19          }
    1.20 @@ -61,13 +60,15 @@
    1.21          } catch (e: Throwable) {
    1.22              return VcsConnectorResult.Error("Creating temporary directory for VCS connection failed: " + e.message)
    1.23          }
    1.24 -        val init = invokeCommand(tmpDir, "init")
    1.25 +        val init = invokeCommand("init", workingDir = tmpDir)
    1.26          if (init is VcsConnectorResult.Error) {
    1.27              return init
    1.28          }
    1.29  
    1.30          val commitLogContent = when (val result = invokeCommand(
    1.31 -            tmpDir, "incoming", pathOrUrl, "-n", "--template", "::lpitref::{node}:{desc}\\n"
    1.32 +            "incoming", pathOrUrl, "-n", "--template", "::lpitref::{node}:{desc}\\n",
    1.33 +            workingDir = tmpDir,
    1.34 +            timeout = 60
    1.35          )) {
    1.36              is VcsConnectorResult.Error -> return result
    1.37              is VcsConnectorResult.Success -> result.content
     2.1 --- a/src/main/kotlin/de/uapcore/lightpit/vcs/VcsConnector.kt	Tue Jul 18 18:05:49 2023 +0200
     2.2 +++ b/src/main/kotlin/de/uapcore/lightpit/vcs/VcsConnector.kt	Sat Jul 22 11:32:27 2023 +0200
     2.3 @@ -7,13 +7,17 @@
     2.4      /**
     2.5       * Invokes the VCS binary with the given [args] and returns the output on stdout.
     2.6       */
     2.7 -    protected fun invokeCommand(workingDir: Path, vararg args : String): VcsConnectorResult<String> {
     2.8 +    protected fun invokeCommand(
     2.9 +        vararg args: String,
    2.10 +        workingDir: Path = Path.of("."),
    2.11 +        timeout: Long = 30L
    2.12 +    ): VcsConnectorResult<String> {
    2.13          return try {
    2.14              val command = mutableListOf(path)
    2.15              command.addAll(args)
    2.16              val process = ProcessBuilder(command).directory(workingDir.toFile()).start()
    2.17              val stdout = String(process.inputStream.readAllBytes(), Charsets.UTF_8)
    2.18 -            if (process.waitFor(30, TimeUnit.SECONDS)) {
    2.19 +            if (process.waitFor(timeout, TimeUnit.SECONDS)) {
    2.20                  if (process.exitValue() == 0) {
    2.21                      VcsConnectorResult.Success(stdout)
    2.22                  } else {

mercurial