Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions garden-common/src/main/assets/linux/flatpak
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -35,4 +61,14 @@ if [ -n "${flatpak_first_use-}" ]; then
echo "Flathub added: flatpak install flathub <app>" >&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 "$@"
8 changes: 8 additions & 0 deletions garden-common/src/main/assets/linux/thothterm-garden.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -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"));
}
}
4 changes: 2 additions & 2 deletions garden-common/thothdock/thothdock.properties
Original file line number Diff line number Diff line change
@@ -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

Expand Down
5 changes: 3 additions & 2 deletions garden-debian/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
Loading