Skip to content

Commit ac08dc8

Browse files
committed
fix(desktop): keep the installed AppImage when the cache is a mount alias
1 parent c212916 commit ac08dc8

2 files changed

Lines changed: 31 additions & 2 deletions

File tree

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,29 @@ describe.skipIf(HostProcess.Platform.defaultValue() === "win32")("installAppImag
231231
assert.equal(NodeFS.readFileSync(destination, "utf8"), NEW_APPIMAGE);
232232
});
233233

234+
// A bind mount needs privileges. A macOS firmlink is the same kind of alias,
235+
// one directory entry under two paths that realpath keeps apart.
236+
it.skipIf(!NodeFS.existsSync("/System/Volumes/Data/private"))(
237+
"keeps the destination when the cache reaches it through a mount alias",
238+
() => {
239+
const input = fixture("T3-Code-1.2.2-x86_64.AppImage");
240+
const alias = NodePath.join("/System/Volumes/Data", NodeFS.realpathSync(input.applications));
241+
const installerPath = NodePath.join(alias, NodePath.basename(input.installerPath));
242+
NodeFS.renameSync(input.installerPath, installerPath);
243+
const entry = NodePath.join(input.applications, NodePath.basename(installerPath));
244+
assert.notEqual(NodeFS.realpathSync(installerPath), NodeFS.realpathSync(entry));
245+
assert.equal(NodeFS.statSync(installerPath).ino, NodeFS.statSync(entry).ino);
246+
const destination = installAppImageUpdate({
247+
...input,
248+
installerPath,
249+
sha512: sha512(NEW_APPIMAGE),
250+
});
251+
assert.equal(destination, entry);
252+
assert.equal(NodeFS.readFileSync(destination, "utf8"), NEW_APPIMAGE);
253+
assert.isFalse(NodeFS.existsSync(input.appImageFile));
254+
},
255+
);
256+
234257
it("rejects an empty source even when its digest matches", () => {
235258
const input = fixture();
236259
NodeFS.writeFileSync(input.installerPath, "");

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,14 @@ export function installAppImageUpdate(input: {
7070
const staged = NodePath.join(stageDirectory, "update.AppImage");
7171
const cleanup = (path: string, directory = false) => {
7272
try {
73-
// realpath also covers a cache reached through a symlinked directory.
74-
if (!directory && NodeFS.realpathSync(path) === NodeFS.realpathSync(destination)) return;
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
75+
// bind mount, which realpath does not resolve.
76+
if (!directory) {
77+
const file = NodeFS.statSync(path, { bigint: true });
78+
const installed = NodeFS.statSync(destination, { bigint: true });
79+
if (file.dev === installed.dev && file.ino === installed.ino) return;
80+
}
7581
NodeFS.rmSync(path, { force: true, recursive: directory });
7682
} catch (error) {
7783
input.logger?.warn(

0 commit comments

Comments
 (0)