Showing the changes to apps/server/src/atomicWrite.ts (1 of 12 files). Show all
Unified · Split
| @@ -23,3 +23,25 @@ export const writeFileStringAtomically = (input: { · 22 unmodified lines | |||
| 23 | yield* fs.rename(tempPath, input.filePath); | 23 | yield* fs.rename(tempPath, input.filePath); |
| 24 | }), | 24 | }), |
| 25 | ); | 25 | ); |
| 26 | |||
| 27 | export const writeSymbolicLinkAtomically = (input: { | ||
| 28 | readonly linkPath: string; | ||
| 29 | readonly targetPath: string; | ||
| 30 | }) => | ||
| 31 | Effect.scoped( | ||
| 32 | Effect.gen(function* () { | ||
| 33 | const fs = yield* FileSystem.FileSystem; | ||
| 34 | const path = yield* Path.Path; | ||
| 35 | const targetDirectory = path.dirname(input.linkPath); | ||
| 36 | |||
| 37 | yield* fs.makeDirectory(targetDirectory, { recursive: true }); | ||
| 38 | const tempDirectory = yield* fs.makeTempDirectoryScoped({ | ||
| 39 | directory: targetDirectory, | ||
| 40 | prefix: `${path.basename(input.linkPath)}.`, | ||
| 41 | }); | ||
| 42 | const tempPath = path.join(tempDirectory, "link.tmp"); | ||
| 43 | |||
| 44 | yield* fs.symlink(input.targetPath, tempPath); | ||
| 45 | yield* fs.rename(tempPath, input.linkPath); | ||
| 46 | }), | ||
| 47 | ); | ||