Skip to content

Commit 471d4cc

Browse files
committed
fix(desktop): persist AppImage replacements before cleanup
1 parent 91f27eb commit 471d4cc

6 files changed

Lines changed: 62 additions & 11 deletions

File tree

‎apps/desktop/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"effect": "catalog:",
2727
"electron": "44.4.2",
2828
"electron-store": "^8.2.0",
29-
"electron-updater": "^6.8.9",
29+
"electron-updater": "6.8.9",
3030
"ffi-rs": "1.3.2",
3131
"playwright-core": "1.60.0",
3232
"react-grab": "^0.1.32"

‎apps/desktop/src/electron/AppImageUpdater.test.ts‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,44 @@ afterEach(() => {
6666
});
6767

6868
describe("AppImage installation", () => {
69+
// eslint-disable-next-line t3code/no-global-process-runtime -- Directory fsync is a Linux installation boundary.
70+
it.skipIf(NodeOS.platform() !== "linux").each([false, true])(
71+
"syncs the renamed directory before cleanup and relaunch (sync failure: %s)",
72+
async (failSync) => {
73+
const { installed, installer, updater, errors, root } =
74+
await fixture("T3-Code-1.0.0.AppImage");
75+
const destination = NodePath.join(root, NodePath.basename(installer));
76+
const sync = fs.fsyncSync;
77+
let directoryFd: number | undefined;
78+
vi.spyOn(fs, "fsyncSync").mockImplementation((fd) => {
79+
if (fs.fstatSync(fd).isDirectory()) {
80+
directoryFd = fd;
81+
expect(fs.fstatSync(fd).ino).toBe(fs.statSync(root).ino);
82+
expect(fs.readFileSync(destination, "utf8")).toBe(newBinary);
83+
expect(fs.readFileSync(installed, "utf8")).toBe(oldBinary);
84+
expect(fs.readFileSync(installer, "utf8")).toBe(newBinary);
85+
expect(updater.spawnLog).not.toHaveBeenCalled();
86+
expect(updater.logger?.info).not.toHaveBeenCalledWith(
87+
expect.stringContaining("Installed verified"),
88+
);
89+
if (failSync) throw new Error("directory sync failed");
90+
}
91+
sync(fd);
92+
});
93+
94+
updater.quitAndInstall(true, true);
95+
96+
const closedFd = directoryFd;
97+
expect(closedFd).toBeDefined();
98+
if (closedFd !== undefined) expect(() => fs.fstatSync(closedFd)).toThrow();
99+
expect(errors).toHaveBeenCalledTimes(failSync ? 1 : 0);
100+
expect(updater.spawnLog).toHaveBeenCalledTimes(failSync ? 0 : 1);
101+
expect(vi.getTimerCount()).toBe(failSync ? 0 : 1);
102+
expect(fs.existsSync(installed)).toBe(failSync);
103+
expect(fs.existsSync(installer)).toBe(failSync);
104+
},
105+
);
106+
69107
it.each(["empty", "corrupt", "ENOSPC"])(
70108
"preserves the old executable after a %s copy",
71109
async (fault) => {

‎apps/desktop/src/electron/ElectronUpdater.test.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { assert, describe, it } from "@effect/vitest";
2+
import * as Context from "effect/Context";
23
import * as Effect from "effect/Effect";
34
import * as Layer from "effect/Layer";
45
import * as Logger from "effect/Logger";
56
import * as References from "effect/References";
7+
import * as Tracer from "effect/Tracer";
68
import { beforeEach, vi } from "vite-plus/test";
79

810
const { autoUpdaterMock } = vi.hoisted(() => ({
@@ -37,10 +39,11 @@ describe("ElectronUpdater", () => {
3739
const previousLogger = autoUpdaterMock.logger;
3840
const records: unknown[] = [];
3941
const logger = Logger.make(({ message, fiber }) => {
42+
const span = Context.getOrUndefined(fiber.context, Tracer.ParentSpan);
4043
records.push({
4144
message,
4245
component: fiber.getRef(References.CurrentLogAnnotations).component,
43-
span: fiber.currentSpan?._tag === "Span" ? fiber.currentSpan.name : undefined,
46+
span: span?._tag === "Span" ? span.name : undefined,
4447
});
4548
});
4649
return Effect.gen(function* () {
Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
diff --git a/out/AppImageUpdater.js b/out/AppImageUpdater.js
2-
index 25cef3598cd278cc2a7f1432377c7a50048824b9..b8427a0e622766755faaa0d616f361e5a284e265 100644
2+
index 452e93f..82a6b7c 100644
33
--- a/out/AppImageUpdater.js
44
+++ b/out/AppImageUpdater.js
55
@@ -6,6 +6,7 @@ const child_process_1 = require("child_process");
@@ -10,16 +10,16 @@ index 25cef3598cd278cc2a7f1432377c7a50048824b9..b8427a0e622766755faaa0d616f361e5
1010
const BaseUpdater_1 = require("./BaseUpdater");
1111
const FileWithEmbeddedBlockMapDifferentialDownloader_1 = require("./differentialDownloader/FileWithEmbeddedBlockMapDifferentialDownloader");
1212
const Provider_1 = require("./providers/Provider");
13-
@@ -74,8 +75,6 @@ class AppImageUpdater extends BaseUpdater_1.BaseUpdater {
14-
if (appImageFile == null) {
15-
throw (0, builder_util_runtime_1.newError)("APPIMAGE env is not defined", "ERR_UPDATER_OLD_FILE_NOT_FOUND");
13+
@@ -77,8 +78,6 @@ class AppImageUpdater extends BaseUpdater_1.BaseUpdater {
14+
if (!path.isAbsolute(appImageFile) || appImageFile.includes("\0")) {
15+
throw (0, builder_util_runtime_1.newError)(`APPIMAGE env is not a valid absolute path: "${appImageFile}"`, "ERR_UPDATER_OLD_FILE_NOT_FOUND");
1616
}
1717
- // https://stackoverflow.com/a/1712051/1910191
1818
- (0, fs_1.unlinkSync)(appImageFile);
1919
let destination;
2020
const existingBaseName = path.basename(appImageFile);
2121
const installerPath = this.installerPath;
22-
@@ -92,7 +91,53 @@ class AppImageUpdater extends BaseUpdater_1.BaseUpdater {
22+
@@ -95,7 +94,62 @@ class AppImageUpdater extends BaseUpdater_1.BaseUpdater {
2323
else {
2424
destination = path.join(path.dirname(appImageFile), path.basename(installerPath));
2525
}
@@ -52,6 +52,15 @@ index 25cef3598cd278cc2a7f1432377c7a50048824b9..b8427a0e622766755faaa0d616f361e5
5252
+ fs_1.closeSync(fd);
5353
+ }
5454
+ fs_1.renameSync(staged, destination);
55+
+ if (process.platform === "linux") {
56+
+ const directoryFd = fs_1.openSync(path.dirname(destination), "r");
57+
+ try {
58+
+ fs_1.fsyncSync(directoryFd);
59+
+ }
60+
+ finally {
61+
+ fs_1.closeSync(directoryFd);
62+
+ }
63+
+ }
5564
+ this._logger.info(`Installed verified AppImage at ${destination}`);
5665
+ }
5766
+ finally {

‎pnpm-lock.yaml‎

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎pnpm-workspace.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ patchedDependencies:
192192
"@react-navigation/[email protected]": patches/@react-navigation%[email protected]
193193
194194
195-
195+
196196
197197
198198

0 commit comments

Comments
 (0)