Skip to content

Commit 6de62af

Browse files
committed
fix(desktop): keep the realpath match beside the inode check
1 parent ea42ac8 commit 6de62af

2 files changed

Lines changed: 32 additions & 3 deletions

File tree

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,31 @@ describe.skipIf(HostProcess.Platform.defaultValue() === "win32")("installAppImag
300300
assert.isFalse(NodeFS.existsSync(input.installerPath));
301301
});
302302

303+
it("keeps the destination when the same path reports different inode numbers", () => {
304+
const input = fixture("T3-Code-1.2.2-x86_64.AppImage");
305+
const installerPath = NodePath.join(input.applications, NodePath.basename(input.installerPath));
306+
NodeFS.renameSync(input.installerPath, installerPath);
307+
const stat = vi.mocked(NodeFS.statSync).getMockImplementation() as (
308+
...args: Array<unknown>
309+
) => NodeFS.BigIntStats;
310+
let inodeOffset = 0n;
311+
vi.mocked(NodeFS.statSync).mockImplementation(((path: NodeFS.PathLike, options?: unknown) => {
312+
const result = stat(path, options);
313+
if (String(path) === installerPath && typeof result.ino === "bigint") {
314+
return { ...result, ino: result.ino + inodeOffset++ };
315+
}
316+
return result;
317+
}) as unknown as typeof NodeFS.statSync);
318+
const destination = installAppImageUpdate({
319+
...input,
320+
installerPath,
321+
sha512: sha512(NEW_APPIMAGE),
322+
});
323+
assert.equal(destination, installerPath);
324+
assert.equal(NodeFS.readFileSync(destination, "utf8"), NEW_APPIMAGE);
325+
assert.isFalse(NodeFS.existsSync(input.appImageFile));
326+
});
327+
303328
it("rejects an empty source even when its digest matches", () => {
304329
const input = fixture();
305330
NodeFS.writeFileSync(input.installerPath, "");

‎apps/desktop/src/electron/AppImageInstall.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,17 @@ export function installAppImageUpdate(input: {
7070
const staged = NodePath.join(stageDirectory, "update.AppImage");
7171
const cleanup = (path: string, directory = false) => {
7272
try {
73-
// The same device and inode is the installed file, whether the path
74-
// reaches it through a symlinked directory or a mount alias such as a
73+
// Equal realpaths protect filesystems with unstable inode numbers.
74+
// A matching device and inode also covers mount aliases such as a
7575
// bind mount, which realpath does not resolve.
7676
if (!directory) {
7777
const file = NodeFS.statSync(path, { bigint: true });
7878
const installed = NodeFS.statSync(destination, { bigint: true });
79-
if (file.dev === installed.dev && file.ino === installed.ino) return;
79+
if (
80+
NodeFS.realpathSync(path) === NodeFS.realpathSync(destination) ||
81+
(file.dev === installed.dev && file.ino === installed.ino)
82+
)
83+
return;
8084
}
8185
NodeFS.rmSync(path, { force: true, recursive: directory });
8286
} catch (error) {

0 commit comments

Comments
 (0)