From 2e2b950964447bf1e1702b4cb1dfcdb0ec7c1c8e Mon Sep 17 00:00:00 2001 From: maxjivi05 Date: Mon, 26 Oct 2026 12:04:20 -0400 Subject: [PATCH] fix: Flatpak setup clears a package lock left by an interrupted run --- .../usr/local/bin/droiddeck-flatpak-setup | 3 ++ tools/tests/test_flatpak_setup.py | 28 ++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-flatpak-setup b/tools/linuxfs/overlay/usr/local/bin/droiddeck-flatpak-setup index bd25b6089..9717da5ba 100644 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-flatpak-setup +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-flatpak-setup @@ -49,6 +49,9 @@ if [ ! -f /etc/pacman.d/gnupg/pubring.gpg ] && [ ! -f /etc/pacman.d/gnupg/pubrin fi step "Reading the package lists" +if [ -e "$WORK/db/db.lck" ] && ! grep -qx pacman /proc/[0-9]*/comm 2>/dev/null; then + rm -f "$WORK/db/db.lck" +fi sync_log=$(pacman --config "$CONF" --dbpath "$WORK/db" --noconfirm -Sy 2>&1) \ || sync_log=$(pacman --config "$CONF" --dbpath "$WORK/db" --noconfirm -Sy 2>&1) if [ ! -f "$WORK/db/sync/extra.db" ]; then diff --git a/tools/tests/test_flatpak_setup.py b/tools/tests/test_flatpak_setup.py index b5714b9a4..5ad712efe 100644 --- a/tools/tests/test_flatpak_setup.py +++ b/tools/tests/test_flatpak_setup.py @@ -9,9 +9,12 @@ SCRIPT = Path(__file__).resolve().parents[1] / "linuxfs/overlay/usr/local/bin/dr class FlatpakSetupTest(unittest.TestCase): - def run_setup(self, uid, pacman): + def run_setup(self, uid, pacman, locked=False): with tempfile.TemporaryDirectory() as directory: root = Path(directory) + if locked: + (root / "work/db").mkdir(parents=True) + (root / "work/db/db.lck").write_text("") bin_dir = root / "bin" bin_dir.mkdir() stubs = {"id": "echo %d" % uid, "curl": "exit 7", "pacman": pacman, "pacman-key": "exit 0"} @@ -40,6 +43,29 @@ class FlatpakSetupTest(unittest.TestCase): self.assertIn("== FAIL could not reach the Arch Linux ARM mirrors (error: failed retrieving file 'core.db' : " "Could not resolve host)", out) + SYNC = ("db=; while [ $# -gt 0 ]; do [ \"$1\" = --dbpath ] && db=$2; shift; done\n" + "[ -e \"$db/db.lck\" ] && { echo 'error: failed to synchronize all databases (unable to lock database)' >&2; exit 1; }\n" + "mkdir -p \"$db/sync\" && touch \"$db/sync/extra.db\"") + + def test_a_lock_left_by_an_interrupted_run_is_cleared(self): + code, out = self.run_setup(0, self.SYNC, locked=True) + self.assertNotIn("unable to lock database", out) + self.assertIn("== STEP Downloading Flatpak", out) + + def test_a_lock_held_by_a_running_pacman_is_kept(self): + with tempfile.TemporaryDirectory() as directory: + holder = Path(directory) / "pacman" + holder.write_bytes(Path("/bin/sleep").read_bytes()) + holder.chmod(0o755) + running = subprocess.Popen([str(holder), "30"]) + try: + code, out = self.run_setup(0, self.SYNC, locked=True) + finally: + running.kill() + running.wait() + self.assertEqual(code, 1) + self.assertIn("unable to lock database", out) + if __name__ == "__main__": unittest.main()