@openclaw/matrix 2026.11.10-beta.3 → 2026.12.1-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (149) hide show
  1. package/node_modules/@openclaw/fs-safe/CHANGELOG.md +57 -0
  2. package/node_modules/@openclaw/fs-safe/README.md +6 -0
  3. package/node_modules/@openclaw/fs-safe/dist/archive-parser.wasm +0 -0
  4. package/node_modules/@openclaw/fs-safe/dist/atomic-io.d.ts +1 -0
  5. package/node_modules/@openclaw/fs-safe/dist/atomic-io.js +10 -0
  6. package/node_modules/@openclaw/fs-safe/dist/bounded-read.d.ts +1 -1
  7. package/node_modules/@openclaw/fs-safe/dist/bounded-read.js +15 -4
  8. package/node_modules/@openclaw/fs-safe/dist/directory-guard.js +11 -2
  9. package/node_modules/@openclaw/fs-safe/dist/drvfs-parent.d.ts +6 -0
  10. package/node_modules/@openclaw/fs-safe/dist/drvfs-parent.js +38 -0
  11. package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-acquisition.d.ts +1 -1
  12. package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-acquisition.js +2 -2
  13. package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-root-acquire.js +13 -8
  14. package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-root-io.js +13 -0
  15. package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-root-mutation.d.ts +2 -2
  16. package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-root-mutation.js +34 -24
  17. package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-stale-admission.js +7 -2
  18. package/node_modules/@openclaw/fs-safe/dist/file-lock-sync.js +20 -20
  19. package/node_modules/@openclaw/fs-safe/dist/file-observation.d.ts +13 -2
  20. package/node_modules/@openclaw/fs-safe/dist/file-observation.js +8 -4
  21. package/node_modules/@openclaw/fs-safe/dist/file-store-sync-write.d.ts +1 -0
  22. package/node_modules/@openclaw/fs-safe/dist/file-store-sync-write.js +11 -1
  23. package/node_modules/@openclaw/fs-safe/dist/file-store-write-options.d.ts +2 -0
  24. package/node_modules/@openclaw/fs-safe/dist/file-store-write-options.js +17 -0
  25. package/node_modules/@openclaw/fs-safe/dist/file-store.d.ts +2 -1
  26. package/node_modules/@openclaw/fs-safe/dist/file-store.js +12 -16
  27. package/node_modules/@openclaw/fs-safe/dist/guest-native-python.js +1 -1
  28. package/node_modules/@openclaw/fs-safe/dist/guest.js +3 -4
  29. package/node_modules/@openclaw/fs-safe/dist/json-document-store.d.ts +2 -0
  30. package/node_modules/@openclaw/fs-safe/dist/json-document-store.js +1 -0
  31. package/node_modules/@openclaw/fs-safe/dist/json-store.js +1 -0
  32. package/node_modules/@openclaw/fs-safe/dist/json.d.ts +5 -2
  33. package/node_modules/@openclaw/fs-safe/dist/json.js +6 -2
  34. package/node_modules/@openclaw/fs-safe/dist/local-file-descriptor.js +16 -10
  35. package/node_modules/@openclaw/fs-safe/dist/native-binding.d.ts +6 -0
  36. package/node_modules/@openclaw/fs-safe/dist/native-pinned-write.js +4 -0
  37. package/node_modules/@openclaw/fs-safe/dist/native-staged-file-metadata.d.ts +20 -0
  38. package/node_modules/@openclaw/fs-safe/dist/native-staged-file-metadata.js +18 -0
  39. package/node_modules/@openclaw/fs-safe/dist/native-staged-file.d.ts +3 -18
  40. package/node_modules/@openclaw/fs-safe/dist/native-staged-file.js +48 -24
  41. package/node_modules/@openclaw/fs-safe/dist/opened-file-failure.js +19 -7
  42. package/node_modules/@openclaw/fs-safe/dist/output.d.ts +1 -0
  43. package/node_modules/@openclaw/fs-safe/dist/output.js +3 -0
  44. package/node_modules/@openclaw/fs-safe/dist/path-policy.js +4 -1
  45. package/node_modules/@openclaw/fs-safe/dist/permissions-windows.js +35 -10
  46. package/node_modules/@openclaw/fs-safe/dist/pinned-open.d.ts +9 -2
  47. package/node_modules/@openclaw/fs-safe/dist/pinned-open.js +42 -23
  48. package/node_modules/@openclaw/fs-safe/dist/pinned-write-staged.js +85 -34
  49. package/node_modules/@openclaw/fs-safe/dist/pinned-write-types.d.ts +3 -0
  50. package/node_modules/@openclaw/fs-safe/dist/pinned-write.js +4 -0
  51. package/node_modules/@openclaw/fs-safe/dist/prepare-directory-mode.d.ts +1 -0
  52. package/node_modules/@openclaw/fs-safe/dist/prepare-directory-mode.js +1 -1
  53. package/node_modules/@openclaw/fs-safe/dist/private-temp-workspace.js +2 -2
  54. package/node_modules/@openclaw/fs-safe/dist/publication-recovery.d.ts +24 -0
  55. package/node_modules/@openclaw/fs-safe/dist/publication-recovery.js +151 -0
  56. package/node_modules/@openclaw/fs-safe/dist/publish-copy-stage.d.ts +1 -0
  57. package/node_modules/@openclaw/fs-safe/dist/publish-copy-stage.js +2 -1
  58. package/node_modules/@openclaw/fs-safe/dist/realpath.d.ts +1 -1
  59. package/node_modules/@openclaw/fs-safe/dist/realpath.js +22 -11
  60. package/node_modules/@openclaw/fs-safe/dist/replace-file-descriptor.d.ts +1 -0
  61. package/node_modules/@openclaw/fs-safe/dist/replace-file-descriptor.js +5 -0
  62. package/node_modules/@openclaw/fs-safe/dist/replace-file-temp-owner.d.ts +7 -0
  63. package/node_modules/@openclaw/fs-safe/dist/replace-file-temp-owner.js +75 -2
  64. package/node_modules/@openclaw/fs-safe/dist/replace-file-types.d.ts +2 -0
  65. package/node_modules/@openclaw/fs-safe/dist/replace-file.js +14 -10
  66. package/node_modules/@openclaw/fs-safe/dist/root-context.js +28 -12
  67. package/node_modules/@openclaw/fs-safe/dist/root-copy.js +1 -0
  68. package/node_modules/@openclaw/fs-safe/dist/root-create-input.js +2 -2
  69. package/node_modules/@openclaw/fs-safe/dist/root-file-final-admission.d.ts +4 -0
  70. package/node_modules/@openclaw/fs-safe/dist/root-file-final-admission.js +53 -36
  71. package/node_modules/@openclaw/fs-safe/dist/root-file-open-batch-sync.js +3 -1
  72. package/node_modules/@openclaw/fs-safe/dist/root-file.d.ts +2 -1
  73. package/node_modules/@openclaw/fs-safe/dist/root-file.js +24 -13
  74. package/node_modules/@openclaw/fs-safe/dist/root-impl.js +17 -1
  75. package/node_modules/@openclaw/fs-safe/dist/root-options.d.ts +4 -2
  76. package/node_modules/@openclaw/fs-safe/dist/root-path.d.ts +1 -1
  77. package/node_modules/@openclaw/fs-safe/dist/root-path.js +2 -1
  78. package/node_modules/@openclaw/fs-safe/dist/root-read-admission.js +31 -9
  79. package/node_modules/@openclaw/fs-safe/dist/root-write-admission.js +6 -2
  80. package/node_modules/@openclaw/fs-safe/dist/secret-file.d.ts +1 -0
  81. package/node_modules/@openclaw/fs-safe/dist/secret-file.js +2 -0
  82. package/node_modules/@openclaw/fs-safe/dist/sibling-staged-file.d.ts +1 -0
  83. package/node_modules/@openclaw/fs-safe/dist/sibling-staged-file.js +84 -4
  84. package/node_modules/@openclaw/fs-safe/dist/sibling-temp.d.ts +1 -0
  85. package/node_modules/@openclaw/fs-safe/dist/sibling-temp.js +2 -0
  86. package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-acquire.js +22 -15
  87. package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-publication.d.ts +22 -0
  88. package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-publication.js +303 -0
  89. package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-reclaim.d.ts +2 -0
  90. package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-reclaim.js +9 -1
  91. package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-root.d.ts +8 -0
  92. package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-root.js +37 -3
  93. package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-staging.d.ts +14 -0
  94. package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-staging.js +155 -0
  95. package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-stale-admission.js +7 -2
  96. package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-write.d.ts +10 -0
  97. package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-write.js +143 -0
  98. package/node_modules/@openclaw/fs-safe/dist/temp-target.js +28 -7
  99. package/node_modules/@openclaw/fs-safe/dist/temp-workspace-admission.d.ts +2 -2
  100. package/node_modules/@openclaw/fs-safe/dist/temp-workspace-admission.js +34 -18
  101. package/node_modules/@openclaw/fs-safe/dist/temp-workspace-child-admission.d.ts +1 -1
  102. package/node_modules/@openclaw/fs-safe/dist/temp-workspace-child-admission.js +13 -3
  103. package/node_modules/@openclaw/fs-safe/dist/temp-workspace-ownership.js +1 -1
  104. package/node_modules/@openclaw/fs-safe/dist/temp-workspace-types.d.ts +9 -0
  105. package/node_modules/@openclaw/fs-safe/dist/test-hooks.d.ts +6 -0
  106. package/node_modules/@openclaw/fs-safe/dist/text-atomic.d.ts +1 -1
  107. package/node_modules/@openclaw/fs-safe/dist/text-atomic.js +1 -0
  108. package/node_modules/@openclaw/fs-safe/dist/windows-owner.d.ts +1 -0
  109. package/node_modules/@openclaw/fs-safe/dist/windows-owner.js +2 -1
  110. package/node_modules/@openclaw/fs-safe/dist/windows-security-helper.exe +0 -0
  111. package/node_modules/@openclaw/fs-safe/docs/advanced.md +6 -1
  112. package/node_modules/@openclaw/fs-safe/docs/atomic.md +64 -0
  113. package/node_modules/@openclaw/fs-safe/docs/contributing.md +69 -0
  114. package/node_modules/@openclaw/fs-safe/docs/file-store.md +2 -0
  115. package/node_modules/@openclaw/fs-safe/docs/json-store.md +2 -0
  116. package/node_modules/@openclaw/fs-safe/docs/json.md +2 -0
  117. package/node_modules/@openclaw/fs-safe/docs/output.md +2 -0
  118. package/node_modules/@openclaw/fs-safe/docs/permissions.md +20 -7
  119. package/node_modules/@openclaw/fs-safe/docs/reading.md +24 -9
  120. package/node_modules/@openclaw/fs-safe/docs/root.md +2 -0
  121. package/node_modules/@openclaw/fs-safe/docs/security-model.md +2 -0
  122. package/node_modules/@openclaw/fs-safe/docs/sidecar-lock.md +12 -7
  123. package/node_modules/@openclaw/fs-safe/docs/staged-file.md +2 -0
  124. package/node_modules/@openclaw/fs-safe/docs/temp-isolation-reference.md +73 -0
  125. package/node_modules/@openclaw/fs-safe/docs/temp.md +65 -0
  126. package/node_modules/@openclaw/fs-safe/docs/testing.md +1 -0
  127. package/node_modules/@openclaw/fs-safe/docs/writing.md +2 -0
  128. package/node_modules/@openclaw/fs-safe/package.json +25 -20
  129. package/node_modules/@openclaw/fs-safe-darwin-arm64/fs-safe-native.node +0 -0
  130. package/node_modules/@openclaw/fs-safe-darwin-arm64/package.json +1 -1
  131. package/node_modules/@openclaw/fs-safe-darwin-x64/fs-safe-native.node +0 -0
  132. package/node_modules/@openclaw/fs-safe-darwin-x64/package.json +1 -1
  133. package/node_modules/@openclaw/fs-safe-freebsd-arm64/fs-safe-native.node +0 -0
  134. package/node_modules/@openclaw/fs-safe-freebsd-arm64/package.json +1 -1
  135. package/node_modules/@openclaw/fs-safe-freebsd-x64/fs-safe-native.node +0 -0
  136. package/node_modules/@openclaw/fs-safe-freebsd-x64/package.json +1 -1
  137. package/node_modules/@openclaw/fs-safe-linux-arm64-gnu/fs-safe-native.node +0 -0
  138. package/node_modules/@openclaw/fs-safe-linux-arm64-gnu/package.json +1 -1
  139. package/node_modules/@openclaw/fs-safe-linux-arm64-musl/fs-safe-native.node +0 -0
  140. package/node_modules/@openclaw/fs-safe-linux-arm64-musl/package.json +1 -1
  141. package/node_modules/@openclaw/fs-safe-linux-x64-gnu/fs-safe-native.node +0 -0
  142. package/node_modules/@openclaw/fs-safe-linux-x64-gnu/package.json +1 -1
  143. package/node_modules/@openclaw/fs-safe-linux-x64-musl/fs-safe-native.node +0 -0
  144. package/node_modules/@openclaw/fs-safe-linux-x64-musl/package.json +1 -1
  145. package/node_modules/@openclaw/fs-safe-win32-arm64-msvc/fs-safe-native.node +0 -0
  146. package/node_modules/@openclaw/fs-safe-win32-arm64-msvc/package.json +1 -1
  147. package/node_modules/@openclaw/fs-safe-win32-x64-msvc/fs-safe-native.node +0 -0
  148. package/node_modules/@openclaw/fs-safe-win32-x64-msvc/package.json +1 -1
  149. package/package.json +5 -5
