From 144f49a26473c334db90495108a4592654c665ae Mon Sep 17 00:00:00 2001 From: Derpedyea Date: Wed, 21 Oct 2026 21:17:05 -0400 Subject: [PATCH 1/2] fix(desktop): a failed AppImage update no longer deletes the installed app electron-updater's AppImage install unlinked the running AppImage, then moved the new one in with a PATH-resolved `mv`. When `mv` failed (ENOTCONN from a dead AppImage mount on PATH), no AppImage was left to launch. Patch electron-updater 6.8.9 to stage the new AppImage beside the target (hard link, or copy across filesystems) and rename it over the old one, so there is no child process and a failure leaves the old file in place. Fixes #23188 Co-Authored-By: Claude Opus 5.5 --- .../src/electron/ElectronUpdater.test.ts | 48 +++++++++++++++++++ patches/electron-updater@6.8.9.patch | 44 +++++++++++++++++ pnpm-lock.yaml | 5 +- pnpm-workspace.yaml | 3 ++ 4 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 apps/desktop/src/electron/ElectronUpdater.test.ts create mode 100644 patches/electron-updater@6.8.9.patch diff --git a/apps/desktop/src/electron/ElectronUpdater.test.ts b/apps/desktop/src/electron/ElectronUpdater.test.ts new file mode 100644 index 0000000000000..d87afd489fc1e --- /dev/null +++ b/apps/desktop/src/electron/ElectronUpdater.test.ts @@ -0,0 +1,48 @@ +// @effect-diagnostics nodeBuiltinImport:off - Exercises the patched AppImage install on a real filesystem. +import * as NodeFS from "node:fs"; +import * as NodeOS from "node:os"; +import * as NodePath from "node:path"; + +import { AppImageUpdater } from "electron-updater"; +import { afterEach, expect, it, vi } from "vite-plus/test"; + +afterEach(() => vi.unstubAllEnvs()); + +const installAppImage = (removeInstaller: boolean) => { + const root = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-appimage-install-")); + const appImage = NodePath.join(root, "T3-Code.AppImage"); + const installerPath = NodePath.join(root, "pending.AppImage"); + NodeFS.writeFileSync(appImage, "old"); + if (!removeInstaller) NodeFS.writeFileSync(installerPath, "new"); + vi.stubEnv("APPIMAGE", appImage); + // An empty dir stands in for a dead AppImage mount: either way `mv` is not found. + vi.stubEnv("PATH", NodePath.join(root, "empty")); + const updater = { installerPath, spawnLog: async () => true, emit: () => true }; + try { + AppImageUpdater.prototype["doInstall"].call(updater as unknown as AppImageUpdater, { + isSilent: true, + isForceRunAfter: true, + isAdminRightsRequired: false, + }); + return NodeFS.readdirSync(root).map((name) => [ + name, + NodeFS.readFileSync(`${root}/${name}`, "utf8"), + ]); + } catch (error) { + return { + error: String(error), + files: NodeFS.readdirSync(root), + appImage: NodeFS.existsSync(appImage) ? NodeFS.readFileSync(appImage, "utf8") : null, + }; + } finally { + NodeFS.rmSync(root, { recursive: true, force: true }); + } +}; + +it("replaces the AppImage without a PATH lookup", () => { + expect(installAppImage(false)).toEqual([["T3-Code.AppImage", "new"]]); +}); + +it("keeps the running AppImage when the swap fails", () => { + expect(installAppImage(true)).toMatchObject({ files: ["T3-Code.AppImage"], appImage: "old" }); +}); diff --git a/patches/electron-updater@6.8.9.patch b/patches/electron-updater@6.8.9.patch new file mode 100644 index 0000000000000..5ba3b00c59789 --- /dev/null +++ b/patches/electron-updater@6.8.9.patch @@ -0,0 +1,44 @@ +diff --git a/out/AppImageUpdater.js b/out/AppImageUpdater.js +index 452e93f819eaeb5e6532a831255adc70d854df4b..a9ae497c1049c2e2f9471583039ade64d54c43f1 100644 +--- a/out/AppImageUpdater.js ++++ b/out/AppImageUpdater.js +@@ -77,8 +77,6 @@ class AppImageUpdater extends BaseUpdater_1.BaseUpdater { + if (!path.isAbsolute(appImageFile) || appImageFile.includes("\0")) { + throw (0, builder_util_runtime_1.newError)(`APPIMAGE env is not a valid absolute path: "${appImageFile}"`, "ERR_UPDATER_OLD_FILE_NOT_FOUND"); + } +- // https://stackoverflow.com/a/1712051/1910191 +- (0, fs_1.unlinkSync)(appImageFile); + let destination; + const existingBaseName = path.basename(appImageFile); + const installerPath = this.installerPath; +@@ -95,8 +93,29 @@ class AppImageUpdater extends BaseUpdater_1.BaseUpdater { + else { + destination = path.join(path.dirname(appImageFile), path.basename(installerPath)); + } +- (0, child_process_1.execFileSync)("mv", ["-f", installerPath, destination]); ++ // T3 Code: swap the AppImage in with one rename instead of unlink + `mv`. The `mv` ++ // PATH lookup fails with ENOTCONN on a dead AppImage mount left on PATH, and the ++ // unlink before it had already removed the only copy of the app. Staging beside the ++ // destination keeps the rename on one filesystem, and the running AppImage stays in ++ // place until the new one is complete. ++ const stagedPath = path.join(path.dirname(destination), `.${path.basename(destination)}.update`); ++ (0, fs_1.rmSync)(stagedPath, { force: true }); ++ try { ++ try { ++ (0, fs_1.linkSync)(installerPath, stagedPath); ++ } ++ catch { ++ (0, fs_1.copyFileSync)(installerPath, stagedPath); ++ } ++ (0, fs_1.renameSync)(stagedPath, destination); ++ } ++ catch (e) { ++ (0, fs_1.rmSync)(stagedPath, { force: true }); ++ throw e; ++ } ++ (0, fs_1.rmSync)(installerPath, { force: true }); + if (destination !== appImageFile) { ++ (0, fs_1.rmSync)(appImageFile, { force: true }); + this.emit("appimage-filename-updated", destination); + } + const env = { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 232a7da308c7e..7b51effae8d49 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -341,6 +341,7 @@ patchedDependencies: alchemy@2.0.0-beta.80: bea1b6c0c0b23157fd5f439a1d7feff430f28ac1621ba135d8a13eeec60ccacd app-builder-lib@26.16.1: a28c2dfcfc2b90d6c6247e199e6537391db9ecd941854c650910d607442512d3 dbus-next@0.10.2: cfff57561b0ee59b5addb3b2e6c6f20906e967507a530ab67e8db8108e520ba4 + electron-updater@6.8.9: 3b5108258e7f60fb24aef159bcfda355ecf8af2bacc746ba1c6fff5116e8d666 expo-audio@58.0.9: 2c2f8c73a23d48804c8b537b8cd73c25eb331aa47d82eaa481c6766cb81e5add expo-modules-core@58.0.22: f0b0fd100550ed76e5c25b4d13eb7c9ff62825f8f197c53edf7bf447c50c9fb7 expo-network@58.0.3: cd09b6d1744dde4efa081b5619ebcff38877d98f7502a51cab121629dece8237 @@ -432,7 +433,7 @@ importers: version: 8.2.0 electron-updater: specifier: ^6.8.9 - version: 6.8.9(supports-color@8.1.1) + version: 6.8.9(patch_hash=3b5108258e7f60fb24aef159bcfda355ecf8af2bacc746ba1c6fff5116e8d666)(supports-color@8.1.1) electron-webauthn: specifier: 'catalog:' version: 1.3.1(typescript@7.0.2) @@ -18410,7 +18411,7 @@ snapshots: electron-to-chromium@1.5.430: {} - electron-updater@6.8.9(supports-color@8.1.1): + electron-updater@6.8.9(patch_hash=3b5108258e7f60fb24aef159bcfda355ecf8af2bacc746ba1c6fff5116e8d666)(supports-color@8.1.1): dependencies: builder-util-runtime: 9.7.0(supports-color@8.1.1) fs-extra: 10.1.0 diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index 24afc13b72281..b36d6764e814d 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -364,6 +364,9 @@ patchedDependencies: # skip, the fingerprint silently drops every Expo native module and OTAs reach stale binaries. "@expo/fingerprint@0.21.5": patches/@expo__fingerprint@0.21.5.patch app-builder-lib@26.16.1: patches/app-builder-lib@26.16.1.patch + # Linux: an AppImage update renames the new file over the old one instead of deleting the + # old one before a PATH-resolved `mv`, so a failed install still leaves an app to launch. + electron-updater@6.8.9: patches/electron-updater@6.8.9.patch peerDependencyRules: allowAny: From 56b13cff750f9ebd01fe86d348455231d6b98408 Mon Sep 17 00:00:00 2001 From: Derpedyea Date: Wed, 21 Oct 2026 21:23:48 -0400 Subject: [PATCH 2/2] refactor(desktop): replace the electron-updater patch with an AppImageUpdater subclass The atomic AppImage install now lives in our code as a typed override of doInstall, so electron-updater stays unpatched and bumps don't touch it. Co-Authored-By: Claude Opus 5.5 --- .../src/electron/ElectronUpdater.test.ts | 7 +- apps/desktop/src/electron/ElectronUpdater.ts | 96 +++++++++++++++---- patches/electron-updater@6.8.9.patch | 44 --------- pnpm-lock.yaml | 5 +- pnpm-workspace.yaml | 3 - 5 files changed, 85 insertions(+), 70 deletions(-) delete mode 100644 patches/electron-updater@6.8.9.patch diff --git a/apps/desktop/src/electron/ElectronUpdater.test.ts b/apps/desktop/src/electron/ElectronUpdater.test.ts index d87afd489fc1e..1b06815188030 100644 --- a/apps/desktop/src/electron/ElectronUpdater.test.ts +++ b/apps/desktop/src/electron/ElectronUpdater.test.ts @@ -1,11 +1,12 @@ -// @effect-diagnostics nodeBuiltinImport:off - Exercises the patched AppImage install on a real filesystem. +// @effect-diagnostics nodeBuiltinImport:off - Exercises the AppImage install on a real filesystem. import * as NodeFS from "node:fs"; import * as NodeOS from "node:os"; import * as NodePath from "node:path"; -import { AppImageUpdater } from "electron-updater"; import { afterEach, expect, it, vi } from "vite-plus/test"; +import { AtomicAppImageUpdater } from "./ElectronUpdater.ts"; + afterEach(() => vi.unstubAllEnvs()); const installAppImage = (removeInstaller: boolean) => { @@ -19,7 +20,7 @@ const installAppImage = (removeInstaller: boolean) => { vi.stubEnv("PATH", NodePath.join(root, "empty")); const updater = { installerPath, spawnLog: async () => true, emit: () => true }; try { - AppImageUpdater.prototype["doInstall"].call(updater as unknown as AppImageUpdater, { + AtomicAppImageUpdater.prototype["doInstall"].call(updater as unknown as AtomicAppImageUpdater, { isSilent: true, isForceRunAfter: true, isAdminRightsRequired: false, diff --git a/apps/desktop/src/electron/ElectronUpdater.ts b/apps/desktop/src/electron/ElectronUpdater.ts index e42ebc1003ab4..e9244a7e34cba 100644 --- a/apps/desktop/src/electron/ElectronUpdater.ts +++ b/apps/desktop/src/electron/ElectronUpdater.ts @@ -1,13 +1,75 @@ +// @effect-diagnostics nodeBuiltinImport:off -- The AppImage install swaps files synchronously inside electron-updater's quitAndInstall. +import * as NodeChildProcess from "node:child_process"; +import * as NodeFS from "node:fs"; +import * as NodePath from "node:path"; + import * as Context from "effect/Context"; import * as Effect from "effect/Effect"; import * as Layer from "effect/Layer"; import * as Schema from "effect/Schema"; import * as Scope from "effect/Scope"; -import { autoUpdater } from "electron-updater"; +import { AppImageUpdater, type AppUpdater, autoUpdater } from "electron-updater"; type AutoUpdater = typeof autoUpdater; +// electron-updater deletes the running AppImage, then moves the download in with a +// PATH-resolved `mv`. When that `mv` fails (ENOTCONN from a dead AppImage mount on PATH) +// no app is left to launch. Rename over it instead, staged beside the destination so the +// rename stays on one filesystem and the old AppImage survives any failure. +export class AtomicAppImageUpdater extends AppImageUpdater { + protected override doInstall(options: Parameters[0]): boolean { + const appImage = process.env.APPIMAGE; + const installerPath = this.installerPath; + // Upstream throws on a missing or relative APPIMAGE before it touches any file. + if (appImage === undefined || !NodePath.isAbsolute(appImage)) { + return super.doInstall(options); + } + if (installerPath === null) { + this.dispatchError(new Error("No update filepath provided, can't quit and install")); + return false; + } + const name = NodePath.basename(appImage); + // A versioned file name follows the download; a custom one is kept (electron-builder#2964). + const destination = + NodePath.basename(installerPath) === name || !/\d+\.\d+\.\d+/u.test(name) + ? appImage + : NodePath.join(NodePath.dirname(appImage), NodePath.basename(installerPath)); + const staged = NodePath.join(NodePath.dirname(destination), `.${name}.update`); + NodeFS.rmSync(staged, { force: true }); + try { + try { + NodeFS.linkSync(installerPath, staged); + } catch { + NodeFS.copyFileSync(installerPath, staged); + } + NodeFS.renameSync(staged, destination); + } catch (error) { + NodeFS.rmSync(staged, { force: true }); + throw error; + } + NodeFS.rmSync(installerPath, { force: true }); + if (destination !== appImage) { + NodeFS.rmSync(appImage, { force: true }); + this.emit("appimage-filename-updated", destination); + } + const env = { ...process.env, APPIMAGE_SILENT_INSTALL: "true" }; + if (options.isForceRunAfter) { + void this.spawnLog(destination, [], env); + } else { + NodeChildProcess.execFileSync(destination, [], { + env: { ...env, APPIMAGE_EXIT_AFTER_INSTALL: "true" }, + }); + } + return true; + } +} + +let selectedUpdater: AppUpdater | undefined; +const updater = () => + (selectedUpdater ??= + autoUpdater instanceof AppImageUpdater ? new AtomicAppImageUpdater() : autoUpdater); + export type ElectronUpdaterFeedUrl = Parameters[0]; export class ElectronUpdaterCheckForUpdatesError extends Schema.TaggedError()( @@ -84,64 +146,64 @@ export class ElectronUpdater extends Context.Service< export const make = ElectronUpdater.of({ setFeedURL: (options) => Effect.suspend(() => { - autoUpdater.setFeedURL(options); + updater().setFeedURL(options); return Effect.void; }), setAutoDownload: (value) => Effect.suspend(() => { - autoUpdater.autoDownload = value; + updater().autoDownload = value; return Effect.void; }), setAutoInstallOnAppQuit: (value) => Effect.suspend(() => { - autoUpdater.autoInstallOnAppQuit = value; + updater().autoInstallOnAppQuit = value; return Effect.void; }), setChannel: (channel) => Effect.suspend(() => { - autoUpdater.channel = channel; + updater().channel = channel; return Effect.void; }), setAllowPrerelease: (value) => Effect.suspend(() => { - autoUpdater.allowPrerelease = value; + updater().allowPrerelease = value; return Effect.void; }), - allowDowngrade: Effect.sync(() => autoUpdater.allowDowngrade), + allowDowngrade: Effect.sync(() => updater().allowDowngrade), setAllowDowngrade: (value) => Effect.suspend(() => { - autoUpdater.allowDowngrade = value; + updater().allowDowngrade = value; return Effect.void; }), setFullChangelog: (value) => Effect.suspend(() => { - autoUpdater.fullChangelog = value; + updater().fullChangelog = value; return Effect.void; }), setDisableDifferentialDownload: (value) => Effect.suspend(() => { - autoUpdater.disableDifferentialDownload = value; + updater().disableDifferentialDownload = value; return Effect.void; }), checkForUpdates: Effect.suspend(() => { - const channel = autoUpdater.channel; + const channel = updater().channel; return Effect.tryPromise({ - try: () => autoUpdater.checkForUpdates(), + try: () => updater().checkForUpdates(), catch: (cause) => new ElectronUpdaterCheckForUpdatesError({ channel, cause }), }).pipe(Effect.asVoid); }), downloadUpdate: Effect.suspend(() => { - const channel = autoUpdater.channel; + const channel = updater().channel; return Effect.tryPromise({ - try: () => autoUpdater.downloadUpdate(), + try: () => updater().downloadUpdate(), catch: (cause) => new ElectronUpdaterDownloadUpdateError({ channel, cause }), }).pipe(Effect.asVoid); }), quitAndInstall: ({ isSilent, isForceRunAfter }) => Effect.suspend(() => { - const channel = autoUpdater.channel; + const channel = updater().channel; return Effect.try({ - try: () => autoUpdater.quitAndInstall(isSilent, isForceRunAfter), + try: () => updater().quitAndInstall(isSilent, isForceRunAfter), catch: (cause) => new ElectronUpdaterQuitAndInstallError({ channel, @@ -152,7 +214,7 @@ export const make = ElectronUpdater.of({ }); }), on: (eventName, listener) => { - const eventTarget = autoUpdater as unknown as { + const eventTarget = updater() as unknown as { on: (eventName: string, listener: (...args: Array) => void) => void; removeListener: (eventName: string, listener: (...args: Array) => void) => void; }; diff --git a/patches/electron-updater@6.8.9.patch b/patches/electron-updater@6.8.9.patch deleted file mode 100644 index 5ba3b00c59789..0000000000000 --- a/patches/electron-updater@6.8.9.patch +++ /dev/null @@ -1,44 +0,0 @@ -diff --git a/out/AppImageUpdater.js b/out/AppImageUpdater.js -index 452e93f819eaeb5e6532a831255adc70d854df4b..a9ae497c1049c2e2f9471583039ade64d54c43f1 100644 ---- a/out/AppImageUpdater.js -+++ b/out/AppImageUpdater.js -@@ -77,8 +77,6 @@ class AppImageUpdater extends BaseUpdater_1.BaseUpdater { - if (!path.isAbsolute(appImageFile) || appImageFile.includes("\0")) { - throw (0, builder_util_runtime_1.newError)(`APPIMAGE env is not a valid absolute path: "${appImageFile}"`, "ERR_UPDATER_OLD_FILE_NOT_FOUND"); - } -- // https://stackoverflow.com/a/1712051/1910191 -- (0, fs_1.unlinkSync)(appImageFile); - let destination; - const existingBaseName = path.basename(appImageFile); - const installerPath = this.installerPath; -@@ -95,8 +93,29 @@ class AppImageUpdater extends BaseUpdater_1.BaseUpdater { - else { - destination = path.join(path.dirname(appImageFile), path.basename(installerPath)); - } -- (0, child_process_1.execFileSync)("mv", ["-f", installerPath, destination]); -+ // T3 Code: swap the AppImage in with one rename instead of unlink + `mv`. The `mv` -+ // PATH lookup fails with ENOTCONN on a dead AppImage mount left on PATH, and the -+ // unlink before it had already removed the only copy of the app. Staging beside the -+ // destination keeps the rename on one filesystem, and the running AppImage stays in -+ // place until the new one is complete. -+ const stagedPath = path.join(path.dirname(destination), `.${path.basename(destination)}.update`); -+ (0, fs_1.rmSync)(stagedPath, { force: true }); -+ try { -+ try { -+ (0, fs_1.linkSync)(installerPath, stagedPath); -+ } -+ catch { -+ (0, fs_1.copyFileSync)(installerPath, stagedPath); -+ } -+ (0, fs_1.renameSync)(stagedPath, destination); -+ } -+ catch (e) { -+ (0, fs_1.rmSync)(stagedPath, { force: true }); -+ throw e; -+ } -+ (0, fs_1.rmSync)(installerPath, { force: true }); - if (destination !== appImageFile) { -+ (0, fs_1.rmSync)(appImageFile, { force: true }); - this.emit("appimage-filename-updated", destination); - } - const env = { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7b51effae8d49..232a7da308c7e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -341,7 +341,6 @@ patchedDependencies: alchemy@2.0.0-beta.80: bea1b6c0c0b23157fd5f439a1d7feff430f28ac1621ba135d8a13eeec60ccacd app-builder-lib@26.16.1: a28c2dfcfc2b90d6c6247e199e6537391db9ecd941854c650910d607442512d3 dbus-next@0.10.2: cfff57561b0ee59b5addb3b2e6c6f20906e967507a530ab67e8db8108e520ba4 - electron-updater@6.8.9: 3b5108258e7f60fb24aef159bcfda355ecf8af2bacc746ba1c6fff5116e8d666 expo-audio@58.0.9: 2c2f8c73a23d48804c8b537b8cd73c25eb331aa47d82eaa481c6766cb81e5add expo-modules-core@58.0.22: f0b0fd100550ed76e5c25b4d13eb7c9ff62825f8f197c53edf7bf447c50c9fb7 expo-network@58.0.3: cd09b6d1744dde4efa081b5619ebcff38877d98f7502a51cab121629dece8237 @@ -433,7 +432,7 @@ importers: version: 8.2.0 electron-updater: specifier: ^6.8.9 - version: 6.8.9(patch_hash=3b5108258e7f60fb24aef159bcfda355ecf8af2bacc746ba1c6fff5116e8d666)(supports-color@8.1.1) + version: 6.8.9(supports-color@8.1.1) electron-webauthn: specifier: 'catalog:' version: 1.3.1(typescript@7.0.2) @@ -18411,7 +18410,7 @@ snapshots: electron-to-chromium@1.5.430: {} - electron-updater@6.8.9(patch_hash=3b5108258e7f60fb24aef159bcfda355ecf8af2bacc746ba1c6fff5116e8d666)(supports-color@8.1.1): + electron-updater@6.8.9(supports-color@8.1.1): dependencies: builder-util-runtime: 9.7.0(supports-color@8.1.1) fs-extra: 10.1.0 diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index b36d6764e814d..24afc13b72281 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -364,9 +364,6 @@ patchedDependencies: # skip, the fingerprint silently drops every Expo native module and OTAs reach stale binaries. "@expo/fingerprint@0.21.5": patches/@expo__fingerprint@0.21.5.patch app-builder-lib@26.16.1: patches/app-builder-lib@26.16.1.patch - # Linux: an AppImage update renames the new file over the old one instead of deleting the - # old one before a PATH-resolved `mv`, so a failed install still leaves an app to launch. - electron-updater@6.8.9: patches/electron-updater@6.8.9.patch peerDependencyRules: allowAny: