# HG changeset patch # User Mike Becker # Date 1690018347 -7200 # Node ID c15b9555ecf3d96503c3bdb4b6c13f32fed5482d # Parent 12b898531d1a8272ee7924e93a82a4e5fce5db6d make vcs command timeout configurable relates to #274 diff -r 12b898531d1a -r c15b9555ecf3 src/main/kotlin/de/uapcore/lightpit/vcs/HgConnector.kt --- a/src/main/kotlin/de/uapcore/lightpit/vcs/HgConnector.kt Tue Jul 18 18:05:49 2023 +0200 +++ b/src/main/kotlin/de/uapcore/lightpit/vcs/HgConnector.kt Sat Jul 22 11:32:27 2023 +0200 @@ -27,7 +27,6 @@ package de.uapcore.lightpit.vcs import java.nio.file.Files -import java.nio.file.Path import kotlin.io.path.ExperimentalPathApi import kotlin.io.path.deleteRecursively @@ -42,7 +41,7 @@ * Checks, if the specified binary is available and executable. */ fun checkAvailability(): Boolean { - return when (val versionInfo = invokeCommand(Path.of("."), "--version")) { + return when (val versionInfo = invokeCommand("--version")) { is VcsConnectorResult.Success -> versionInfo.content.contains("Mercurial") else -> false } @@ -61,13 +60,15 @@ } catch (e: Throwable) { return VcsConnectorResult.Error("Creating temporary directory for VCS connection failed: " + e.message) } - val init = invokeCommand(tmpDir, "init") + val init = invokeCommand("init", workingDir = tmpDir) if (init is VcsConnectorResult.Error) { return init } val commitLogContent = when (val result = invokeCommand( - tmpDir, "incoming", pathOrUrl, "-n", "--template", "::lpitref::{node}:{desc}\\n" + "incoming", pathOrUrl, "-n", "--template", "::lpitref::{node}:{desc}\\n", + workingDir = tmpDir, + timeout = 60 )) { is VcsConnectorResult.Error -> return result is VcsConnectorResult.Success -> result.content diff -r 12b898531d1a -r c15b9555ecf3 src/main/kotlin/de/uapcore/lightpit/vcs/VcsConnector.kt --- a/src/main/kotlin/de/uapcore/lightpit/vcs/VcsConnector.kt Tue Jul 18 18:05:49 2023 +0200 +++ b/src/main/kotlin/de/uapcore/lightpit/vcs/VcsConnector.kt Sat Jul 22 11:32:27 2023 +0200 @@ -7,13 +7,17 @@ /** * Invokes the VCS binary with the given [args] and returns the output on stdout. */ - protected fun invokeCommand(workingDir: Path, vararg args : String): VcsConnectorResult { + protected fun invokeCommand( + vararg args: String, + workingDir: Path = Path.of("."), + timeout: Long = 30L + ): VcsConnectorResult { return try { val command = mutableListOf(path) command.addAll(args) val process = ProcessBuilder(command).directory(workingDir.toFile()).start() val stdout = String(process.inputStream.readAllBytes(), Charsets.UTF_8) - if (process.waitFor(30, TimeUnit.SECONDS)) { + if (process.waitFor(timeout, TimeUnit.SECONDS)) { if (process.exitValue() == 0) { VcsConnectorResult.Success(stdout) } else {