Skip to content

Commit b59c68a

Browse files
committed
fix(desktop): verify regular launcher ownership
1 parent c821ed2 commit b59c68a

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

‎apps/desktop/src/app/DesktopCliCommand.test.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,14 @@ it.layer(NodeServices.layer)("DesktopCliCommand", (it) => {
135135
yield* command.uninstall;
136136
expect(yield* fs.readFileString(theirs)).toBe("npm's t3\n");
137137
expect(yield* fs.readLink(path.join(home, "bin", "t3"))).toBe(path.join(home, "gone"));
138+
139+
const launcher = path.join(home, ".t3", "bin", "t3");
140+
yield* fs.writeFileString(launcher, "npm's t3\n");
141+
process.env.PATH = path.dirname(launcher);
142+
expect(yield* command.state).toMatchObject({ onPath: false, shadowedBy: launcher });
143+
expect((yield* Effect.flip(command.install)).message).toContain("Could not set up");
144+
yield* command.uninstall;
145+
expect(yield* fs.readFileString(launcher)).toBe("npm's t3\n");
138146
}).pipe(Effect.scoped),
139147
);
140148

‎apps/desktop/src/app/DesktopCliCommand.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,10 @@ export const make = Effect.gen(function* () {
9494
function* (candidate: string) {
9595
if (yield* isOurLink(candidate)) return true;
9696
const [resolved, ours] = yield* Effect.all([fs.realPath(candidate), fs.realPath(launcher)]);
97-
return resolved === ours;
97+
if (resolved !== ours) return false;
98+
const info = yield* fs.stat(candidate);
99+
if (info.type !== "File" || Number(info.size) > 16_384) return false;
100+
return (yield* fs.readFileString(candidate)).includes(DesktopCliShim.MARKER);
98101
},
99102
Effect.orElseSucceed(() => false),
100103
);

0 commit comments

Comments
 (0)