From 9cf0a7e43f515e72da6f080fd87a354bf33e98c7 Mon Sep 17 00:00:00 2001 From: The412Banner <205237651+The412Banner@users.noreply.github.com> Date: Wed, 25 Nov 2026 21:08:10 +0000 Subject: [PATCH] fix(flatpak): Electron apps find zypak-wrapper when it is a link that leaves the app's mount --- .../launcher/runtime/BwrapSpawner.kt | 4 ++-- .../launcher/runtime/BwrapSpawnerTest.kt | 20 ++++++++++++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/droiddeck/launcher/runtime/BwrapSpawner.kt b/app/src/main/java/com/droiddeck/launcher/runtime/BwrapSpawner.kt index 0e42e770e3..690da143e6 100644 --- a/app/src/main/java/com/droiddeck/launcher/runtime/BwrapSpawner.kt +++ b/app/src/main/java/com/droiddeck/launcher/runtime/BwrapSpawner.kt @@ -329,8 +329,8 @@ object BwrapSpawner { private fun zypakShims(binds: List, root: File, dir: File): List { val wrappers = listOf("/app/bin/zypak-wrapper.sh", "/app/bin/zypak-wrapper").filter { guest -> - val host = File(hostPath(binds, root.path, guest)) - host.isFile && !Files.isSymbolicLink(host.toPath()) + val host = File(hostPath(binds, root.path, guest)).toPath() + Files.isRegularFile(host, java.nio.file.LinkOption.NOFOLLOW_LINKS) || Files.isSymbolicLink(host) } if (wrappers.isEmpty()) return emptyList() val shim = File(dir, "zypak-wrapper") diff --git a/app/src/test/java/com/droiddeck/launcher/runtime/BwrapSpawnerTest.kt b/app/src/test/java/com/droiddeck/launcher/runtime/BwrapSpawnerTest.kt index 5b5cef26b4..12641543ff 100644 --- a/app/src/test/java/com/droiddeck/launcher/runtime/BwrapSpawnerTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/runtime/BwrapSpawnerTest.kt @@ -263,8 +263,26 @@ class BwrapSpawnerPlanTest { val shim = plan.binds.single { it.guest == "/app/bin/zypak-wrapper.sh" } assertTrue(shim.host.startsWith(dir.path)) assertTrue(File(shim.host).readText().contains("exec \"\$program\" --no-sandbox \"\$@\"")) - assertFalse(plan.binds.any { it.guest == "/app/bin/zypak-wrapper" }) + assertEquals(shim.host, plan.binds.single { it.guest == "/app/bin/zypak-wrapper" }.host) assertTrue(File(app, "bin/zypak-wrapper.sh").readText().contains("zypak-helper")) + assertEquals("/app/bin/zypak-wrapper.sh", Files.readSymbolicLink(File(app, "bin/zypak-wrapper").toPath()).toString()) + } + + @Test fun zypakWrapperLinkThatDoesNotResolveOnTheHostGetsTheShim() { + val context = RuntimeEnvironment.getApplication() + val app = File(runtime, "app").apply { File(this, "bin").mkdirs() } + File(app, "bin/zypak-wrapper.sh").writeText("#!/usr/bin/bash\nexec zypak-helper host - \"\$@\"\n") + val dangling = java.nio.file.Paths.get(LinuxRuntime.rootDir(context).path, "app/bin/zypak-wrapper.sh") + Files.createSymbolicLink(File(app, "bin/zypak-wrapper").toPath(), dangling) + val plan = BwrapSpawner.plan(context, request( + op("t" to "bind", "src" to "/runtime-files/app", "dest" to "/app", "ro" to true), + ), dir) + + assertFalse(Files.exists(dangling)) + val shim = plan.binds.single { it.guest == "/app/bin/zypak-wrapper" } + assertTrue(shim.host.startsWith(dir.path)) + assertTrue(File(shim.host).readText().contains("exec \"\$program\" --no-sandbox \"\$@\"")) + assertEquals(shim.host, plan.binds.single { it.guest == "/app/bin/zypak-wrapper.sh" }.host) } @Test fun appsWithoutZypakKeepTheirFiles() {