fix(gog): keep innoextract output in the log and leave the install failure message unchanged

This commit is contained in:
Kurt Himebauch committed 2026-11-11 20:23:02 +00:00
1 parent 6c26aaaa8e
commit e98b076734
4 files changed
+8 -76

No files matched your search

@@ -323,15 +323,15 @@ public final class GogDownloadManager {
}
String guestSetup = guestDir + "/" + setupName;
cb.onProgress("Extracting installer…", 95);
GogInnoextract.Result result;
int rc;
try {
result = GogInnoextract.extract(ctx, guestSetup, guestDir, "gog-innoextract", cancelled,
rc = GogInnoextract.extract(ctx, guestSetup, guestDir, "gog-innoextract", cancelled,
line -> { cb.onLog("gog innoextract: " + line); return kotlin.Unit.INSTANCE; });
} catch (Exception e) {
throw new InstallException("The installer could not be extracted: " + e.getClass().getSimpleName());
}
if (cancelled.get()) return;
if (result.getExit() != 0) throw new InstallException(result.failure("The installer could not be extracted (innoextract exit " + result.getExit() + ")"));
if (rc != 0) throw new InstallException("The installer could not be extracted (innoextract exit " + rc + ")");
}
static long installerBytesNeeded(long downloadBytes, long installedBytes) {
@@ -7,38 +7,11 @@ import java.util.concurrent.atomic.AtomicBoolean
internal object GogInnoextract {
private const val PROGRAM = "/usr/local/bin/droiddeck-innoextract"
private const val REASON_LINES = 3
private const val REASON_CHARS = 400
private val TREE = Regex("""^[\s├└│─]+""")
private val BOILERPLATE = Regex(
"""^(\S+ )?warning:|^If you are sure the setup file is not corrupted|^filing a bug report at |^Done with \d+ (errors?|warnings?)""",
RegexOption.IGNORE_CASE,
)
class Result(val exit: Int, val reason: String) {
fun failure(message: String): String = if (reason.isEmpty()) message else "$message: $reason"
}
@JvmStatic
fun extract(context: Context, setup: String, target: String, logName: String, cancelled: AtomicBoolean, onLine: (String) -> Unit): Result {
val details = ArrayDeque<String>()
val exit = GuestCommand.run(context, argv(setup, target), logName = logName,
extraBinds = StoreInstallRoot.guestBinds(context), cancelled = cancelled) { line ->
onLine(line)
val kept = detail(line)
if (kept != null) {
details.addLast(kept)
if (details.size > REASON_LINES) details.removeFirst()
}
}
return Result(exit, if (exit == 0) "" else reason(details))
}
fun extract(context: Context, setup: String, target: String, logName: String, cancelled: AtomicBoolean, onLine: (String) -> Unit): Int =
GuestCommand.run(context, argv(setup, target), logName = logName,
extraBinds = StoreInstallRoot.guestBinds(context), cancelled = cancelled, onLine = onLine)
internal fun argv(setup: String, target: String): List<String> = listOf(PROGRAM, "--gog", "--silent", "-d", target, setup)
internal fun reason(lines: Iterable<String>): String =
lines.mapNotNull(::detail).takeLast(REASON_LINES).joinToString(" ").take(REASON_CHARS)
private fun detail(raw: String): String? =
raw.replace(TREE, "").trim().takeUnless { it.isEmpty() || BOILERPLATE.containsMatchIn(it) }
}
@@ -69,9 +69,9 @@ internal object GogOffline {
val source = AddedGames.guestPath(context, installer) ?: error("The GOG installer is not visible to Linux")
val target = AddedGames.guestPath(context, extracted) ?: error("The GOG staging folder is not visible to Linux")
handle.stage(DownloadStage.INSTALL, "Extracting the full offline installer")
val result = GogInnoextract.extract(context, source, target, "gog-refresh", stop, handle::log)
val rc = GogInnoextract.extract(context, source, target, "gog-refresh", stop, handle::log)
if (stop.get()) return
check(result.exit == 0) { result.failure("GOG installer extraction failed (exit ${result.exit})") }
check(rc == 0) { "GOG installer extraction failed (exit $rc)" }
applyRefresh(proposal, extracted, handle, stop)
}
@@ -90,45 +90,4 @@ class GogInnoextractTest {
assertTrue(internalGuest.startsWith(StoreInstallRoot.INTERNAL_GUEST + "/GOG/"))
assertNull(hostOf("$internalGuest/setup_1207658935.exe", StoreInstallRoot.guestBinds(app)))
}
@Test fun aFailedExtractionReportsTheExtractorsOwnError() {
val result = GogInnoextract.Result(2, GogInnoextract.reason(listOf(
"Warning: Unexpected setup data version: Inno Setup Setup Data (6.4.0)",
"Stream error while parsing setup headers!",
" ├─ detected setup version: 6.4.0",
" └─ error reason: iostream error",
"",
)))
assertEquals(
"The installer could not be extracted (innoextract exit 2): Stream error while parsing setup headers! detected setup version: 6.4.0 error reason: iostream error",
result.failure("The installer could not be extracted (innoextract exit 2)"),
)
}
@Test fun aStreamErrorDuringExtractionReportsItsReasonWithoutTheExtractorsBoilerplate() {
val result = GogInnoextract.Result(2, GogInnoextract.reason(listOf(
"proot warning: can't sanitize binding \"/proc/self/fd/0\": No such file or directory",
"proot warning: can't sanitize binding \"/proc/self/fd/1\": No such file or directory",
"Stream error while extracting files!",
" └─ error reason: zlib error: iostream error",
"If you are sure the setup file is not corrupted, consider ",
"filing a bug report at https://innoextract.constexpr.org/issues",
"Done with 1 error.",
)))
assertEquals(
"The installer could not be extracted (innoextract exit 2): Stream error while extracting files! error reason: zlib error: iostream error",
result.failure("The installer could not be extracted (innoextract exit 2)"),
)
}
@Test fun theReasonKeepsTheLastErrorLinesAndStaysShort() {
val lines = (1..10).map { "Could not open file \"/mnt/droiddeck-stores/card/setup_$it.exe\"" }
assertEquals(lines.takeLast(3).joinToString(" "), GogInnoextract.reason(lines))
assertEquals(400, GogInnoextract.reason(listOf("x".repeat(1000))).length)
}
@Test fun anExtractionWithoutOutputKeepsTheExitMessage() {
val result = GogInnoextract.Result(2, GogInnoextract.reason(listOf("", "Warning: Unexpected setup data version")))
assertEquals("GOG installer extraction failed (exit 2)", result.failure("GOG installer extraction failed (exit 2)"))
}
}