fix: x86 Flatpak bundles are refused with a clear message instead of installing and failing to start (#1873)

This commit is contained in:
MaxsTechReview authored and GitHub committed 2026-10-30 19:03:27 -04:00
1 parent 8cf01ebb77
commit 6673a892e2
36 files changed
+133 -2

No files matched your search

@@ -141,10 +141,15 @@ def install_bundle(path):
inst = installation()
bundle = Gio.File.new_for_path(path)
try:
app_id = Flatpak.BundleRef.new(bundle).get_name()
ref = Flatpak.BundleRef.new(bundle)
app_id = ref.get_name()
except GLib.Error as err:
emit(e="error", message="%s is not a Flatpak bundle (%s)" % (os.path.basename(path), err.message))
return 1
if ref.get_arch() != Flatpak.get_default_arch():
emit(e="error", code="arch", id=app_id, arch=ref.get_arch(),
message="%s is built for %s, not %s" % (app_id, ref.get_arch(), Flatpak.get_default_arch()))
return 1
if app_ref(inst, app_id) is not None:
emit(e="done", id=app_id, note="already installed")
return 0
+89
View File
@@ -0,0 +1,89 @@
import importlib.machinery
import importlib.util
import io
import json
from pathlib import Path
import sys
import types
import unittest
from contextlib import redirect_stdout
SCRIPT = Path(__file__).resolve().parents[1] / "linuxfs/overlay/usr/local/bin/droiddeck-flatpak"
class FakeRef:
def __init__(self, arch):
self.arch = arch
def get_name(self):
return "io.github.ebkr.r2modman"
def get_arch(self):
return self.arch
def load(bundle_arch, installs):
flatpak = types.SimpleNamespace(
get_default_arch=lambda: "aarch64",
BundleRef=types.SimpleNamespace(new=lambda bundle: FakeRef(bundle_arch)),
)
repository = types.ModuleType("gi.repository")
repository.Flatpak = flatpak
repository.Gio = types.SimpleNamespace(File=types.SimpleNamespace(new_for_path=lambda path: path))
repository.GLib = types.SimpleNamespace(Error=RuntimeError)
gi = types.ModuleType("gi")
gi.require_version = lambda *args: None
gi.repository = repository
saved = {name: sys.modules.get(name) for name in ("gi", "gi.repository")}
sys.modules["gi"] = gi
sys.modules["gi.repository"] = repository
try:
loader = importlib.machinery.SourceFileLoader("droiddeck_flatpak", str(SCRIPT))
module = importlib.util.module_from_spec(importlib.util.spec_from_loader(loader.name, loader))
loader.exec_module(module)
finally:
for name, value in saved.items():
if value is None:
sys.modules.pop(name, None)
else:
sys.modules[name] = value
module.installation = lambda: object()
module.app_ref = lambda inst, app_id: None
def transaction(inst):
installs.append("bundle")
raise AssertionError("the bundle reached a transaction")
module.transaction = transaction
return module
class FlatpakBundleArchTest(unittest.TestCase):
def run_install(self, arch):
installs = []
module = load(arch, installs)
out = io.StringIO()
with redirect_stdout(out):
try:
rc = module.install_bundle("/tmp/r2modman.flatpak")
except AssertionError:
rc = None
return rc, [json.loads(line) for line in out.getvalue().splitlines()], installs
def test_a_bundle_for_another_architecture_is_refused_before_installing(self):
rc, events, installs = self.run_install("x86_64")
self.assertEqual(rc, 1)
self.assertEqual(installs, [])
self.assertEqual(events[0]["e"], "error")
self.assertEqual(events[0]["code"], "arch")
self.assertEqual(events[0]["arch"], "x86_64")
self.assertEqual(events[0]["id"], "io.github.ebkr.r2modman")
def test_a_bundle_for_this_device_goes_on_to_install(self):
rc, events, installs = self.run_install("aarch64")
self.assertEqual(installs, ["bundle"])
self.assertEqual(events, [])
if __name__ == "__main__":
unittest.main()