Skip to content

Commit bb4756e

Browse files
author
Umut
committed
fix(server): include symlinked directories in browse
1 parent 70cd258 commit bb4756e

2 files changed

Lines changed: 50 additions & 3 deletions

File tree

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,37 @@ it.layer(TestLayer, { excludeTestServices: true })("WorkspaceEntries", (it) => {
701701
}),
702702
);
703703

704+
it.effect("includes symlinked directories and ignores non-directory targets", () =>
705+
Effect.gen(function* () {
706+
const workspaceEntries = yield* WorkspaceEntries.WorkspaceEntries;
707+
const fileSystem = yield* FileSystem.FileSystem;
708+
const path = yield* Path.Path;
709+
const cwd = yield* makeTempDir({ prefix: "t3code-workspace-browse-symlink-" });
710+
const realDirectory = path.join(cwd, "projects");
711+
const linkedDirectory = path.join(cwd, "linked-projects");
712+
const linkedFile = path.join(cwd, "linked-file");
713+
const brokenLink = path.join(cwd, "broken-projects");
714+
715+
yield* fileSystem.makeDirectory(realDirectory);
716+
yield* fileSystem.writeFileString(path.join(cwd, "README.md"), "");
717+
yield* fileSystem.symlink(realDirectory, linkedDirectory);
718+
yield* fileSystem.symlink(path.join(cwd, "README.md"), linkedFile);
719+
yield* fileSystem.symlink(path.join(cwd, "missing"), brokenLink);
720+
721+
const result = yield* workspaceEntries.browse({
722+
partialPath: yield* appendSeparator(cwd),
723+
});
724+
725+
expect(result).toEqual({
726+
parentPath: cwd,
727+
entries: [
728+
{ name: "linked-projects", fullPath: linkedDirectory },
729+
{ name: "projects", fullPath: realDirectory },
730+
],
731+
});
732+
}),
733+
);
734+
704735
it.effect("rejects relative paths without cwd", () =>
705736
Effect.gen(function* () {
706737
const workspaceEntries = yield* WorkspaceEntries.WorkspaceEntries;

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

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,26 @@ export const make = Effect.gen(function* () {
209209
const entries: Array<{ readonly name: string; readonly fullPath: string }> = [];
210210
for (const dirent of dirents) {
211211
if (
212-
dirent.isDirectory() &&
213-
dirent.name.toLowerCase().startsWith(lowerPrefix) &&
214-
(showHidden || !dirent.name.startsWith("."))
212+
!dirent.name.toLowerCase().startsWith(lowerPrefix) ||
213+
(!showHidden && dirent.name.startsWith("."))
215214
) {
215+
continue;
216+
}
217+
218+
let isDirectory = dirent.isDirectory();
219+
if (!isDirectory && dirent.isSymbolicLink()) {
220+
// `readdir` reports symlinks as non-directories. Follow the target
221+
// only to classify it; broken or cyclic links are not browseable.
222+
isDirectory = yield* Effect.promise(async () => {
223+
try {
224+
return (await NodeFSP.stat(path.join(parentPath, dirent.name))).isDirectory();
225+
} catch {
226+
return false;
227+
}
228+
});
229+
}
230+
231+
if (isDirectory) {
216232
entries.push({
217233
name: dirent.name,
218234
fullPath: path.join(parentPath, dirent.name),

0 commit comments

Comments
 (0)