From afbf398093372d31ab4aaee2ce5ae4c9d3b63689 Mon Sep 17 00:00:00 2001 From: Lord Egypt Date: Mon, 2 Nov 2026 16:05:21 +0300 Subject: [PATCH] ThothTerm 0.5.5: Flatpak fixes (dbus proxy, /dev binds, resumed installs), engine 0.4.1 Co-Authored-By: Claude Sonnet 5.5 --- garden-common/src/main/assets/linux/flatpak | 36 ++++++++ .../src/main/assets/linux/thothterm-garden.sh | 8 ++ .../com/thothterm/linux/FlatpakRetryTest.java | 85 +++++++++++++++++++ garden-common/thothdock/thothdock.properties | 4 +- garden-debian/build.gradle | 5 +- .../metadata/android/en-US/changelogs/505.txt | 1 + .../com/thothterm/debian/ProductNameTest.java | 2 +- third_party/thothdock | 2 +- 8 files changed, 137 insertions(+), 6 deletions(-) create mode 100644 garden-common/src/test/java/com/thothterm/linux/FlatpakRetryTest.java create mode 100644 garden-debian/fastlane/metadata/android/en-US/changelogs/505.txt diff --git a/garden-common/src/main/assets/linux/flatpak b/garden-common/src/main/assets/linux/flatpak index 725edcf..03d91f6 100644 --- a/garden-common/src/main/assets/linux/flatpak +++ b/garden-common/src/main/assets/linux/flatpak @@ -9,6 +9,32 @@ # not connect: No such file or directory"). Start one when none answers. # * On first use it installs flatpak and dbus (only Recommended by flatpak, # but needed for that bus) and adds the Flathub remote. +# * A large install or update ends on "The connection is closed" now and then +# (LibreOffice, after 2.6 GB). OSTree keeps what it fetched, so the command +# is run again, up to five times, and goes on where it stopped. +# retry-begin +# flatpak_retry REAL ARGS...: run REAL; when it ends on a network error, run it +# again (five runs at most). stderr is shown when a run ends: the progress bar +# and the questions are stdout's. +flatpak_retry() { + real=$1; shift + n=1 + while :; do + err=$(mktemp "${TMPDIR:-/tmp}/flatpak-err.XXXXXX") || { "$real" "$@"; return $?; } + "$real" "$@" 2>"$err" + rc=$? + cat "$err" >&2 + if [ "$rc" -eq 0 ] || [ "$n" -ge 5 ] || ! grep -qiE 'connection is closed|could not resolve|name or service not known|connection reset|connection refused|timed out|timeout|could not connect|unable to connect|temporary failure|network is unreachable|broken pipe|premature eof|http/2|bad gateway|service unavailable|gateway time-out|tls |ssl ' "$err"; then + rm -f "$err" + return "$rc" + fi + rm -f "$err" + n=$((n + 1)) + echo "flatpak (ThothTerm): network error; continuing (run $n of 5)" >&2 + sleep "${FLATPAK_RETRY_DELAY:-3}" + done +} +# retry-end BWRAP=/usr/libexec/thothdock/bwrap if [ -z "${FLATPAK_BWRAP-}" ] && [ -x "$BWRAP" ]; then FLATPAK_BWRAP="$BWRAP" @@ -35,4 +61,14 @@ if [ -n "${flatpak_first_use-}" ]; then echo "Flathub added: flatpak install flathub " >&2 || echo "Flathub was not added: flatpak remote-add --user flathub https://dl.flathub.org/repo/flathub.flatpakrepo" >&2 fi +# The first word that is not an option is the subcommand. +for flatpak_word in "$@"; do + case $flatpak_word in -*) continue ;; esac + break +done +case ${flatpak_word-} in + install|update) + flatpak_retry /usr/bin/flatpak "$@" + exit $? ;; +esac exec /usr/bin/flatpak "$@" diff --git a/garden-common/src/main/assets/linux/thothterm-garden.sh b/garden-common/src/main/assets/linux/thothterm-garden.sh index 2d3cd1d..3480784 100644 --- a/garden-common/src/main/assets/linux/thothterm-garden.sh +++ b/garden-common/src/main/assets/linux/thothterm-garden.sh @@ -76,3 +76,11 @@ if [ -z "${THOTHTERM_SNAPS_STARTED-}" ] && [ -x /usr/local/bin/snap ] \ export THOTHTERM_SNAPS_STARTED=1 ( /usr/local/bin/snap autostart >/dev/null 2>&1 & ) fi + +# Flatpak lists its exports in XDG_DATA_DIRS (Debian does it from a login +# shell's profile.d); without them every install prints "directories currently +# searched are ..." and desktop files of installed apps are not found. +if [ -d "$HOME/.local/share/flatpak/exports/share" ] || [ -d /var/lib/flatpak/exports/share ]; then + XDG_DATA_DIRS="$HOME/.local/share/flatpak/exports/share:/var/lib/flatpak/exports/share:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}" + export XDG_DATA_DIRS +fi diff --git a/garden-common/src/test/java/com/thothterm/linux/FlatpakRetryTest.java b/garden-common/src/test/java/com/thothterm/linux/FlatpakRetryTest.java new file mode 100644 index 0000000..7f4c459 --- /dev/null +++ b/garden-common/src/test/java/com/thothterm/linux/FlatpakRetryTest.java @@ -0,0 +1,85 @@ +package com.thothterm.linux; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.util.concurrent.TimeUnit; + +import org.junit.Test; + +/** + * The flatpak wrapper runs an install again when it ends on a network error: + * a 2.6 GB LibreOffice install ended on "The connection is closed" and OSTree + * would have gone on where it stopped. The retry function is run here against + * a fake flatpak. + */ +public class FlatpakRetryTest { + private static String retryFunction() throws Exception { + File here = new File("").getAbsoluteFile(); + File repo = new File(here, "third_party").isDirectory() ? here : here.getParentFile(); + String script = new String(Files.readAllBytes( + new File(repo, "garden-common/src/main/assets/linux/flatpak").toPath()), StandardCharsets.UTF_8); + int begin = script.indexOf("# retry-begin"); + int end = script.indexOf("# retry-end"); + assertTrue("markers missing", begin >= 0 && end > begin); + return script.substring(begin, end); + } + + /** Runs flatpak_retry against a fake that fails with {@code message} the first {@code failures} times. */ + private static String[] run(int failures, String message) throws Exception { + File dir = Files.createTempDirectory("flatpak-retry").toFile(); + File fake = new File(dir, "fake-flatpak"); + File count = new File(dir, "count"); + Files.write(fake.toPath(), ("#!/bin/sh\n" + + "n=$(cat '" + count + "' 2>/dev/null || echo 0); n=$((n + 1)); echo $n > '" + count + "'\n" + + "echo \"progress $*\"\n" + + "if [ $n -le " + failures + " ]; then echo '" + message + "' >&2; exit 1; fi\n" + + "exit 0\n").getBytes(StandardCharsets.UTF_8)); + fake.setExecutable(true); + ProcessBuilder pb = new ProcessBuilder("sh", "-c", retryFunction() + + "\nflatpak_retry '" + fake + "' install --user flathub org.example.App\necho \"rc=$?\""); + pb.environment().put("FLATPAK_RETRY_DELAY", "0"); + pb.environment().put("TMPDIR", dir.getPath()); + pb.redirectErrorStream(false); + Process p = pb.start(); + byte[] out = p.getInputStream().readAllBytes(); + byte[] err = p.getErrorStream().readAllBytes(); + assertTrue(p.waitFor(30, TimeUnit.SECONDS)); + String runs = new String(Files.readAllBytes(count.toPath()), StandardCharsets.UTF_8).trim(); + return new String[]{new String(out, StandardCharsets.UTF_8), new String(err, StandardCharsets.UTF_8), runs}; + } + + @Test + public void aDroppedConnectionIsRunAgainUntilItWorks() throws Exception { + String[] r = run(2, "Error: Failed to install org.example.App: The connection is closed"); + assertEquals("3", r[2]); + assertTrue(r[0], r[0].endsWith("rc=0\n")); + assertTrue(r[1], r[1].contains("run 3 of 5")); + assertTrue("stdout is passed through each time", r[0].split("progress install --user flathub org.example.App").length == 4); + } + + @Test + public void anErrorThatIsNotTheNetworkIsNotRetried() throws Exception { + String[] r = run(9, "error: Nothing matches org.example.App in remote flathub"); + assertEquals("1", r[2]); + assertTrue(r[0], r[0].endsWith("rc=1\n")); + assertTrue(r[1], r[1].contains("Nothing matches")); + } + + @Test + public void aNetworkThatStaysDownStopsAfterFiveRuns() throws Exception { + String[] r = run(99, "Error: Failed to install org.example.App: Timeout was reached"); + assertEquals("5", r[2]); + assertTrue(r[0], r[0].endsWith("rc=1\n")); + } + + @Test + public void aFailedNameLookupIsRunAgain() throws Exception { + String[] r = run(1, "error: Unable to load summary from remote flathub: Could not resolve hostname"); + assertEquals("2", r[2]); + assertTrue(r[0], r[0].endsWith("rc=0\n")); + } +} diff --git a/garden-common/thothdock/thothdock.properties b/garden-common/thothdock/thothdock.properties index def4612..7b50e6f 100644 --- a/garden-common/thothdock/thothdock.properties +++ b/garden-common/thothdock/thothdock.properties @@ -1,9 +1,9 @@ # ThothDock pins (see tools/stage-thothdock.sh). Both programs are built from # source at exactly these commits; nothing is downloaded during the build. -# github.com/Lord1Egypt/ThothDock v0.4.0 (submodule third_party/thothdock), Apache-2.0. +# github.com/Lord1Egypt/ThothDock v0.4.1 (submodule third_party/thothdock), Apache-2.0. # The daemon's only dependency, golang.org/x/sys, is vendored in that tree. -thothdockCommit=08b0e69 +thothdockCommit=9e9fcd7 # Lowest Go toolchain accepted (GOTOOLCHAIN=local: Go never fetches another). goMinVersion=1.26.0 diff --git a/garden-debian/build.gradle b/garden-debian/build.gradle index 1d5093d..eb5729d 100644 --- a/garden-debian/build.gradle +++ b/garden-debian/build.gradle @@ -25,6 +25,7 @@ android { vectorDrawables.useSupportLibrary = true + // 0.5.5: ThothDock engine 0.4.1 (Flatpak: xdg-dbus-proxy for KeePassXC and Firefox, /dev binds for GL apps; installs resume after a dropped connection). // 0.5.4: ThothDock engine 0.4.0 (snapctl and snap services, one address per snap, hard-link repair; snap run --shell, snap autostart, refresh). // 0.5.3: ThothDock engine 0.3.1 (snap downloads resume, store aliases, squashfs-tools and flatpak set up on first use, snapd guarded); volume keys are no longer Ctrl/Fn by default. // 0.5.2: swipes reach full-screen TUIs as mouse wheel events (OpenCode), SGR mouse reports. @@ -33,8 +34,8 @@ android { // 0.4.2: store listing only (ThothDock icon, current screenshots, store text); same code and engine as 0.4.1. // 0.4.1: ThothDock engine 0.2.1 (System V IPC, hostname, long Unix sockets; PRoot patches 0010-0018). (0.4.0 was 400.) // 0.4.0: ThothTerm (bullet) ThothDock (package com.thothterm.debian), ThothDock engine 0.2.0 (NextGen). (0.3.1 was 301.) - versionCode 504 - versionName '0.5.4' + versionCode 505 + versionName '0.5.5' // Device tests (the pinch gesture and garden-common's shared tests); // run with `am instrument` against the installed app, never diff --git a/garden-debian/fastlane/metadata/android/en-US/changelogs/505.txt b/garden-debian/fastlane/metadata/android/en-US/changelogs/505.txt new file mode 100644 index 0000000..6861d5c --- /dev/null +++ b/garden-debian/fastlane/metadata/android/en-US/changelogs/505.txt @@ -0,0 +1 @@ +flatpak: KeePassXC, Firefox and other apps with D-Bus permissions start (xdg-dbus-proxy), GL apps no longer fail on /dev/dri, and an install that loses its connection (LibreOffice, Krita) resumes by itself; Flatpak export paths are set. Tested with 14 apps. Engine 0.4.1. \ No newline at end of file diff --git a/garden-debian/src/test/java/com/thothterm/debian/ProductNameTest.java b/garden-debian/src/test/java/com/thothterm/debian/ProductNameTest.java index d6ec5e4..e5a69d6 100644 --- a/garden-debian/src/test/java/com/thothterm/debian/ProductNameTest.java +++ b/garden-debian/src/test/java/com/thothterm/debian/ProductNameTest.java @@ -94,7 +94,7 @@ public void storeTextFitsFdroidLimits() throws Exception { assertTrue(read(dir + "title.txt").trim().length() <= 50); assertTrue(read(dir + "short_description.txt").trim().length() <= 80); assertTrue(read(dir + "full_description.txt").length() <= 4000); - for (String code : new String[]{"301", "400", "401", "402", "500", "501", "502", "503", "504"}) { + for (String code : new String[]{"301", "400", "401", "402", "500", "501", "502", "503", "504", "505"}) { assertTrue(code, read(dir + "changelogs/" + code + ".txt").length() <= 500); } } diff --git a/third_party/thothdock b/third_party/thothdock index 08b0e69..9e9fcd7 160000 --- a/third_party/thothdock +++ b/third_party/thothdock @@ -1 +1 @@ -Subproject commit 08b0e69b75b3acde0aeeb46d9d2922077cc4e244 +Subproject commit 9e9fcd72074dc2c2661b0276e7aad86525fed20e