Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(shared): Windows saves no longer fail while a scanner holds the file #21062

MergedSunkenInTime(GitHub profile, opens in a new tab)merged 1 commit intomain fromrefs/pull/21062/headmerged by juliusmarminge View on GitHub

Showing 3 changed files with 165 additions and 0 deletions (loading 2).

x
0 of 3 viewed, 3 left
165 additions and 0 deletionspackages/shared/src/atomicWrite.test.tsModified
View file
@@ -1,13 +1,17 @@
import * as NodeServices from "@effect/platform-node/NodeServices";
import { assert, it } from "@effect/vitest";
+import * as Deferred from "effect/Deferred";
import * as Effect from "effect/Effect";
import * as Exit from "effect/Exit";
+import * as Fiber from "effect/Fiber";
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 TestClock from "effect/testing/TestClock";
​
import { writeFileStringAtomically } from "./atomicWrite.ts";
+import * as HostProcess from "./HostProcess.ts";
​
it.layer(NodeServices.layer)("writeFileStringAtomically", (it) => {
it.effect("keeps a symlinked file linked and rewrites its destination", () =>
@@ -101,8 +105,169 @@
assert.strictEqual(yield* fs.readFileString(filePath), "fresh");
}),
+​
+ it.effect("waits out a Windows scanner holding the target, then replaces it", () =>
+ Effect.gen(function* () {
+ const fs = yield* FileSystem.FileSystem;
+ const path = yield* Path.Path;
+ const root = yield* fs.makeTempDirectoryScoped({ prefix: "t3-atomic-write-" });
+ const filePath = path.join(root, "settings.json");
+ yield* fs.writeFileString(filePath, "before");