Skip to content

Commit 582067b

Browse files
committed
fix(server): bound ancestor resolution for deep symlink paths
1 parent 9e4b2d2 commit 582067b

2 files changed

Lines changed: 19 additions & 12 deletions

File tree

‎apps/server/src/workspace/WorkspaceEntries.test.ts‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,13 +202,16 @@ it.layer(layerTest, { excludeTestServices: true })("WorkspaceEntries", (it) => {
202202
const fileSystem = yield* FileSystem.FileSystem;
203203
const path = yield* Path.Path;
204204
// Shaped like a pnpm `node_modules`: one link per package into `.pnpm`.
205+
const directoryPath = [...Array.from({ length: 80 }, () => "nested"), "node_modules"].join(
206+
"/",
207+
);
205208
const packages = Array.from({ length: 200 }, (_, index) => `pkg-${index}`);
206209
yield* Effect.forEach(
207210
packages,
208211
(name) =>
209212
Effect.gen(function* () {
210-
yield* writeTextFile(cwd, `node_modules/.pnpm/${name}/index.js`);
211-
yield* fileSystem.symlink(`.pnpm/${name}`, path.join(cwd, "node_modules", name));
213+
yield* writeTextFile(cwd, `${directoryPath}/.pnpm/${name}/index.js`);
214+
yield* fileSystem.symlink(`.pnpm/${name}`, path.join(cwd, directoryPath, name));
212215
}),
213216
{ concurrency: 32, discard: true },
214217
);
@@ -225,9 +228,12 @@ it.layer(layerTest, { excludeTestServices: true })("WorkspaceEntries", (it) => {
225228
}) as typeof NodeFSP.realpath);
226229

227230
const workspaceEntries = yield* WorkspaceEntries.WorkspaceEntries;
228-
const { entries } = yield* workspaceEntries.list({ cwd, directoryPath: "node_modules" });
231+
const { entries } = yield* workspaceEntries.list({ cwd, directoryPath });
229232
expect(entries.map((entry) => entry.path).toSorted()).toEqual(
230-
["node_modules/.pnpm", ...packages.map((name) => `node_modules/${name}`)].toSorted(),
233+
[
234+
`${directoryPath}/.pnpm`,
235+
...packages.map((name) => `${directoryPath}/${name}`),
236+
].toSorted(),
231237
);
232238
expect(entries.every((entry) => entry.kind === "directory")).toBe(true);
233239
expect(maxInFlight).toBeLessThanOrEqual(64);

‎apps/server/src/workspace/WorkspaceEntries.ts‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -332,14 +332,15 @@ export const make = Effect.gen(function* () {
332332
// Reject canonical ancestors so "Expand all folders" cannot follow a cycle.
333333
let visitedFolders: Promise<ReadonlyArray<string>> | undefined;
334334
const loadVisitedFolders = () =>
335-
(visitedFolders ??= Promise.all(
336-
target.relativePath
337-
.split("/")
338-
.filter((segment) => segment !== "")
339-
.map((_, index, segments) =>
340-
NodeFSP.realpath(path.join(normalizedCwd, ...segments.slice(0, index + 1))),
341-
),
342-
).then((folders) => [root, ...folders]));
335+
(visitedFolders ??= (async () => {
336+
const folders = [root];
337+
let current = normalizedCwd;
338+
for (const segment of target.relativePath.split("/").filter(Boolean)) {
339+
current = path.join(current, segment);
340+
folders.push(await NodeFSP.realpath(current));
341+
}
342+
return folders;
343+
})());
343344
const resolveSymlinkKind = async (
344345
name: string,
345346
): Promise<ProjectEntry["kind"] | undefined> => {

0 commit comments

Comments
 (0)