|
5 | 5 | type DesktopUpdateChannel, |
6 | 6 | } from "@t3tools/contracts"; |
7 | 7 | import { fromLenientJson } from "@t3tools/shared/schemaJson"; |
| 8 | +import { resolveSymlinkTarget } from "@t3tools/shared/symlink"; |
8 | 9 | import * as Context from "effect/Context"; |
9 | 10 | import * as Crypto from "effect/Crypto"; |
10 | 11 | import * as Effect from "effect/Effect"; |
@@ -130,6 +131,7 @@ const settingsChange = (settings: DesktopSettings, changed: boolean): DesktopSet |
130 | 131 |
|
131 | 132 | const DesktopSettingsWriteOperation = Schema.Literals([ |
132 | 133 | "create-temporary-file-name", |
| 134 | + "resolve-symlink", |
133 | 135 | "encode-document", |
134 | 136 | "create-directory", |
135 | 137 | "write-temporary-file", |
@@ -421,8 +423,20 @@ const writeSettings = Effect.fn("desktop.settings.writeSettings")(function* (inp |
421 | 423 | readonly defaultSettings: DesktopSettings; |
422 | 424 | readonly suffix: string; |
423 | 425 | }): Effect.fn.Return<void, DesktopSettingsWriteError> { |
424 | | - const directory = input.path.dirname(input.settingsPath); |
425 | | - const tempPath = `${input.settingsPath}.${process.pid}.${input.suffix}.tmp`; |
| 426 | + const targetPath = yield* resolveSymlinkTarget(input.settingsPath).pipe( |
| 427 | + Effect.provideService(FileSystem.FileSystem, input.fileSystem), |
| 428 | + Effect.provideService(Path.Path, input.path), |
| 429 | + Effect.mapError( |
| 430 | + (cause) => |
| 431 | + new DesktopSettingsWriteError({ |
| 432 | + operation: "resolve-symlink", |
| 433 | + path: input.settingsPath, |
| 434 | + cause, |
| 435 | + }), |
| 436 | + ), |
| 437 | + ); |
| 438 | + const directory = input.path.dirname(targetPath); |
| 439 | + const tempPath = `${targetPath}.${process.pid}.${input.suffix}.tmp`; |
426 | 440 | const encoded = yield* encodeDesktopSettingsJson( |
427 | 441 | toDesktopSettingsDocument(input.settings, input.defaultSettings), |
428 | 442 | ).pipe( |
@@ -455,7 +469,7 @@ const writeSettings = Effect.fn("desktop.settings.writeSettings")(function* (inp |
455 | 469 | }), |
456 | 470 | ), |
457 | 471 | ); |
458 | | - yield* input.fileSystem.rename(tempPath, input.settingsPath).pipe( |
| 472 | + yield* input.fileSystem.rename(tempPath, targetPath).pipe( |
459 | 473 | Effect.mapError( |
460 | 474 | (cause) => |
461 | 475 | new DesktopSettingsWriteError({ |
|
0 commit comments