fix: Flatpak setup clears a package lock left by an interrupted run

This commit is contained in:
maxjivi05 authored and MaxsTechReview committed 2026-10-26 12:47:00 -04:00
1 parent da127d1b4c
commit 2e2b950964
2 files changed
+30 -1

No files matched your search

@@ -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
+27 -1
View File
@@ -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()