@@ -1,5 +1,62 @@
1
1
  # Changelog
2
2
 
3
+ ## Unreleased
4
+
5
+ ## 0.28.2 - 2026-11-22
6
+
7
+ **Highlights:** Windows bindings no longer need a separate Visual C++ Redistributable, long temporary-file paths work reliably, and archive decoding handles chunked bzip2 input plus gzip/deflate fixes.
8
+
9
+ ### Fixes
10
+
11
+ - **Windows native loading:** remove the separate Visual C++ Redistributable prerequisite for x64 and ARM64 bindings while retaining the OS-serviced UCRT. Thanks @paulcam206. ([#1094](https://github.com/openclaw/fs-safe/pull/1094))
12
+
13
+ - **Windows temp files:** create temporary directories on long paths without exposing extended-length namespace aliases to callers; preserve identity and cleanup checks. Thanks @xuanda0201. ([#1091](https://github.com/openclaw/fs-safe/pull/1091))
14
+
15
+ - **Archive decoding:** preserve bzip2 decoder progress for valid streams with long coding tables split across input chunks, and update native gzip/deflate decoding fixes. ([#1103](https://github.com/openclaw/fs-safe/pull/1103))
16
+
17
+ ## 0.28.1 - 2026-11-13
18
+
19
+ **Highlights:** Fixes for Root lock contention, stale-lock diagnostics, guest temporary names, and opt-in DrvFS writes.
20
+
21
+ ### Fixes
22
+
23
+ - **Guest filesystem:** generate temporary names with OS randomness without importing Python hashing or TLS modules; preserve name entropy and exclusive-create behavior. ([#1085](https://github.com/openclaw/fs-safe/pull/1085))
24
+
25
+ - **File locks:** restore custom stale-policy diagnostics for empty or malformed owner records while keeping unverifiable owners ineligible for automatic removal. ([#1079](https://github.com/openclaw/fs-safe/pull/1079))
26
+
27
+ - **Root file locks:** restore POSIX acquisition I/O errors as `FsSafeError` with the existing `invalid-path` code and original cause; retain raw-lock and Windows fallback error identity. Retry verified concurrent publication handoffs to avoid spurious `path-mismatch` and `outside-workspace` failures. ([#1081](https://github.com/openclaw/fs-safe/pull/1081), [#1087](https://github.com/openclaw/fs-safe/pull/1087))
28
+
29
+ - **DrvFS opt-in writes:** skip recovery preparation on known non-9p filesystems, caching only negative observations so later writes add no filesystem calls while recovery keeps full mount and identity verification. ([#1080](https://github.com/openclaw/fs-safe/pull/1080))
30
+
31
+ ## 0.28.0 - 2026-11-07
32
+
33
+ **Highlights:** Crash-safe lock publication and working writes on Docker Desktop Windows bind mounts through the new opt-in `allowDrvfsRenameRecovery`. ([#1066](https://github.com/openclaw/fs-safe/pull/1066), [#1076](https://github.com/openclaw/fs-safe/pull/1076), [#1074](https://github.com/openclaw/fs-safe/pull/1074))
34
+
35
+ ### Features
36
+
37
+ - **Atomic writes:** add the explicit, off-by-default `allowDrvfsRenameRecovery` option for verified DrvFS mounts, with documented residual inode-reuse risk. ([#1074](https://github.com/openclaw/fs-safe/pull/1074))
38
+
39
+ - **Temp workspaces:** add opt-in `trustedWritableAncestors` for externally isolated deployments. Exact named ancestors may be group/world writable while ownership, private-directory permissions, and path-integrity checks remain enforced; defaults stay strict. Using the exception emits a path-free `FS_SAFE_TRUSTED_WRITABLE_ANCESTOR` warning once per process. Thanks @Kimiyu-186. ([#1073](https://github.com/openclaw/fs-safe/pull/1073))
40
+
41
+ ### Fixes
42
+
43
+ - **DrvFS publication:** recover files hidden until the last descriptor closes on verified Windows-drive mounts, retaining exact identity, ownership, mode, size, link-count, parent, and available content checks. Thanks @om49967588 for the report and @lswang9 for the probes. ([#1074](https://github.com/openclaw/fs-safe/pull/1074))
44
+
45
+ - **File locks:** stage and sync complete owner records before exclusive publication; retain mutually exclusive create-and-write on mounts without no-replace rename or hardlinks, where a crash can leave an empty or partial lock requiring offline recovery. Existing unverifiable locks remain untouched. Thanks @chrislro. ([#1066](https://github.com/openclaw/fs-safe/pull/1066), [#1076](https://github.com/openclaw/fs-safe/pull/1076))
46
+
47
+ - **Windows batch reads:** retain the native descriptor's matching closer through admission and return it as optional `close()` on successful reads; use it to avoid Worker descriptor warnings. Thanks @shenghu7358 for the OpenClaw report. ([#1071](https://github.com/openclaw/fs-safe/pull/1071))
48
+
49
+ ## 0.27.2 - 2026-11-05
50
+
51
+ **Highlights:** POSIX reads stay responsive on slow storage; Windows public-path inspection keeps TrustedInstaller trust narrow, and release verification dependencies include denial-of-service fixes.
52
+
53
+ ### Fixes
54
+
55
+ - **POSIX reads:** keep root acquisition, root-file opens, and Root read admission off the JavaScript thread while preserving pinned-descriptor identity and final root/path checks; retain Windows and custom synchronous adapter behavior.
56
+ - **Windows permissions:** trust exact TrustedInstaller ownership and serviced read-only sources for public inspection while rejecting servicing write grants on user-owned or user-writable profiles and retaining strict private-file checks. Thanks @paulcam206.
57
+ - **Temporary filenames:** preserve safe Unicode names, including CJK text and accents, while retaining path/control filtering, Windows device protection, and portable byte limits. Thanks @beeven.
58
+ - **Release verification:** patch denial-of-service issues in the provenance verifier's dependency chain.
59
+
3
60
  ## 0.27.1 - 2026-10-31
4
61
 
5
62
  **Highlights:** Native POSIX staged file creation, atomic publication, small-buffer writes, path-prefix canonicalization, and awaited root-path traversal no longer block the JavaScript thread, so slow storage cannot stall the event loop. ([#1052](https://github.com/openclaw/fs-safe/pull/1052), [#1053](https://github.com/openclaw/fs-safe/pull/1053), [#1054](https://github.com/openclaw/fs-safe/pull/1054))
@@ -221,6 +221,11 @@ mutation authority, and publication receipts. Retained lifecycles have separate
221
221
  contracts: [staged files](docs/staged-file.md), [entry publication](docs/entry-publication.md),
222
222
  and [staged symlinks](docs/staged-symlink.md).
223
223
 
224
+ For affected WSL/Docker Windows-drive mounts, explicitly opt into
225
+ [`allowDrvfsRenameRecovery`](docs/atomic.md#drvfs-hidden-rename-recovery). It is
226
+ off by default, requires descriptor-verified DrvFS mount evidence, and gives up
227
+ continuous inode retention during recovery; read the documented reuse risk.
228
+
224
229
  For a shared parent, pass `dirMode: "preserve"`: verified existing directories
225
230
  keep their permissions without chmod, while directories created by the write
226
231
  finish at `0o700`. Omission retains the existing parent-tightening default.
@@ -266,6 +271,7 @@ See [JSON stores](docs/json-store.md) for single-path stores and update semantic
266
271
  [File locks](docs/sidecar-lock.md) for coordination and stale-lock recovery.
267
272
  The store subpath also provides [durable JSON queues](docs/store.md#durable-json-queues).
268
273
  Use [temp workspaces](docs/temp.md) for scoped scratch files and cleanup policies.
274
+ Externally isolated deployments can opt into [exact trusted writable ancestors](docs/temp.md#externally-isolated-ancestors); private-directory checks remain strict.
269
275
 
270
276
  ## Exact file comparison
271
277
 
@@ -40,6 +40,7 @@ export declare class AtomicFile {
40
40
  syncBestEffort(): Procedure<void>;
41
41
  chmod(mode: number): void | Promise<void>;
42
42
  writeFile(data: string | Uint8Array, throughModule?: boolean): void | Promise<void>;
43
+ readFileBounded(maxBytes: number): Procedure<Buffer>;
43
44
  readFile(sizeHint?: number): Procedure<Buffer>;
44
45
  read(buffer: Buffer, offset: number, length: number, position: number | null): number | Promise<{
45
46
  bytesRead: number;
@@ -211,6 +211,16 @@ export class AtomicFile {
211
211
  return this.resource.writeFile(data);
212
212
  }
213
213
  }
214
+ *readFileBounded(maxBytes) {
215
+ if (typeof this.resource !== "number")
216
+ return yield* wait(readFileHandleBounded(this.resource, maxBytes));
217
+ let position = 0;
218
+ return readBoundedSync(maxBytes, (buffer, length) => {
219
+ const bytes = this.io.syncFs.readSync(this.resource, buffer, 0, length, position);
220
+ position += bytes;
221
+ return bytes;
222
+ });
223
+ }
214
224
  *readFile(sizeHint) {
215
225
  if (typeof this.resource !== "number")
216
226
  return yield* wait(readFileHandleBounded(this.resource, Infinity));
@@ -1,7 +1,7 @@
1
1
  import type { FileHandle } from "node:fs/promises";
2
2
  type ReadableFileHandle = Pick<FileHandle, "read">;
3
3
  export declare function readBoundedAsync(maxBytes: number, readChunk: (scratch: Buffer, length: number) => Promise<number>, options?: {
4
- observeRegularFileSize?: () => number | undefined;
4
+ observeRegularFileSize?: () => number | undefined | Promise<number | undefined>;
5
5
  initialSize?: number;
6
6
  createLimitError?: () => Error;
7
7
  /** Keep the result outside Node's shared small-buffer allocation pool. */
@@ -44,7 +44,7 @@ export async function readBoundedAsync(maxBytes, readChunk, options = {}) {
44
44
  let total = 0;
45
45
  const { observeRegularFileSize, createLimitError } = options;
46
46
  const allocate = options.unpooled ? Buffer.allocUnsafeSlow : undefined;
47
- const size = options.initialSize ?? observeRegularFileSize?.();
47
+ const size = options.initialSize ?? await observeRegularFileSize?.();
48
48
  let buffer = size === undefined ? createScratchBuffer(maxBytes, allocate) : createInitialBuffer(maxBytes, size, allocate);
49
49
  if (size !== undefined) {
50
50
  const bytesRead = await readChunk(buffer, buffer.length);
@@ -52,7 +52,7 @@ export async function readBoundedAsync(maxBytes, readChunk, options = {}) {
52
52
  return finishReadBuffer(buffer, 0, allocate);
53
53
  // Short reads can occur before EOF. Only use the size shortcut on this
54
54
  // initial read; virtual files can report zero or stale sizes thereafter.
55
- const currentSize = bytesRead < buffer.length ? observeRegularFileSize?.() : undefined;
55
+ const currentSize = bytesRead < buffer.length ? await observeRegularFileSize?.() : undefined;
56
56
  total = addReadBytes(total, bytesRead, maxBytes, createLimitError);
57
57
  if (currentSize !== undefined && currentSize > 0 && bytesRead >= currentSize)
58
58
  return finishReadBuffer(buffer, total, allocate);
@@ -83,7 +83,7 @@ export function readFileHandleBoundedWithSize(handle, maxBytes, initialSize) {
83
83
  return (await handle.read(scratch, 0, length, null)).bytesRead;
84
84
  }, {
85
85
  initialSize,
86
- observeRegularFileSize: fd === undefined ? undefined : () => regularFileSize(fd),
86
+ observeRegularFileSize: fd === undefined ? undefined : () => regularFileSizeAsync(fd),
87
87
  });
88
88
  }
89
89
  function regularFileSize(fd) {
@@ -97,6 +97,17 @@ function regularFileSize(fd) {
97
97
  return undefined;
98
98
  }
99
99
  }
100
+ async function regularFileSizeAsync(fd) {
101
+ try {
102
+ const stat = await new Promise((resolve, reject) => {
103
+ fs.fstat(fd, (error, value) => error ? reject(error) : resolve(value));
104
+ });
105
+ return stat.isFile() && Number.isSafeInteger(stat.size) && stat.size >= 0 ? stat.size : undefined;
106
+ }
107
+ catch {
108
+ return undefined;
109
+ }
110
+ }
100
111
  function readDescriptorChunk(fd, scratch, length) {
101
112
  return new Promise((resolve, reject) => {
102
113
  fs.read(fd, scratch, 0, length, null, (error, bytesRead) => {
@@ -113,7 +124,7 @@ export async function readFileDescriptorBounded(fd, maxBytes) {
113
124
  normalizeMaxBytes(maxBytes);
114
125
  return await readBoundedAsync(maxBytes, async (scratch, length) => {
115
126
  return await readDescriptorChunk(fd, scratch, length);
116
- }, { observeRegularFileSize: () => regularFileSize(fd) });
127
+ }, { observeRegularFileSize: () => regularFileSizeAsync(fd) });
117
128
  }
118
129
  export function readBoundedSync(maxBytes, readChunk, options = {}) {
119
130
  normalizeMaxBytes(maxBytes);
@@ -1,8 +1,9 @@
1
1
  import fsSync from "node:fs";
2
+ import fs from "node:fs/promises";
2
3
  import path from "node:path";
3
4
  import { FsSafeError } from "./errors.js";
4
5
  import { hasSafeFileIdentity, sameFileIdentity } from "./file-identity.js";
5
- import { inspectFileIdentitySync } from "./strict-file-identity.js";
6
+ import { inspectFileIdentity, inspectFileIdentitySync } from "./strict-file-identity.js";
6
7
  import { isNotFoundPathError } from "./path.js";
7
8
  import { directoryComponentNotDirectoryError } from "./root-errors.js";
8
9
  import { assertNoWindowsPathAlias, pathForWindowsFilesystem, resolvePathPreservingWindowsRoot, } from "./windows-path-alias.js";
@@ -116,7 +117,15 @@ export async function createNearestExistingDirectoryGuard(rootReal, targetPath,
116
117
  }
117
118
  // Recovery receipts must retain every identity bit, including on Windows.
118
119
  export async function inspectDirectoryIdentity(dir, expected) {
119
- return inspectDirectoryIdentitySync(dir, expected);
120
+ if (process.platform === "win32")
121
+ return inspectDirectoryIdentitySync(dir, expected);
122
+ const operationPath = directoryOperationPath(dir);
123
+ return inspectFileIdentity(async () => {
124
+ const stat = await fs.lstat(operationPath, { bigint: true });
125
+ if (stat.isSymbolicLink() || !stat.isDirectory())
126
+ throw directoryComponentNotDirectoryError();
127
+ return stat;
128
+ }, expected);
120
129
  }
121
130
  function directoryOperationPath(dir) {
122
131
  assertNoWindowsPathAlias(dir, "filesystem");
@@ -0,0 +1,6 @@
1
+ /** Retained only for an explicitly enabled operation; no new default-path I/O. */
2
+ export declare function retainDrvfsParent(directory: string, dev?: bigint, filesystemChecked?: boolean): {
3
+ fd: number;
4
+ assertCurrent: () => void;
5
+ close(): void;
6
+ } | undefined;
@@ -0,0 +1,38 @@
1
+ import fs, {} from "node:fs";
2
+ import { assertDirectoryGuard, captureDirectoryGuard } from "./directory-guard.js";
3
+ import { openStagedDirectory, assertStagedDirectoryCurrent } from "./staged-directory.js";
4
+ import { inspectFileIdentitySync } from "./strict-file-identity.js";
5
+ import { mayPrepareDrvfsRecoveryAtFd, shouldPrepareDrvfsRecovery } from "./publication-recovery.js";
6
+ /** Retained only for an explicitly enabled operation; no new default-path I/O. */
7
+ export function retainDrvfsParent(directory, dev, filesystemChecked = false) {
8
+ if (!shouldPrepareDrvfsRecovery(true, dev))
9
+ return undefined;
10
+ let parent;
11
+ try {
12
+ // Resolve through the filesystem first: lexical normalization of link/..
13
+ // can select a different directory (and therefore a different mount).
14
+ const guard = captureDirectoryGuard(directory, "native", { bigint: true });
15
+ parent = openStagedDirectory(guard.realPath);
16
+ const retained = parent;
17
+ const assertCurrent = () => {
18
+ inspectFileIdentitySync(() => fs.fstatSync(retained.fd, { bigint: true }), guard.stat);
19
+ assertDirectoryGuard(guard, "native");
20
+ assertStagedDirectoryCurrent(retained.receipt);
21
+ };
22
+ assertCurrent();
23
+ if (!filesystemChecked && !mayPrepareDrvfsRecoveryAtFd(retained.fd, retained.receipt.identity.dev)) {
24
+ parent = undefined;
25
+ fs.closeSync(retained.fd);
26
+ return undefined;
27
+ }
28
+ return { fd: retained.fd, assertCurrent, close() { fs.closeSync(retained.fd); } };
29
+ }
30
+ catch {
31
+ if (parent)
32
+ try {
33
+ fs.closeSync(parent.fd);
34
+ }
35
+ catch { /* Preserve strict fallback. */ }
36
+ return undefined;
37
+ }
38
+ }
@@ -15,7 +15,7 @@ export declare class SyncLockAcquisition {
15
15
  release(): void;
16
16
  run<T>(callback: () => T): T;
17
17
  waitForRetry(): void;
18
- retryDenial(error: unknown): boolean;
18
+ retryDenial(error: unknown, openedPath?: string): boolean;
19
19
  monitor(held: {
20
20
  timer?: NodeJS.Timeout;
21
21
  }, handle: FileLockSyncHandle, callback: ((info: SidecarLockCompromisedInfo) => void) | undefined, interval: number | undefined, receiver: object, recordTimer?: (timer: NodeJS.Timeout) => void): void;
@@ -57,8 +57,8 @@ export class SyncLockAcquisition {
57
57
  sleepSync(delay);
58
58
  this.#attempt += 1;
59
59
  }
60
- retryDenial(error) {
61
- if (!isTransientLockFileDenial(error, this.lockPath) ||
60
+ retryDenial(error, openedPath = this.lockPath) {
61
+ if (!isTransientLockFileDenial(error, openedPath) ||
62
62
  ++this.#transientDenials > maxTransientLockDenials)
63
63
  return false;
64
64
  try {
@@ -1,3 +1,4 @@
1
+ import { isIncompleteSidecarLockRecord } from "./sidecar-lock-reclaim.js";
1
2
  import fs from "node:fs";
2
3
  import path from "node:path";
3
4
  import { FsSafeError } from "./errors.js";
@@ -152,7 +153,7 @@ export function acquireFileLockSyncWithRoot(targetPath, inputOptions, lockRoot)
152
153
  let unpublishedTimer;
153
154
  let lockFileCreateOpenFailure;
154
155
  try {
155
- const created = createFileLockSyncRootFile(lockRootPath, {
156
+ const created = createFileLockSyncRootFile(lockRootPath, raw, {
156
157
  assertBeforeOpen: () => {
157
158
  acquisition.assert();
158
159
  if (ownedReclaimGuard)
@@ -160,14 +161,12 @@ export function acquireFileLockSyncWithRoot(targetPath, inputOptions, lockRoot)
160
161
  if (currentTargetHolder() !== undefined)
161
162
  throw new FileLockSyncRootArbitrationCollision();
162
163
  },
163
- onOpenFailure: (error) => {
164
- lockFileCreateOpenFailure = { error };
164
+ onOpenFailure: (error, pathname = lockPath) => {
165
+ lockFileCreateOpenFailure = { error, pathname };
165
166
  },
166
167
  });
167
168
  fd = created.fd;
168
169
  rootReceipt = created.receipt;
169
- fs.writeFileSync(fd, raw, "utf8");
170
- fs.fsyncSync(fd);
171
170
  const snapshot = {
172
171
  raw,
173
172
  payload,
@@ -225,9 +224,10 @@ export function acquireFileLockSyncWithRoot(targetPath, inputOptions, lockRoot)
225
224
  }
226
225
  const fromLockFileOpen = lockFileCreateOpenFailure !== undefined &&
227
226
  lockFileCreateOpenFailure.error === error;
228
- if (fromLockFileOpen && acquisition.retryDenial(error))
227
+ if (fromLockFileOpen && acquisition.retryDenial(error, lockFileCreateOpenFailure.pathname))
229
228
  continue;
230
- if (!fromLockFileOpen || error.code !== "EEXIST")
229
+ if (!fromLockFileOpen || lockFileCreateOpenFailure.pathname !== lockPath ||
230
+ error.code !== "EEXIST")
231
231
  throw error;
232
232
  if (ownedReclaimGuard) {
233
233
  releaseReclaimGuard();
@@ -269,6 +269,8 @@ export function acquireFileLockSyncWithRoot(targetPath, inputOptions, lockRoot)
269
269
  continue;
270
270
  }
271
271
  const snapshot = current.snapshot;
272
+ // An incomplete owner can still be writing; never reclaim it by age.
273
+ const incomplete = (!options.parsePayload && snapshot.payload === null) || isIncompleteSidecarLockRecord(snapshot.raw);
272
274
  const nowMs = Date.now();
273
275
  let reclaim;
274
276
  if (options.shouldReclaim) {
@@ -287,9 +289,12 @@ export function acquireFileLockSyncWithRoot(targetPath, inputOptions, lockRoot)
287
289
  }
288
290
  }
289
291
  else {
290
- reclaim = defaultSidecarLockShouldReclaim(snapshot, options.staleMs, nowMs);
292
+ reclaim = !incomplete && defaultSidecarLockShouldReclaim(snapshot, options.staleMs, nowMs);
291
293
  }
292
294
  if (reclaim) {
295
+ // Policy may diagnose an incomplete record, but can never authorize its removal.
296
+ if (incomplete)
297
+ throw sidecarLockStale(lockPath, normalizedTargetPath);
293
298
  if (options.staleRecovery === "remove-if-unchanged" &&
294
299
  snapshot.raw !== undefined &&
295
300
  options.shouldRemoveStaleLock) {
@@ -9,6 +9,7 @@ import { assertRootIdentityCurrentSync } from "./root-context.js";
9
9
  import { hardlinkedPathNotAllowedError } from "./root-errors.js";
10
10
  import { resolveReadOpenFlags } from "./read-open-flags.js";
11
11
  import { realpathSync } from "./realpath.js";
12
+ import { sidecarPublicationPending } from "./sidecar-lock-staging.js";
12
13
  import { sidecarLockSnapshotMatches, } from "./sidecar-lock-reclaim.js";
13
14
  import { inspectFileIdentitySync } from "./strict-file-identity.js";
14
15
  import { createSuppressedError } from "./suppressed-error.js";
@@ -90,6 +91,10 @@ export function readFileLockSyncRootSnapshot(pathAuthority, options = {}) {
90
91
  return missingAfterCurrentRead(pathAuthority, expectedReceipt);
91
92
  throw error;
92
93
  }
94
+ if (!expectedReceipt && before.nlink === 2n && sidecarPublicationPending(pathAuthority.path)) {
95
+ assertFreshPathCurrent(pathAuthority);
96
+ return null;
97
+ }
93
98
  assertRegularFile(before, pathAuthority.authority.hardlinks);
94
99
  const parent = expectedReceipt?.parent ?? observeDirectory(path.dirname(pathAuthority.path));
95
100
  let fd;
@@ -122,6 +127,10 @@ export function readFileLockSyncRootSnapshot(pathAuthority, options = {}) {
122
127
  }
123
128
  throw error;
124
129
  }
130
+ if (!expectedReceipt && opened.nlink === 2n && sidecarPublicationPending(pathAuthority.path)) {
131
+ assertFreshPathCurrent(pathAuthority);
132
+ return null;
133
+ }
125
134
  assertRegularFile(opened, pathAuthority.authority.hardlinks);
126
135
  const raw = readFileDescriptorBoundedSync(fd, MAX_SIDECAR_LOCK_PAYLOAD_BYTES).toString("utf8");
127
136
  let after;
@@ -142,6 +151,10 @@ export function readFileLockSyncRootSnapshot(pathAuthority, options = {}) {
142
151
  }
143
152
  throw error;
144
153
  }
154
+ if (!expectedReceipt && after.nlink === 2n && sidecarPublicationPending(pathAuthority.path)) {
155
+ assertFreshPathCurrent(pathAuthority);
156
+ return null;
157
+ }
145
158
  assertRegularFile(after, pathAuthority.authority.hardlinks);
146
159
  const stat = fs.fstatSync(fd, { bigint: true });
147
160
  if (expectedReceipt) {
@@ -1,9 +1,9 @@
1
1
  import { type SidecarLockSnapshot } from "./sidecar-lock-reclaim.js";
2
2
  import { type FileLockSyncRootPath } from "./file-lock-sync-root.js";
3
3
  import { type FileLockSyncRootDirectoryReceipt, type FileLockSyncRootFileReceipt } from "./file-lock-sync-root-io.js";
4
- export declare function createFileLockSyncRootFile(pathAuthority: FileLockSyncRootPath, options: {
4
+ export declare function createFileLockSyncRootFile(pathAuthority: FileLockSyncRootPath, raw: string, options: {
5
5
  assertBeforeOpen: () => void;
6
- onOpenFailure: (error: unknown) => void;
6
+ onOpenFailure: (error: unknown, pathname?: string) => void;
7
7
  }): {
8
8
  fd: number;
9
9
  receipt: FileLockSyncRootFileReceipt;
@@ -1,5 +1,6 @@
1
1
  import fs, {} from "node:fs";
2
- import { assertExclusiveCreateLeaf } from "./exclusive-create.js";
2
+ import { createSidecarFileSync } from "./sidecar-lock-publication.js";
3
+ import { sidecarPublicationPending } from "./sidecar-lock-staging.js";
3
4
  import path from "node:path";
4
5
  import { inspectDirectoryIdentitySync } from "./directory-guard.js";
5
6
  import { FsSafeError } from "./errors.js";
@@ -77,7 +78,7 @@ function ensureParent(pathAuthority) {
77
78
  assertDirectoryCurrent(currentReceipt);
78
79
  return currentReceipt;
79
80
  }
80
- export function createFileLockSyncRootFile(pathAuthority, options) {
81
+ export function createFileLockSyncRootFile(pathAuthority, raw, options) {
81
82
  const parent = ensureParent(pathAuthority);
82
83
  if (invokeFileLockSyncRootMutationAuthority(pathAuthority.authority)) {
83
84
  assertFileLockSyncRootResolvedPathCurrent(pathAuthority);
@@ -89,25 +90,29 @@ export function createFileLockSyncRootFile(pathAuthority, options) {
89
90
  let fd;
90
91
  let receipt;
91
92
  try {
92
- options.assertBeforeOpen();
93
- try {
94
- assertExclusiveCreateLeaf(pathForWindowsFilesystem(pathAuthority.path));
95
- }
96
- catch (error) {
97
- if (error.code === "EEXIST")
98
- options.onOpenFailure(error);
99
- throw error;
100
- }
101
- try {
102
- fd = fs.openSync(pathForWindowsFilesystem(pathAuthority.path), fs.constants.O_WRONLY | fs.constants.O_CREAT | fs.constants.O_EXCL | noFollow, 0o600);
103
- }
104
- catch (error) {
105
- options.onOpenFailure(error);
106
- throw error;
107
- }
108
- const opened = inspectFileIdentitySync(() => fs.fstatSync(fd, { bigint: true }));
109
- assertRegularFile(opened, pathAuthority.authority.hardlinks);
93
+ const assertCurrent = () => {
94
+ assertFileLockSyncRootResolvedPathCurrent(pathAuthority);
95
+ assertRetainedParentCurrent(pathAuthority, parent);
96
+ options.assertBeforeOpen();
97
+ };
98
+ assertCurrent();
99
+ const created = createSidecarFileSync(pathForWindowsFilesystem(pathAuthority.path), raw, pathname => {
100
+ assertCurrent();
101
+ try {
102
+ return fs.openSync(pathname, fs.constants.O_WRONLY | fs.constants.O_CREAT | fs.constants.O_EXCL | noFollow, 0o600);
103
+ }
104
+ catch (error) {
105
+ options.onOpenFailure(error, pathname);
106
+ throw error;
107
+ }
108
+ }, {
109
+ assertCurrent, onConflict: options.onOpenFailure, requireExactIdentity: true,
110
+ assertCleanupCandidate: candidate => assertFileLockSyncRootMutationAllowed(candidate, pathAuthority.authority.denyMutations),
111
+ });
112
+ fd = created.fd;
113
+ const opened = created.identity;
110
114
  receipt = Object.freeze({ identity: exactFileIdentity(opened), parent });
115
+ assertRegularFile(opened, pathAuthority.authority.hardlinks);
111
116
  if (!fileReceiptCurrentAfterParentCheck(pathAuthority, receipt)) {
112
117
  throw new FsSafeError("path-mismatch", "created sidecar lock changed before admission");
113
118
  }
@@ -167,10 +172,10 @@ export function removeFileLockSyncRootFile(pathAuthority, receipt, expected, ass
167
172
  return true;
168
173
  throw error;
169
174
  }
170
- assertRegularFile(successorStat, pathAuthority.authority.hardlinks);
171
175
  assertRetainedParentCurrent(pathAuthority, receipt.parent);
172
176
  if (!sameExactIdentity(exactFileIdentity(successorStat), receipt.identity))
173
177
  return true;
178
+ assertRegularFile(successorStat, pathAuthority.authority.hardlinks);
174
179
  if (expected) {
175
180
  const successor = readFileLockSyncRootSnapshot(pathAuthority);
176
181
  assertRetainedParentCurrent(pathAuthority, receipt.parent);
@@ -194,10 +199,10 @@ export function removeFileLockSyncRootFile(pathAuthority, receipt, expected, ass
194
199
  }
195
200
  throw error;
196
201
  }
197
- assertRegularFile(current, pathAuthority.authority.hardlinks);
198
202
  assertRetainedParentCurrent(pathAuthority, receipt.parent);
199
203
  if (!sameExactIdentity(exactFileIdentity(current), receipt.identity))
200
204
  return true;
205
+ assertRegularFile(current, pathAuthority.authority.hardlinks);
201
206
  }
202
207
  }
203
208
  throw new FsSafeError("path-mismatch", "sidecar lock was replaced during removal");
@@ -221,12 +226,17 @@ export function fileLockSyncRootGuardExists(pathAuthority) {
221
226
  if (stat.isSymbolicLink() || (!stat.isDirectory() && !stat.isFile())) {
222
227
  throw directoryComponentNotDirectoryError();
223
228
  }
229
+ const assertGuardFile = (current) => {
230
+ if (current.nlink !== 2n || !sidecarPublicationPending(pathAuthority.path)) {
231
+ assertRegularFile(current, pathAuthority.authority.hardlinks);
232
+ }
233
+ };
224
234
  if (stat.isFile())
225
- assertRegularFile(stat, pathAuthority.authority.hardlinks);
235
+ assertGuardFile(stat);
226
236
  const parent = observeDirectory(path.dirname(pathAuthority.path));
227
237
  if (stat.isFile()) {
228
238
  const current = inspectFileIdentitySync(() => fs.lstatSync(pathForWindowsFilesystem(pathAuthority.path), { bigint: true }), exactFileIdentity(stat));
229
- assertRegularFile(current, pathAuthority.authority.hardlinks);
239
+ assertGuardFile(current);
230
240
  }
231
241
  else {
232
242
  inspectDirectoryIdentitySync(pathAuthority.path, exactFileIdentity(stat));
@@ -1,5 +1,5 @@
1
1
  import fs from "node:fs";
2
- import { parseSidecarLockSnapshot, readSidecarLockRawSnapshotSync, removeSidecarLockIfUnchangedSync, } from "./sidecar-lock-reclaim.js";
2
+ import { parseSidecarLockSnapshot, isIncompleteSidecarLockRecord, readSidecarLockRawSnapshotSync, removeSidecarLockIfUnchangedSync, } from "./sidecar-lock-reclaim.js";
3
3
  import { assertSynchronousCallbackResult } from "./mutation-authority.js";
4
4
  import { defaultSidecarLockShouldReclaim, sidecarLockStale } from "./sidecar-lock-policy.js";
5
5
  /** Handle one exclusive-create conflict without surrendering canonical admission. */
@@ -90,10 +90,12 @@ export function handleSyncStaleAdmission(acquisition, params) {
90
90
  return;
91
91
  throw error;
92
92
  }
93
+ // An incomplete owner can still be writing; age is not liveness evidence.
93
94
  if (!snapshot) {
94
95
  acquisition.waitForRetry();
95
96
  return;
96
97
  }
98
+ const incomplete = (!params.parsePayload && snapshot.payload === null) || isIncompleteSidecarLockRecord(snapshot.raw);
97
99
  const nowMs = Date.now();
98
100
  let reclaim;
99
101
  try {
@@ -108,7 +110,7 @@ export function handleSyncStaleAdmission(acquisition, params) {
108
110
  nowMs,
109
111
  heldByThisProcess: false,
110
112
  }])
111
- : defaultSidecarLockShouldReclaim(snapshot, params.staleMs, nowMs);
113
+ : !incomplete && defaultSidecarLockShouldReclaim(snapshot, params.staleMs, nowMs);
112
114
  assertSynchronousCallbackResult(reclaim, "shouldReclaim");
113
115
  }
114
116
  finally {
@@ -124,6 +126,9 @@ export function handleSyncStaleAdmission(acquisition, params) {
124
126
  acquisition.waitForRetry();
125
127
  return;
126
128
  }
129
+ // Policy may diagnose an incomplete record, but can never authorize its removal.
130
+ if (incomplete)
131
+ throw sidecarLockStale(acquisition.lockPath, acquisition.normalizedTargetPath);
127
132
  if (params.staleRecovery === "remove-if-unchanged" &&
128
133
  snapshot.raw !== undefined &&
129
134
  stale.shouldRemove !== undefined) {
@@ -1,5 +1,5 @@
1
1
  import fs from "node:fs";
2
- import { assertExclusiveCreateLeaf } from "./exclusive-create.js";
2
+ import { createSidecarFileSync } from "./sidecar-lock-publication.js";
3
3
  import { acquireFileLockSyncWithRoot } from "./file-lock-sync-root-acquire.js";
4
4
  import { withSyncHeldLockHandle } from "./file-lock-sync-root-held.js";
5
5
  import path from "node:path";
@@ -230,34 +230,34 @@ export function acquireFileLockSync(targetPath, options) {
230
230
  }
231
231
  }
232
232
  let lockFileCreateDenied = false;
233
+ let createOpenPath = lockPath;
233
234
  let exclusiveCreateConflict = false;
234
235
  try {
235
236
  const noFollow = process.platform !== "win32" && typeof fs.constants.O_NOFOLLOW === "number"
236
237
  ? fs.constants.O_NOFOLLOW
237
238
  : 0;
238
- try {
239
- assertExclusiveCreateLeaf(lockPath);
240
- }
241
- catch (error) {
242
- exclusiveCreateConflict = error.code === "EEXIST";
243
- throw error;
244
- }
245
- try {
246
- fd = fs.openSync(lockPath, fs.constants.O_WRONLY | fs.constants.O_CREAT | fs.constants.O_EXCL | noFollow, 0o600);
247
- }
248
- catch (error) {
249
- lockFileCreateDenied = isTransientLockFileDenial(error, lockPath);
250
- exclusiveCreateConflict = error.code === "EEXIST";
251
- throw error;
252
- }
253
- fs.writeFileSync(fd, raw, "utf8");
254
- fs.fsyncSync(fd);
239
+ const failedOpen = (error, pathname = lockPath) => {
240
+ createOpenPath = pathname;
241
+ lockFileCreateDenied = isTransientLockFileDenial(error, pathname);
242
+ exclusiveCreateConflict = pathname === lockPath && error.code === "EEXIST";
243
+ };
244
+ const created = createSidecarFileSync(lockPath, raw, pathname => {
245
+ try {
246
+ return fs.openSync(pathname, fs.constants.O_WRONLY | fs.constants.O_CREAT | fs.constants.O_EXCL | noFollow, 0o600);
247
+ }
248
+ catch (error) {
249
+ failedOpen(error, pathname);
250
+ throw error;
251
+ }
252
+ }, { onConflict: failedOpen });
253
+ fd = created.fd;
255
254
  createdSnapshot = {
256
255
  raw,
257
256
  payload,
258
- stat: fs.fstatSync(fd, { bigint: true }),
257
+ stat: created.identity,
259
258
  ownershipToken,
260
259
  };
260
+ createdSnapshot.stat = fs.fstatSync(fd, { bigint: true });
261
261
  createdHeld = {
262
262
  fd,
263
263
  lockPath,
@@ -321,7 +321,7 @@ export function acquireFileLockSync(targetPath, options) {
321
321
  acquisition.waitForRetry();
322
322
  continue;
323
323
  }
324
- if (acquisition.retryDenial(error))
324
+ if (acquisition.retryDenial(error, createOpenPath))
325
325
  continue;
326
326
  throw error;
327
327
  }
@@ -1,7 +1,18 @@
1
- type FailureKind = "identity" | "resolution" | `open:${string}` | `exclusive-create:${string}` | `unlinked:${string}` | `changed:${string}` | `stat-leaf-missing:${string}` | `stat-leaf-changed:${string}`;
1
+ type FailureKind = "hardlink" | "identity" | "resolution" | `open:${string}` | `sidecar-create-denial:${string}` | `exclusive-create:${string}` | `unlinked:${string}` | `changed:${string}` | `linked-change:${string}` | `stat-leaf-missing:${string}` | `stat-leaf-changed:${string}`;
2
+ type ObservationContext = {
3
+ failures: Map<unknown, Set<FailureKind>>;
4
+ publicationPending?: (filePath: string, identity: {
5
+ dev: bigint;
6
+ ino: bigint;
7
+ }) => Promise<boolean>;
8
+ };
2
9
  export declare function recordFileObservationFailure(error: unknown, kind: FailureKind): void;
3
10
  export declare function isFileObservationFailure(error: unknown, kind: FailureKind): boolean;
4
- export declare function fileObservation(): {
11
+ export declare function observedFilePublicationPending(filePath: string, identity: {
12
+ dev: bigint;
13
+ ino: bigint;
14
+ }): Promise<boolean>;
15
+ export declare function fileObservation(options?: Pick<ObservationContext, "publicationPending">): {
5
16
  run<T>(operation: () => T): T;
6
17
  has(error: unknown, kind: FailureKind): boolean;
7
18
  };