Skip to content

Commit b5560a9

Browse files
committed
fix(desktop): control sockets work with long temporary paths
1 parent 08a463e commit b5560a9

2 files changed

Lines changed: 20 additions & 9 deletions

File tree

‎packages/shared/src/desktopAppControl.test.ts‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,30 @@ import { describe, expect, it } from "vite-plus/test";
33
import { resolveDesktopAppControlAddress } from "./desktopAppControl.ts";
44

55
describe("resolveDesktopAppControlAddress", () => {
6-
it("keeps Unix socket paths short and separates desktop state directories", () => {
6+
it.each([
7+
["linux", "/tmp", "/tmp/t3code-1000", 107],
8+
["linux", "/var/tmp/custom", "/var/tmp/custom/t3code-1000", 107],
9+
["linux", `/tmp/${"x".repeat(120)}`, "/tmp/t3code-1000", 107],
10+
["darwin", `/tmp/${"é".repeat(30)}`, "/tmp/t3code-1000", 103],
11+
["darwin", `/tmp/${"x".repeat(56)}`, `/tmp/${"x".repeat(56)}/t3code-1000`, 103],
12+
] as const)("keeps %s sockets short under %s", (platform, tempDir, directory, maxBytes) => {
713
const first = resolveDesktopAppControlAddress({
814
stateDir: `/home/user/${"long/".repeat(40)}userdata`,
9-
platform: "linux",
10-
tempDir: "/tmp",
15+
platform,
16+
tempDir,
1117
userId: 1000,
1218
joinPath: (...segments) => segments.join("/"),
1319
});
1420
const second = resolveDesktopAppControlAddress({
1521
stateDir: "/home/user/.t3/other/userdata",
16-
platform: "linux",
17-
tempDir: "/tmp",
22+
platform,
23+
tempDir,
1824
userId: 1000,
1925
joinPath: (...segments) => segments.join("/"),
2026
});
2127

22-
expect(first.directory).toBe("/tmp/t3code-1000");
23-
expect(first.address.length).toBeLessThan(108);
28+
expect(new TextEncoder().encode(first.address).byteLength).toBeLessThanOrEqual(maxBytes);
29+
expect(first.directory).toBe(directory);
2430
expect(first.address).not.toBe(second.address);
2531
});
2632

‎packages/shared/src/desktopAppControl.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,14 @@ export function resolveDesktopAppControlAddress(input: {
2929

3030
const userKey =
3131
input.userId === undefined ? shortHash(input.stateDir).slice(0, 12) : input.userId;
32-
const directory = input.joinPath(input.tempDir, `t3code-${userKey}`);
32+
const socketName = `${stateHash}.sock`;
33+
const maxPathBytes = input.platform === "linux" ? 107 : 103;
34+
let directory = input.joinPath(input.tempDir, `t3code-${userKey}`);
35+
if (new TextEncoder().encode(input.joinPath(directory, socketName)).byteLength > maxPathBytes) {
36+
directory = input.joinPath("/tmp", `t3code-${userKey}`);
37+
}
3338
return {
34-
address: input.joinPath(directory, `${stateHash}.sock`),
39+
address: input.joinPath(directory, socketName),
3540
directory,
3641
};
3742
}

0 commit comments

Comments
 (0)