From 8e08dc266ed6843a274debe33d2d50ea0747f254 Mon Sep 17 00:00:00 2001 From: ruck-syu Date: Sun, 8 Nov 2026 12:12:57 +0530 Subject: [PATCH 1/4] fix(server): failed workspace saves preserve existing files --- .../src/workspace/WorkspaceFileSystem.test.ts | 84 ++++++++++++++++++- .../src/workspace/WorkspaceFileSystem.ts | 56 ++++++++++--- 2 files changed, 129 insertions(+), 11 deletions(-) diff --git a/apps/server/src/workspace/WorkspaceFileSystem.test.ts b/apps/server/src/workspace/WorkspaceFileSystem.test.ts index 34ddeaa872ad4..605d56f392546 100644 --- a/apps/server/src/workspace/WorkspaceFileSystem.test.ts +++ b/apps/server/src/workspace/WorkspaceFileSystem.test.ts @@ -25,7 +25,12 @@ import { vi } from "vite-plus/test"; vi.mock("node:fs/promises", async (importOriginal) => { const actual = await importOriginal(); - return { ...actual, realpath: vi.fn(actual.realpath), open: vi.fn(actual.open) }; + return { + ...actual, + realpath: vi.fn(actual.realpath), + open: vi.fn(actual.open), + writeFile: vi.fn(actual.writeFile), + }; }); const injectShortReads = Effect.fn("injectShortReads")(function* (target: string) { @@ -572,6 +577,78 @@ it.layer(layerTest, { excludeTestServices: true })("WorkspaceFileSystemLive", (i }); describe("writeFile", () => { + it.effect.each([ + { existing: false, failure: "write" }, + { existing: true, failure: "write" }, + { existing: false, failure: "rename" }, + { existing: true, failure: "rename" }, + { existing: true, failure: "cleanup" }, + { existing: true, failure: "directory" }, + ])( + "handles $failure failure without losing destination contents (existing: $existing)", + ({ existing, failure }) => + Effect.gen(function* () { + const service = yield* WorkspaceFileSystem.WorkspaceFileSystem; + const fs = yield* FileSystem.FileSystem; + const path = yield* Path.Path; + const cwd = yield* makeTempDir; + const target = path.join(yield* fs.realPath(cwd), "report.md"); + const original = "original contents\n"; + if (existing) yield* writeTextFile(cwd, "report.md", original); + const native = yield* Effect.promise(() => + vi.importActual("node:fs/promises"), + ); + const cause = Object.assign(new Error("Save failed"), { + code: failure === "write" ? "EFBIG" : "EACCES", + }); + using _write = vi + .spyOn(NodeFSP, "writeFile") + .mockImplementation(async (file, data, options) => { + if (failure !== "write") return native.writeFile(file, data, options); + await native.writeFile(file, String(data).slice(0, 4), options); + throw cause; + }); + using _rename = vi.spyOn(NodeFSP, "rename").mockImplementation(async (...args) => { + if (failure === "rename") throw cause; + return native.rename(...args); + }); + using _cleanup = vi.spyOn(NodeFSP, "rm").mockImplementation(async (...args) => { + if (failure === "cleanup") throw cause; + return native.rm(...args); + }); + using _directory = vi.spyOn(NodeFSP, "mkdtemp").mockImplementation(async (...args) => { + if (failure === "directory") throw cause; + return native.mkdtemp(...args); + }); + + if (failure === "cleanup") { + expect( + yield* service.writeFile({ + cwd, + relativePath: "report.md", + contents: "replacement\n", + }), + ).toEqual({ relativePath: "report.md" }); + expect(yield* fs.readFileString(target)).toBe("replacement\n"); + return; + } + + const error = yield* service + .writeFile({ cwd, relativePath: "report.md", contents: "replacement contents\n" }) + .pipe(Effect.flip); + + expect(error).toMatchObject({ + _tag: "WorkspaceFileSystemOperationError", + operation: "write-file", + operationPath: target, + cause, + }); + if (existing) expect(yield* fs.readFileString(target)).toBe(original); + else expect(yield* fs.exists(target)).toBe(false); + expect(yield* fs.readDirectory(cwd)).toEqual(existing ? ["report.md"] : []); + }), + ); + it.effect("rejects writes outside a known workspace", () => Effect.gen(function* () { const workspaceFileSystem = yield* WorkspaceFileSystem.WorkspaceFileSystem; @@ -638,6 +715,8 @@ it.layer(layerTest, { excludeTestServices: true })("WorkspaceFileSystemLive", (i const path = yield* Path.Path; const cwd = yield* makeTempDir; yield* writeTextFile(cwd, "src/main.ts", "export {};\n"); + const target = path.join(cwd, "src/main.ts"); + if (HostProcess.Platform.defaultValue() !== "win32") yield* fileSystem.chmod(target, 0o750); yield* workspaceFileSystem.writeFile({ cwd, @@ -648,6 +727,9 @@ it.layer(layerTest, { excludeTestServices: true })("WorkspaceFileSystemLive", (i expect(yield* fileSystem.readFileString(path.join(cwd, "src/main.ts"))).toBe( "export const edited = true;\n", ); + if (HostProcess.Platform.defaultValue() !== "win32") { + expect((yield* fileSystem.stat(target)).mode & 0o777).toBe(0o750); + } yield* writeTextFile(cwd, "report.txt", "ordinary file"); for (const relativePath of whitespaceFilePaths) { diff --git a/apps/server/src/workspace/WorkspaceFileSystem.ts b/apps/server/src/workspace/WorkspaceFileSystem.ts index 7f3fb67b15000..ac4801abbc613 100644 --- a/apps/server/src/workspace/WorkspaceFileSystem.ts +++ b/apps/server/src/workspace/WorkspaceFileSystem.ts @@ -602,16 +602,43 @@ export const make = Effect.gen(function* () { }), ), ); + const platform = yield* HostProcess.Platform; + let cleanupFailure: unknown; yield* Effect.tryPromise({ - // A symlink swapped in after the check is not followed. Windows lacks O_NOFOLLOW. - try: () => - NodeFSP.writeFile(realTargetPath, contents, { - flag: - NodeFS.constants.O_WRONLY | - NodeFS.constants.O_CREAT | - NodeFS.constants.O_TRUNC | - (NodeFS.constants.O_NOFOLLOW ?? 0), - }), + try: async () => { + // Check write access without truncating; a swapped-in symlink is not followed on POSIX. + const previous = await NodeFSP.open( + realTargetPath, + NodeFS.constants.O_WRONLY | (NodeFS.constants.O_NOFOLLOW ?? 0), + ).catch((error: unknown) => { + if ((error as NodeJS.ErrnoException).code === "ENOENT") return undefined; + throw error; + }); + let mode: number | undefined; + if (previous) { + try { + mode = (await previous.stat()).mode & 0o777; + } finally { + await previous.close(); + } + } + const temporaryDirectory = await NodeFSP.mkdtemp( + path.join(path.dirname(realTargetPath), ".t3-save-"), + ); + try { + const temporaryPath = path.join(temporaryDirectory, "contents"); + await NodeFSP.writeFile(temporaryPath, contents, { flag: "wx", mode }); + if (mode !== undefined && platform !== "win32") await NodeFSP.chmod(temporaryPath, mode); + await NodeFSP.rename(temporaryPath, realTargetPath); + } finally { + // Cleanup must not report failure after the replacement has landed. + await NodeFSP.rm(temporaryDirectory, { recursive: true, force: true }).catch( + (cause: unknown) => { + cleanupFailure = cause; + }, + ); + } + }, catch: (cause) => new WorkspaceFileSystemOperationError({ workspaceRoot: input.cwd, @@ -621,7 +648,16 @@ export const make = Effect.gen(function* () { operation: "write-file", cause, }), - }); + }).pipe( + Effect.onExit(() => + cleanupFailure === undefined + ? Effect.void + : Effect.logWarning("Workspace save temporary cleanup failed", { + path: realTargetPath, + cause: cleanupFailure, + }), + ), + ); // Editor autosave overwrites existing files, which leaves the indexed paths unchanged, and // fff's watcher applies the new contents on its own. A forced rescan re-walks the whole // workspace, and the save would wait for it. From 49f530593df8abfe190550b81ebb83dce2f32108 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sun, 15 Nov 2026 06:36:44 +0000 Subject: [PATCH 2/4] test(server): keep workspace save failure cases that guard regressions Co-Authored-By: Claude Opus 5.5 --- apps/server/src/workspace/WorkspaceFileSystem.test.ts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/apps/server/src/workspace/WorkspaceFileSystem.test.ts b/apps/server/src/workspace/WorkspaceFileSystem.test.ts index 2d593755ff910..adb09520083fa 100644 --- a/apps/server/src/workspace/WorkspaceFileSystem.test.ts +++ b/apps/server/src/workspace/WorkspaceFileSystem.test.ts @@ -582,10 +582,8 @@ it.layer(layerTest, { excludeTestServices: true })("WorkspaceFileSystemLive", (i it.effect.each([ { existing: false, failure: "write" }, { existing: true, failure: "write" }, - { existing: false, failure: "rename" }, { existing: true, failure: "rename" }, { existing: true, failure: "cleanup" }, - { existing: true, failure: "directory" }, ])( "handles $failure failure without losing destination contents (existing: $existing)", ({ existing, failure }) => @@ -618,10 +616,6 @@ it.layer(layerTest, { excludeTestServices: true })("WorkspaceFileSystemLive", (i if (failure === "cleanup") throw cause; return native.rm(...args); }); - using _directory = vi.spyOn(NodeFSP, "mkdtemp").mockImplementation(async (...args) => { - if (failure === "directory") throw cause; - return native.mkdtemp(...args); - }); if (failure === "cleanup") { expect( From 9d7dce2d6ac32cea3c046fc563def020c3aeec42 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sun, 15 Nov 2026 06:52:10 +0000 Subject: [PATCH 3/4] fix(server): stage workspace saves through the shared atomic writer Saves now go through writeFileStringAtomically, which retries Windows rename locks, with a new mode option that keeps the file's permissions. A writable file in a directory the server cannot write to is saved in place, as before, since a staging file cannot be created beside it. Co-Authored-By: Claude Opus 5.5 --- .../src/workspace/WorkspaceFileSystem.test.ts | 82 +++++++++++------- .../src/workspace/WorkspaceFileSystem.ts | 86 +++++++++---------- packages/shared/src/atomicWrite.ts | 7 +- 3 files changed, 100 insertions(+), 75 deletions(-) diff --git a/apps/server/src/workspace/WorkspaceFileSystem.test.ts b/apps/server/src/workspace/WorkspaceFileSystem.test.ts index adb09520083fa..64fe33ea74d4c 100644 --- a/apps/server/src/workspace/WorkspaceFileSystem.test.ts +++ b/apps/server/src/workspace/WorkspaceFileSystem.test.ts @@ -10,6 +10,7 @@ import * as Effect from "effect/Effect"; import * as FileSystem from "effect/FileSystem"; import * as Layer from "effect/Layer"; import * as Path from "effect/Path"; +import * as PlatformError from "effect/PlatformError"; import * as ServerConfig from "../config.ts"; import { makeFakeWslHost } from "../testUtils/fakeWsl.ts"; @@ -25,12 +26,7 @@ import { vi } from "vite-plus/test"; vi.mock("node:fs/promises", async (importOriginal) => { const actual = await importOriginal(); - return { - ...actual, - realpath: vi.fn(actual.realpath), - open: vi.fn(actual.open), - writeFile: vi.fn(actual.writeFile), - }; + return { ...actual, realpath: vi.fn(actual.realpath), open: vi.fn(actual.open) }; }); const injectShortReads = Effect.fn("injectShortReads")(function* (target: string) { @@ -584,38 +580,42 @@ it.layer(layerTest, { excludeTestServices: true })("WorkspaceFileSystemLive", (i { existing: true, failure: "write" }, { existing: true, failure: "rename" }, { existing: true, failure: "cleanup" }, - ])( + ] as const)( "handles $failure failure without losing destination contents (existing: $existing)", ({ existing, failure }) => Effect.gen(function* () { - const service = yield* WorkspaceFileSystem.WorkspaceFileSystem; const fs = yield* FileSystem.FileSystem; const path = yield* Path.Path; const cwd = yield* makeTempDir; const target = path.join(yield* fs.realPath(cwd), "report.md"); const original = "original contents\n"; if (existing) yield* writeTextFile(cwd, "report.md", original); - const native = yield* Effect.promise(() => - vi.importActual("node:fs/promises"), + const cause = new Error("Save failed"); + const failing = (operation: string) => + Effect.fail( + PlatformError.systemError({ + _tag: "Unknown", + module: "FileSystem", + method: operation, + cause, + }), + ); + const service = yield* WorkspaceFileSystem.make.pipe( + Effect.provide(layerKnownWorkspacesTest), + Effect.provideService(FileSystem.FileSystem, { + ...fs, + writeFileString: (file, data, options) => + failure === "write" + ? fs + .writeFileString(file, data.slice(0, 4), options) + .pipe(Effect.andThen(failing("writeFile"))) + : fs.writeFileString(file, data, options), + rename: (from, to) => + failure === "rename" ? failing("rename") : fs.rename(from, to), + remove: (file, options) => + failure === "cleanup" ? failing("remove") : fs.remove(file, options), + }), ); - const cause = Object.assign(new Error("Save failed"), { - code: failure === "write" ? "EFBIG" : "EACCES", - }); - using _write = vi - .spyOn(NodeFSP, "writeFile") - .mockImplementation(async (file, data, options) => { - if (failure !== "write") return native.writeFile(file, data, options); - await native.writeFile(file, String(data).slice(0, 4), options); - throw cause; - }); - using _rename = vi.spyOn(NodeFSP, "rename").mockImplementation(async (...args) => { - if (failure === "rename") throw cause; - return native.rename(...args); - }); - using _cleanup = vi.spyOn(NodeFSP, "rm").mockImplementation(async (...args) => { - if (failure === "cleanup") throw cause; - return native.rm(...args); - }); if (failure === "cleanup") { expect( @@ -637,7 +637,6 @@ it.layer(layerTest, { excludeTestServices: true })("WorkspaceFileSystemLive", (i _tag: "WorkspaceFileSystemOperationError", operation: "write-file", operationPath: target, - cause, }); if (existing) expect(yield* fs.readFileString(target)).toBe(original); else expect(yield* fs.exists(target)).toBe(false); @@ -645,6 +644,31 @@ it.layer(layerTest, { excludeTestServices: true })("WorkspaceFileSystemLive", (i }), ); + it.effect.skipIf(HostProcess.Platform.defaultValue() === "win32" || process.getuid?.() === 0)( + "saves a writable file inside a read-only directory", + () => + Effect.gen(function* () { + const workspaceFileSystem = yield* WorkspaceFileSystem.WorkspaceFileSystem; + const fs = yield* FileSystem.FileSystem; + const path = yield* Path.Path; + const cwd = yield* makeTempDir; + yield* writeTextFile(cwd, "docs/report.md", "original\n"); + const docs = path.join(cwd, "docs"); + yield* fs.chmod(path.join(docs, "report.md"), 0o600); + yield* Effect.acquireRelease(fs.chmod(docs, 0o500), () => + fs.chmod(docs, 0o700).pipe(Effect.ignore), + ); + + yield* workspaceFileSystem.writeFile({ + cwd, + relativePath: "docs/report.md", + contents: "edited\n", + }); + + expect(yield* fs.readFileString(path.join(docs, "report.md"))).toBe("edited\n"); + }), + ); + it.effect("rejects writes outside a known workspace", () => Effect.gen(function* () { const workspaceFileSystem = yield* WorkspaceFileSystem.WorkspaceFileSystem; diff --git a/apps/server/src/workspace/WorkspaceFileSystem.ts b/apps/server/src/workspace/WorkspaceFileSystem.ts index 162de7d0532b2..5638ab19c8463 100644 --- a/apps/server/src/workspace/WorkspaceFileSystem.ts +++ b/apps/server/src/workspace/WorkspaceFileSystem.ts @@ -12,6 +12,7 @@ import type { ProjectWriteFileResult, } from "@t3tools/contracts"; import { expandHomePath } from "@t3tools/provider-core/server/pathExpansion"; +import { writeFileStringAtomically } from "@t3tools/shared/atomicWrite"; import * as HostProcess from "@t3tools/shared/HostProcess"; import { isNetworkPath } from "@t3tools/shared/path"; import * as Context from "effect/Context"; @@ -603,62 +604,57 @@ export const make = Effect.gen(function* () { }), ), ); - const platform = yield* HostProcess.Platform; - let cleanupFailure: unknown; - yield* Effect.tryPromise({ + const writeError = (cause: unknown) => + new WorkspaceFileSystemOperationError({ + workspaceRoot: input.cwd, + relativePath: input.relativePath, + resolvedPath: realTargetPath, + operationPath: realTargetPath, + operation: "write-file", + cause, + }); + const staged = yield* Effect.tryPromise({ try: async () => { - // Check write access without truncating; a swapped-in symlink is not followed on POSIX. - const previous = await NodeFSP.open( + // Checks write access without truncating; a symlink swapped in here is not followed on POSIX. + const existing = await NodeFSP.open( realTargetPath, NodeFS.constants.O_WRONLY | (NodeFS.constants.O_NOFOLLOW ?? 0), ).catch((error: unknown) => { if ((error as NodeJS.ErrnoException).code === "ENOENT") return undefined; throw error; }); - let mode: number | undefined; - if (previous) { - try { - mode = (await previous.stat()).mode & 0o777; - } finally { - await previous.close(); - } - } - const temporaryDirectory = await NodeFSP.mkdtemp( - path.join(path.dirname(realTargetPath), ".t3-save-"), - ); + if (!existing) return {}; try { - const temporaryPath = path.join(temporaryDirectory, "contents"); - await NodeFSP.writeFile(temporaryPath, contents, { flag: "wx", mode }); - if (mode !== undefined && platform !== "win32") await NodeFSP.chmod(temporaryPath, mode); - await NodeFSP.rename(temporaryPath, realTargetPath); - } finally { - // Cleanup must not report failure after the replacement has landed. - await NodeFSP.rm(temporaryDirectory, { recursive: true, force: true }).catch( - (cause: unknown) => { - cleanupFailure = cause; - }, + const mode = (await existing.stat()).mode & 0o777; + const canStage = await NodeFSP.access( + path.dirname(realTargetPath), + NodeFS.constants.W_OK, + ).then( + () => true, + () => false, ); + if (canStage) return { mode }; + // Staging needs a writable directory; a writable file in a read-only one is saved in place. + await existing.truncate(0); + await existing.writeFile(contents); + return undefined; + } finally { + await existing.close(); } }, - catch: (cause) => - new WorkspaceFileSystemOperationError({ - workspaceRoot: input.cwd, - relativePath: input.relativePath, - resolvedPath: realTargetPath, - operationPath: realTargetPath, - operation: "write-file", - cause, - }), - }).pipe( - Effect.onExit(() => - cleanupFailure === undefined - ? Effect.void - : Effect.logWarning("Workspace save temporary cleanup failed", { - path: realTargetPath, - cause: cleanupFailure, - }), - ), - ); + catch: writeError, + }); + if (staged) { + yield* writeFileStringAtomically({ + filePath: realTargetPath, + contents, + ...staged, + }).pipe( + Effect.provideService(FileSystem.FileSystem, fileSystem), + Effect.provideService(Path.Path, path), + Effect.mapError(writeError), + ); + } // Editor autosave overwrites existing files, which leaves the indexed paths unchanged, and // fff's watcher applies the new contents on its own. A forced rescan re-walks the whole // workspace, and the save would wait for it. diff --git a/packages/shared/src/atomicWrite.ts b/packages/shared/src/atomicWrite.ts index febd1a98fbfca..7fa104f844715 100644 --- a/packages/shared/src/atomicWrite.ts +++ b/packages/shared/src/atomicWrite.ts @@ -22,6 +22,8 @@ const CHUNK_WRITE_LENGTH = 1 << 20; export const writeFileStringAtomically = (input: { readonly filePath: string; readonly contents: string | Iterable; + /** Permission bits for the replacement; ignored on Windows. */ + readonly mode?: number; }) => Effect.scoped( Effect.gen(function* () { @@ -65,7 +67,10 @@ export const writeFileStringAtomically = (input: { }), ); } - if (platform !== "win32") return yield* fs.rename(tempPath, targetPath); + if (platform !== "win32") { + if (input.mode !== undefined) yield* fs.chmod(tempPath, input.mode); + return yield* fs.rename(tempPath, targetPath); + } // Stop retrying if another save changes the target; read-only targets also return permanent EPERM. const targetVersion = fs.stat(targetPath).pipe( From 58dead4e5920108898d04962f81fda4494bf9d0b Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sun, 15 Nov 2026 07:04:26 +0000 Subject: [PATCH 4/4] fix(server): workspace saves replace a swapped-in symlink instead of following it The save target is checked against the workspace and .git after its links are resolved. The shared atomic writer then resolved links again, so a link swapped in after the check was followed to an unchecked destination. Saves now rename onto the checked path with followSymlinks: false. Co-Authored-By: Claude Opus 5.5 --- .../src/workspace/WorkspaceFileSystem.test.ts | 34 +++++++++++++++++++ .../src/workspace/WorkspaceFileSystem.ts | 2 ++ packages/shared/src/atomicWrite.ts | 7 +++- 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/apps/server/src/workspace/WorkspaceFileSystem.test.ts b/apps/server/src/workspace/WorkspaceFileSystem.test.ts index 64fe33ea74d4c..6356811563e8d 100644 --- a/apps/server/src/workspace/WorkspaceFileSystem.test.ts +++ b/apps/server/src/workspace/WorkspaceFileSystem.test.ts @@ -669,6 +669,40 @@ it.layer(layerTest, { excludeTestServices: true })("WorkspaceFileSystemLive", (i }), ); + it.effect.skipIf(!symlinksSupported)( + "replaces a symlink swapped in after the target check instead of writing through it", + () => + Effect.gen(function* () { + const fs = yield* FileSystem.FileSystem; + const path = yield* Path.Path; + const cwd = yield* makeTempDir; + const outside = path.join(yield* makeTempDir, "outside.txt"); + yield* fs.writeFileString(outside, "outside\n"); + yield* writeTextFile(cwd, "report.md", "original\n"); + const target = path.join(yield* fs.realPath(cwd), "report.md"); + let swapped = false; + const swap = Effect.suspend(() => { + if (swapped) return Effect.void; + swapped = true; + return fs.remove(target).pipe(Effect.andThen(fs.symlink(outside, target))); + }); + const service = yield* WorkspaceFileSystem.make.pipe( + Effect.provide(layerKnownWorkspacesTest), + Effect.provideService(FileSystem.FileSystem, { + ...fs, + readLink: (file) => swap.pipe(Effect.andThen(fs.readLink(file))), + makeTempDirectory: (options) => + swap.pipe(Effect.andThen(fs.makeTempDirectory(options))), + }), + ); + + yield* service.writeFile({ cwd, relativePath: "report.md", contents: "edited\n" }); + + expect(yield* fs.readFileString(outside)).toBe("outside\n"); + expect(yield* fs.readFileString(target)).toBe("edited\n"); + }), + ); + it.effect("rejects writes outside a known workspace", () => Effect.gen(function* () { const workspaceFileSystem = yield* WorkspaceFileSystem.WorkspaceFileSystem; diff --git a/apps/server/src/workspace/WorkspaceFileSystem.ts b/apps/server/src/workspace/WorkspaceFileSystem.ts index 5638ab19c8463..849a29ad2faee 100644 --- a/apps/server/src/workspace/WorkspaceFileSystem.ts +++ b/apps/server/src/workspace/WorkspaceFileSystem.ts @@ -649,6 +649,8 @@ export const make = Effect.gen(function* () { filePath: realTargetPath, contents, ...staged, + // The target was checked as resolved; a link swapped in since is replaced, not followed. + followSymlinks: false, }).pipe( Effect.provideService(FileSystem.FileSystem, fileSystem), Effect.provideService(Path.Path, path), diff --git a/packages/shared/src/atomicWrite.ts b/packages/shared/src/atomicWrite.ts index 7fa104f844715..f1dfda5804a82 100644 --- a/packages/shared/src/atomicWrite.ts +++ b/packages/shared/src/atomicWrite.ts @@ -24,13 +24,18 @@ export const writeFileStringAtomically = (input: { readonly contents: string | Iterable; /** Permission bits for the replacement; ignored on Windows. */ readonly mode?: number; + /** False renames onto `filePath` itself, replacing a link there instead of writing through it. */ + readonly followSymlinks?: boolean; }) => Effect.scoped( Effect.gen(function* () { const fs = yield* FileSystem.FileSystem; const path = yield* Path.Path; const platform = yield* HostProcess.Platform; - const targetPath = yield* resolveSymlinkTarget(input.filePath); + const targetPath = + input.followSymlinks === false + ? path.resolve(input.filePath) + : yield* resolveSymlinkTarget(input.filePath); const targetDirectory = path.dirname(targetPath); yield* fs.makeDirectory(targetDirectory, { recursive: true });