@openclaw/matrix 2026.11.11 → 2026.12.1-beta.2
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.
- package/dist/.setup/{approval-handler.runtime-CCGCnRgz.mjs → approval-handler.runtime-BfY586xJ.mjs} +4 -4
- package/dist/.setup/{channel-BEgolhUJ.mjs → channel-Cc7auxIF.mjs} +8 -8
- package/dist/.setup/{channel.runtime-_NMfiRJl.mjs → channel.runtime-B6ZmWLDZ.mjs} +5 -5
- package/dist/.setup/{channel.setup-B7r4NCcE.mjs → channel.setup-D9-chyNP.mjs} +2 -2
- package/dist/.setup/{cli-CyjnAIzU.mjs → cli-BrTpL9JI.mjs} +7 -7
- package/dist/.setup/{cli-metadata-DNeLBXHC.mjs → cli-metadata-R7WyIFzA.mjs} +1 -1
- package/dist/.setup/{client-BVgnwwz0.mjs → client-BmxOI9-U.mjs} +2 -2
- package/dist/.setup/{client-gch0wggI.mjs → client-DOb_5cJm.mjs} +2 -2
- package/dist/.setup/{client-bootstrap-CHs5OQ1Z.mjs → client-bootstrap-BwDbzw5i.mjs} +1 -1
- package/dist/.setup/{create-client-mnjEWdZV.mjs → create-client-BQpMgtl2.mjs} +2 -2
- package/dist/.setup/{crypto-runtime-tZ95jwNO.mjs → crypto-runtime-CStae6zK.mjs} +1 -1
- package/dist/.setup/{direct-management-D59C1WO-.mjs → direct-management-Bm4vd-k1.mjs} +1 -1
- package/dist/.setup/{directory-live-CQNKUJJx.mjs → directory-live-DRGF3zFp.mjs} +1 -1
- package/dist/.setup/{draft-stream-DI_6HWy4.mjs → draft-stream-DpSefQTK.mjs} +2 -2
- package/dist/.setup/{exec-approvals-B23spbVI.mjs → exec-approvals-CTkGLt3Z.mjs} +2 -2
- package/dist/.setup/{messages-VnZ4u4iq.mjs → messages-DjmI7l5t.mjs} +3 -3
- package/dist/.setup/{monitor-wbUkxHXK.mjs → monitor-HjyjGlys.mjs} +18 -18
- package/dist/.setup/{onboarding-B51d5a6R.mjs → onboarding-BPkKv4dw.mjs} +3 -3
- package/dist/.setup/{outbound-D8rgFTRa.mjs → outbound-CthMgcxZ.mjs} +2 -2
- package/dist/.setup/{profile-update-DAQFPf4L.mjs → profile-update-myTQ_w_e.mjs} +3 -3
- package/dist/.setup/{reaction-events-CZlbNkx_.mjs → reaction-events-C22fpTeK.mjs} +5 -5
- package/dist/.setup/{resolve-targets-B3NLls5a.mjs → resolve-targets-3B6QJQUf.mjs} +1 -1
- package/dist/.setup/{room-info-Cw-BH1CA.mjs → room-info-7ER9IkzT.mjs} +3 -3
- package/dist/.setup/{sdk-Bzp2OIxv.mjs → sdk-DphkoEH1.mjs} +32 -33
- package/dist/.setup/{send-CK8h-x83.mjs → send-CAfHI3Oi.mjs} +18 -13
- package/dist/.setup/{send-currentness-D1x6YP9O.mjs → send-currentness-Zv5Z-1_t.mjs} +9 -5
- package/dist/.setup/{setup-bootstrap-DsHa4swp.mjs → setup-bootstrap-COKlzUTV.mjs} +2 -2
- package/dist/.setup/{setup-core-B3MI_zz4.mjs → setup-core-B1dRvn1h.mjs} +1 -1
- package/dist/.setup/setup-plugin-api-BGpOj2cE.mjs +2 -0
- package/dist/.setup/{thread-bindings-C_SHelhg.mjs → thread-bindings-DFF_4WP3.mjs} +1 -1
- package/dist/.setup/{tool-actions-nhsof0wb.mjs → tool-actions-Cal-116X.mjs} +11 -11
- package/dist/.setup/{verification-BZqaSKCW.mjs → verification-2flsiwT7.mjs} +1 -1
- package/dist/.source-module-urls/1cd4d4ff8d44e1c8b830932b44d7cf8a7f3350e09e169910e1d7a85e131b7bea.json +1 -1
- package/dist/api.js +4 -4
- package/dist/channel-plugin-api.js +1 -1
- package/dist/cli-metadata.js +1 -1
- package/dist/contract-api.js +2 -2
- package/dist/index.js +1 -1
- package/dist/plugin-entry.handlers.runtime.js +2 -2
- package/dist/session-binding-contract-api.js +1 -1
- package/dist/setup-entry.js +1 -1
- package/dist/setup-plugin-api.js +1 -1
- package/node_modules/@openclaw/fs-safe/CHANGELOG.md +57 -0
- package/node_modules/@openclaw/fs-safe/README.md +6 -0
- package/node_modules/@openclaw/fs-safe/dist/archive-parser.wasm +0 -0
- package/node_modules/@openclaw/fs-safe/dist/atomic-io.d.ts +1 -0
- package/node_modules/@openclaw/fs-safe/dist/atomic-io.js +10 -0
- package/node_modules/@openclaw/fs-safe/dist/bounded-read.d.ts +1 -1
- package/node_modules/@openclaw/fs-safe/dist/bounded-read.js +15 -4
- package/node_modules/@openclaw/fs-safe/dist/directory-guard.js +11 -2
- package/node_modules/@openclaw/fs-safe/dist/drvfs-parent.d.ts +6 -0
- package/node_modules/@openclaw/fs-safe/dist/drvfs-parent.js +38 -0
- package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-acquisition.d.ts +1 -1
- package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-acquisition.js +2 -2
- package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-root-acquire.js +13 -8
- package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-root-io.js +13 -0
- package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-root-mutation.d.ts +2 -2
- package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-root-mutation.js +34 -24
- package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-stale-admission.js +7 -2
- package/node_modules/@openclaw/fs-safe/dist/file-lock-sync.js +20 -20
- package/node_modules/@openclaw/fs-safe/dist/file-observation.d.ts +13 -2
- package/node_modules/@openclaw/fs-safe/dist/file-observation.js +8 -4
- package/node_modules/@openclaw/fs-safe/dist/file-store-sync-write.d.ts +1 -0
- package/node_modules/@openclaw/fs-safe/dist/file-store-sync-write.js +11 -1
- package/node_modules/@openclaw/fs-safe/dist/file-store-write-options.d.ts +2 -0
- package/node_modules/@openclaw/fs-safe/dist/file-store-write-options.js +17 -0
- package/node_modules/@openclaw/fs-safe/dist/file-store.d.ts +2 -1
- package/node_modules/@openclaw/fs-safe/dist/file-store.js +12 -16
- package/node_modules/@openclaw/fs-safe/dist/guest-native-python.js +1 -1
- package/node_modules/@openclaw/fs-safe/dist/guest.js +3 -4
- package/node_modules/@openclaw/fs-safe/dist/json-document-store.d.ts +2 -0
- package/node_modules/@openclaw/fs-safe/dist/json-document-store.js +1 -0
- package/node_modules/@openclaw/fs-safe/dist/json-store.js +1 -0
- package/node_modules/@openclaw/fs-safe/dist/json.d.ts +5 -2
- package/node_modules/@openclaw/fs-safe/dist/json.js +6 -2
- package/node_modules/@openclaw/fs-safe/dist/local-file-descriptor.js +16 -10
- package/node_modules/@openclaw/fs-safe/dist/native-binding.d.ts +6 -0
- package/node_modules/@openclaw/fs-safe/dist/native-pinned-write.js +4 -0
- package/node_modules/@openclaw/fs-safe/dist/native-staged-file-metadata.d.ts +20 -0
- package/node_modules/@openclaw/fs-safe/dist/native-staged-file-metadata.js +18 -0
- package/node_modules/@openclaw/fs-safe/dist/native-staged-file.d.ts +3 -18
- package/node_modules/@openclaw/fs-safe/dist/native-staged-file.js +48 -24
- package/node_modules/@openclaw/fs-safe/dist/opened-file-failure.js +19 -7
- package/node_modules/@openclaw/fs-safe/dist/output.d.ts +1 -0
- package/node_modules/@openclaw/fs-safe/dist/output.js +3 -0
- package/node_modules/@openclaw/fs-safe/dist/path-policy.js +4 -1
- package/node_modules/@openclaw/fs-safe/dist/permissions-windows.js +35 -10
- package/node_modules/@openclaw/fs-safe/dist/pinned-open.d.ts +9 -2
- package/node_modules/@openclaw/fs-safe/dist/pinned-open.js +42 -23
- package/node_modules/@openclaw/fs-safe/dist/pinned-write-staged.js +85 -34
- package/node_modules/@openclaw/fs-safe/dist/pinned-write-types.d.ts +3 -0
- package/node_modules/@openclaw/fs-safe/dist/pinned-write.js +4 -0
- package/node_modules/@openclaw/fs-safe/dist/prepare-directory-mode.d.ts +1 -0
- package/node_modules/@openclaw/fs-safe/dist/prepare-directory-mode.js +1 -1
- package/node_modules/@openclaw/fs-safe/dist/private-temp-workspace.js +2 -2
- package/node_modules/@openclaw/fs-safe/dist/publication-recovery.d.ts +24 -0
- package/node_modules/@openclaw/fs-safe/dist/publication-recovery.js +151 -0
- package/node_modules/@openclaw/fs-safe/dist/publish-copy-stage.d.ts +1 -0
- package/node_modules/@openclaw/fs-safe/dist/publish-copy-stage.js +2 -1
- package/node_modules/@openclaw/fs-safe/dist/realpath.d.ts +1 -1
- package/node_modules/@openclaw/fs-safe/dist/realpath.js +22 -11
- package/node_modules/@openclaw/fs-safe/dist/replace-file-descriptor.d.ts +1 -0
- package/node_modules/@openclaw/fs-safe/dist/replace-file-descriptor.js +5 -0
- package/node_modules/@openclaw/fs-safe/dist/replace-file-temp-owner.d.ts +7 -0
- package/node_modules/@openclaw/fs-safe/dist/replace-file-temp-owner.js +75 -2
- package/node_modules/@openclaw/fs-safe/dist/replace-file-types.d.ts +2 -0
- package/node_modules/@openclaw/fs-safe/dist/replace-file.js +14 -10
- package/node_modules/@openclaw/fs-safe/dist/root-context.js +28 -12
- package/node_modules/@openclaw/fs-safe/dist/root-copy.js +1 -0
- package/node_modules/@openclaw/fs-safe/dist/root-create-input.js +2 -2
- package/node_modules/@openclaw/fs-safe/dist/root-file-final-admission.d.ts +4 -0
- package/node_modules/@openclaw/fs-safe/dist/root-file-final-admission.js +53 -36
- package/node_modules/@openclaw/fs-safe/dist/root-file-open-batch-sync.js +3 -1
- package/node_modules/@openclaw/fs-safe/dist/root-file.d.ts +2 -1
- package/node_modules/@openclaw/fs-safe/dist/root-file.js +24 -13
- package/node_modules/@openclaw/fs-safe/dist/root-impl.js +17 -1
- package/node_modules/@openclaw/fs-safe/dist/root-options.d.ts +4 -2
- package/node_modules/@openclaw/fs-safe/dist/root-path.d.ts +1 -1
- package/node_modules/@openclaw/fs-safe/dist/root-path.js +2 -1
- package/node_modules/@openclaw/fs-safe/dist/root-read-admission.js +31 -9
- package/node_modules/@openclaw/fs-safe/dist/root-write-admission.js +6 -2
- package/node_modules/@openclaw/fs-safe/dist/secret-file.d.ts +1 -0
- package/node_modules/@openclaw/fs-safe/dist/secret-file.js +2 -0
- package/node_modules/@openclaw/fs-safe/dist/sibling-staged-file.d.ts +1 -0
- package/node_modules/@openclaw/fs-safe/dist/sibling-staged-file.js +84 -4
- package/node_modules/@openclaw/fs-safe/dist/sibling-temp.d.ts +1 -0
- package/node_modules/@openclaw/fs-safe/dist/sibling-temp.js +2 -0
- package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-acquire.js +22 -15
- package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-publication.d.ts +22 -0
- package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-publication.js +303 -0
- package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-reclaim.d.ts +2 -0
- package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-reclaim.js +9 -1
- package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-root.d.ts +8 -0
- package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-root.js +37 -3
- package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-staging.d.ts +14 -0
- package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-staging.js +155 -0
- package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-stale-admission.js +7 -2
- package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-write.d.ts +10 -0
- package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-write.js +143 -0
- package/node_modules/@openclaw/fs-safe/dist/temp-target.js +28 -7
- package/node_modules/@openclaw/fs-safe/dist/temp-workspace-admission.d.ts +2 -2
- package/node_modules/@openclaw/fs-safe/dist/temp-workspace-admission.js +34 -18
- package/node_modules/@openclaw/fs-safe/dist/temp-workspace-child-admission.d.ts +1 -1
- package/node_modules/@openclaw/fs-safe/dist/temp-workspace-child-admission.js +13 -3
- package/node_modules/@openclaw/fs-safe/dist/temp-workspace-ownership.js +1 -1
- package/node_modules/@openclaw/fs-safe/dist/temp-workspace-types.d.ts +9 -0
- package/node_modules/@openclaw/fs-safe/dist/test-hooks.d.ts +6 -0
- package/node_modules/@openclaw/fs-safe/dist/text-atomic.d.ts +1 -1
- package/node_modules/@openclaw/fs-safe/dist/text-atomic.js +1 -0
- package/node_modules/@openclaw/fs-safe/dist/windows-owner.d.ts +1 -0
- package/node_modules/@openclaw/fs-safe/dist/windows-owner.js +2 -1
- package/node_modules/@openclaw/fs-safe/dist/windows-security-helper.exe +0 -0
- package/node_modules/@openclaw/fs-safe/docs/advanced.md +6 -1
- package/node_modules/@openclaw/fs-safe/docs/atomic.md +64 -0
- package/node_modules/@openclaw/fs-safe/docs/contributing.md +69 -0
- package/node_modules/@openclaw/fs-safe/docs/file-store.md +2 -0
- package/node_modules/@openclaw/fs-safe/docs/json-store.md +2 -0
- package/node_modules/@openclaw/fs-safe/docs/json.md +2 -0
- package/node_modules/@openclaw/fs-safe/docs/output.md +2 -0
- package/node_modules/@openclaw/fs-safe/docs/permissions.md +20 -7
- package/node_modules/@openclaw/fs-safe/docs/reading.md +24 -9
- package/node_modules/@openclaw/fs-safe/docs/root.md +2 -0
- package/node_modules/@openclaw/fs-safe/docs/security-model.md +2 -0
- package/node_modules/@openclaw/fs-safe/docs/sidecar-lock.md +12 -7
- package/node_modules/@openclaw/fs-safe/docs/staged-file.md +2 -0
- package/node_modules/@openclaw/fs-safe/docs/temp-isolation-reference.md +73 -0
- package/node_modules/@openclaw/fs-safe/docs/temp.md +65 -0
- package/node_modules/@openclaw/fs-safe/docs/testing.md +1 -0
- package/node_modules/@openclaw/fs-safe/docs/writing.md +2 -0
- package/node_modules/@openclaw/fs-safe/package.json +25 -20
- package/node_modules/@openclaw/fs-safe-darwin-arm64/fs-safe-native.node +0 -0
- package/node_modules/@openclaw/fs-safe-darwin-arm64/package.json +1 -1
- package/node_modules/@openclaw/fs-safe-darwin-x64/fs-safe-native.node +0 -0
- package/node_modules/@openclaw/fs-safe-darwin-x64/package.json +1 -1
- package/node_modules/@openclaw/fs-safe-freebsd-arm64/fs-safe-native.node +0 -0
- package/node_modules/@openclaw/fs-safe-freebsd-arm64/package.json +1 -1
- package/node_modules/@openclaw/fs-safe-freebsd-x64/fs-safe-native.node +0 -0
- package/node_modules/@openclaw/fs-safe-freebsd-x64/package.json +1 -1
- package/node_modules/@openclaw/fs-safe-linux-arm64-gnu/fs-safe-native.node +0 -0
- package/node_modules/@openclaw/fs-safe-linux-arm64-gnu/package.json +1 -1
- package/node_modules/@openclaw/fs-safe-linux-arm64-musl/fs-safe-native.node +0 -0
- package/node_modules/@openclaw/fs-safe-linux-arm64-musl/package.json +1 -1
- package/node_modules/@openclaw/fs-safe-linux-x64-gnu/fs-safe-native.node +0 -0
- package/node_modules/@openclaw/fs-safe-linux-x64-gnu/package.json +1 -1
- package/node_modules/@openclaw/fs-safe-linux-x64-musl/fs-safe-native.node +0 -0
- package/node_modules/@openclaw/fs-safe-linux-x64-musl/package.json +1 -1
- package/node_modules/@openclaw/fs-safe-win32-arm64-msvc/fs-safe-native.node +0 -0
- package/node_modules/@openclaw/fs-safe-win32-arm64-msvc/package.json +1 -1
- package/node_modules/@openclaw/fs-safe-win32-x64-msvc/fs-safe-native.node +0 -0
- package/node_modules/@openclaw/fs-safe-win32-x64-msvc/package.json +1 -1
- package/package.json +5 -5
- package/dist/.setup/setup-plugin-api-D6-D6LLj.mjs +0 -2
|
@@ -7,6 +7,10 @@ import { assertDirectoryIdentitySync, createAsyncDirectoryGuard, } from "./direc
|
|
|
7
7
|
import { syncDirectoryBestEffort } from "./directory-durability.js";
|
|
8
8
|
import { isWindowsReservedDeviceName } from "./device-path.js";
|
|
9
9
|
import { FsSafeError } from "./errors.js";
|
|
10
|
+
import { retainDrvfsParent } from "./drvfs-parent.js";
|
|
11
|
+
import { sha256FileSync } from "./file-hash.js";
|
|
12
|
+
import { hasErrorCode } from "./file-cleanup.js";
|
|
13
|
+
import { assertRecoveredFile, recoverAfterHiddenRename, shouldPrepareDrvfsRecovery } from "./publication-recovery.js";
|
|
10
14
|
import { getNativeBinding } from "./native.js";
|
|
11
15
|
import { isFsSafeNativeRequired } from "./native-config.js";
|
|
12
16
|
import { cachedNoReplaceDevice, isNoReplaceUnavailable } from "./native-noreplace.js";
|
|
@@ -161,6 +165,7 @@ export async function writeCallbackSibling(params) {
|
|
|
161
165
|
const maxBytes = params.maxBytes;
|
|
162
166
|
const syncTempFile = params.syncTempFile;
|
|
163
167
|
const syncParentDir = params.syncParentDir;
|
|
168
|
+
const allowDrvfsRenameRecovery = params.allowDrvfsRenameRecovery === true;
|
|
164
169
|
const rootBoundary = params.rootBoundary;
|
|
165
170
|
const guard = await createAsyncDirectoryGuard(parent, { bigint: true });
|
|
166
171
|
const assertParent = () => {
|
|
@@ -177,6 +182,9 @@ export async function writeCallbackSibling(params) {
|
|
|
177
182
|
throw new FsSafeError("outside-workspace", "sibling parent resolves outside the root");
|
|
178
183
|
}
|
|
179
184
|
};
|
|
185
|
+
let recoveryParent;
|
|
186
|
+
let recoveryIdentity;
|
|
187
|
+
let recoveryHash;
|
|
180
188
|
let handle;
|
|
181
189
|
let identity;
|
|
182
190
|
let unregister;
|
|
@@ -186,7 +194,7 @@ export async function writeCallbackSibling(params) {
|
|
|
186
194
|
const inspectPath = (pathname, expected) => inspectStage(() => fsSync.lstatSync(pathname, { bigint: true }), expected);
|
|
187
195
|
const assertCurrent = (pathname) => {
|
|
188
196
|
assertParent();
|
|
189
|
-
const opened = inspectStage(() => fsSync.fstatSync(handle.fd, { bigint: true }), identity);
|
|
197
|
+
const opened = handle ? inspectStage(() => fsSync.fstatSync(handle.fd, { bigint: true }), identity) : identity;
|
|
190
198
|
const current = inspectPath(pathname, opened);
|
|
191
199
|
if (maxBytes !== undefined &&
|
|
192
200
|
(opened.size > maxBytes || current.size > maxBytes)) {
|
|
@@ -272,15 +280,81 @@ export async function writeCallbackSibling(params) {
|
|
|
272
280
|
await syncFileBestEffort(handle);
|
|
273
281
|
assertCurrent(tempPath);
|
|
274
282
|
}
|
|
283
|
+
if (shouldPrepareDrvfsRecovery(allowDrvfsRenameRecovery)) {
|
|
284
|
+
recoveryParent = retainDrvfsParent(parent, guard.stat.dev);
|
|
285
|
+
if (recoveryParent) {
|
|
286
|
+
recoveryIdentity = fsSync.fstatSync(handle.fd, { bigint: true });
|
|
287
|
+
recoveryHash = sha256FileSync(handle.fd, { maxBytes }).digest;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
275
290
|
await fs.rename(tempPath, filePath);
|
|
276
291
|
// A later verification failure never authorizes rollback of the final name.
|
|
277
292
|
renamed = true;
|
|
278
293
|
unregister();
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
294
|
+
let recoveredHandle;
|
|
295
|
+
let settled = false;
|
|
296
|
+
try {
|
|
282
297
|
assertCurrent(filePath);
|
|
283
298
|
}
|
|
299
|
+
catch (error) {
|
|
300
|
+
if (!hasErrorCode(error, "ENOENT") || !recoveryParent)
|
|
301
|
+
throw error;
|
|
302
|
+
// Keep the recovered descriptor through parent synchronization and final admission.
|
|
303
|
+
const assertPublishedCurrent = (reopened) => {
|
|
304
|
+
assertParent();
|
|
305
|
+
recoveryParent.assertCurrent();
|
|
306
|
+
assertRecoveredFile(reopened.fd, recoveryIdentity);
|
|
307
|
+
if (sha256FileSync(reopened.fd, { maxBytes }).digest !== recoveryHash) {
|
|
308
|
+
throw new FsSafeError("path-mismatch", "sibling content changed during DrvFS recovery");
|
|
309
|
+
}
|
|
310
|
+
const opened = inspectStage(() => fsSync.fstatSync(reopened.fd, { bigint: true }), identity);
|
|
311
|
+
const current = inspectPath(filePath, opened);
|
|
312
|
+
if (maxBytes !== undefined && (opened.size > maxBytes || current.size > maxBytes)) {
|
|
313
|
+
throw new FsSafeError("too-large", `sibling temp exceeds maxBytes (${maxBytes})`);
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
const previous = handle;
|
|
317
|
+
handle = undefined;
|
|
318
|
+
try {
|
|
319
|
+
recoveredHandle = await recoverAfterHiddenRename({
|
|
320
|
+
closeWriter: () => previous.close(),
|
|
321
|
+
parentFd: recoveryParent.fd,
|
|
322
|
+
reopen: async () => {
|
|
323
|
+
const reopened = await fs.open(filePath, resolveReadOpenFlags());
|
|
324
|
+
try {
|
|
325
|
+
assertPublishedCurrent(reopened);
|
|
326
|
+
return reopened;
|
|
327
|
+
}
|
|
328
|
+
catch (verifyError) {
|
|
329
|
+
await reopened.close().catch(() => undefined);
|
|
330
|
+
throw verifyError;
|
|
331
|
+
}
|
|
332
|
+
},
|
|
333
|
+
retain: async (reopened) => {
|
|
334
|
+
if (syncParentDir)
|
|
335
|
+
await syncDirectoryBestEffort(parent);
|
|
336
|
+
assertPublishedCurrent(reopened);
|
|
337
|
+
},
|
|
338
|
+
dispose: async (reopened) => { await reopened.close().catch(() => undefined); },
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
catch (error) {
|
|
342
|
+
// Reclaim the writer if recovery failed before closing it; a
|
|
343
|
+
// second close on an already-closed handle is swallowed.
|
|
344
|
+
await previous.close().catch(() => undefined);
|
|
345
|
+
throw error;
|
|
346
|
+
}
|
|
347
|
+
settled = true;
|
|
348
|
+
}
|
|
349
|
+
try {
|
|
350
|
+
if (syncParentDir && !settled) {
|
|
351
|
+
await syncDirectoryBestEffort(parent);
|
|
352
|
+
assertCurrent(filePath);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
finally {
|
|
356
|
+
await recoveredHandle?.close().catch(() => undefined);
|
|
357
|
+
}
|
|
284
358
|
});
|
|
285
359
|
return { filePath, result };
|
|
286
360
|
}
|
|
@@ -290,6 +364,12 @@ export async function writeCallbackSibling(params) {
|
|
|
290
364
|
}
|
|
291
365
|
finally {
|
|
292
366
|
const settlementErrors = [];
|
|
367
|
+
try {
|
|
368
|
+
recoveryParent?.close();
|
|
369
|
+
}
|
|
370
|
+
catch (error) {
|
|
371
|
+
settlementErrors.push(error);
|
|
372
|
+
}
|
|
293
373
|
if (cleanupWorkspace) {
|
|
294
374
|
try {
|
|
295
375
|
await cleanupWorkspace();
|
|
@@ -14,6 +14,7 @@ export type WriteSiblingTempFileOptions<T> = {
|
|
|
14
14
|
syncTempFile?: boolean;
|
|
15
15
|
/** Best-effort parent directory sync after rename; defaults to false. */
|
|
16
16
|
syncParentDir?: boolean;
|
|
17
|
+
allowDrvfsRenameRecovery?: boolean;
|
|
17
18
|
};
|
|
18
19
|
export type WriteSiblingTempFileResult<T> = {
|
|
19
20
|
filePath: string;
|
|
@@ -34,6 +34,7 @@ export async function writeSiblingTempFile(options) {
|
|
|
34
34
|
const mode = options.mode;
|
|
35
35
|
const syncTempFile = options.syncTempFile === true;
|
|
36
36
|
const syncParentDir = options.syncParentDir === true;
|
|
37
|
+
const allowDrvfsRenameRecovery = options.allowDrvfsRenameRecovery === true;
|
|
37
38
|
if (dirMode === "preserve" || chmodDir) {
|
|
38
39
|
await runAsync(prepareDirectoryMode(AtomicIo.async(fs), {
|
|
39
40
|
dirPath: dir,
|
|
@@ -53,6 +54,7 @@ export async function writeSiblingTempFile(options) {
|
|
|
53
54
|
ignoreModeError: true,
|
|
54
55
|
syncTempFile,
|
|
55
56
|
syncParentDir,
|
|
57
|
+
allowDrvfsRenameRecovery,
|
|
56
58
|
});
|
|
57
59
|
}
|
|
58
60
|
function buildSiblingTempName(params) {
|
|
@@ -4,9 +4,9 @@ import { FsSafeError } from "./errors.js";
|
|
|
4
4
|
import { fileObservation } from "./file-observation.js";
|
|
5
5
|
import { sameFileIdentityForCleanup } from "./file-identity.js";
|
|
6
6
|
import { readFileHandleBounded } from "./bounded-read.js";
|
|
7
|
-
import { openSidecarRoot } from "./sidecar-lock-root.js";
|
|
7
|
+
import { openSidecarRoot, rootSidecarPublicationPending } from "./sidecar-lock-root.js";
|
|
8
8
|
import { createNativeExclusiveFile } from "./native-operations.js";
|
|
9
|
-
import {
|
|
9
|
+
import { createSidecarFile } from "./sidecar-lock-publication.js";
|
|
10
10
|
import { sidecarLockRetryDelay, sidecarLockTimeout, isTransientLockFileDenial, maxTransientLockDenials, validateSidecarLockStaleMs, validateSidecarLockRetryOptions, validateSidecarLockCompromiseCheckIntervalMs, validateSidecarLockTimeoutMs, } from "./sidecar-lock-policy.js";
|
|
11
11
|
import { relativeSidecarLockPath, removeSidecarLockIfUnchanged, serializeSidecarLockPayload, sidecarReclaimGuardExists, } from "./sidecar-lock-reclaim.js";
|
|
12
12
|
import { awaitSidecarAdmissionBoundary, conditionalSidecarLockParser, observeHeldSidecarParser, observeSidecarLockParser, runSidecarAdmissionBoundary, } from "./sidecar-lock-admission-parser.js";
|
|
@@ -259,9 +259,17 @@ export async function acquireSidecarLock(options, context) {
|
|
|
259
259
|
}));
|
|
260
260
|
}
|
|
261
261
|
catch (error) {
|
|
262
|
+
let cause = error;
|
|
263
|
+
for (let depth = 0; depth < 4 && cause && typeof cause === "object"; depth++) {
|
|
264
|
+
if (observation.has(cause, "hardlink") && await rootSidecarPublicationPending(lockRoot, relativeLockPath, { cleanAbandoned: true })) {
|
|
265
|
+
exclusiveCreateConflict = true;
|
|
266
|
+
throw Object.assign(new Error("sidecar publication in progress"), { code: "EEXIST" });
|
|
267
|
+
}
|
|
268
|
+
cause = Object.getOwnPropertyDescriptor(cause, "cause")?.value;
|
|
269
|
+
}
|
|
262
270
|
// Only this invocation's failed exclusive open grants denial retry authority.
|
|
263
|
-
lockFileCreateDenied = observation.has(error, `
|
|
264
|
-
isTransientLockFileDenial(error, lockPath);
|
|
271
|
+
lockFileCreateDenied = observation.has(error, `sidecar-create-denial:${lockPath}`) ||
|
|
272
|
+
(observation.has(error, `exclusive-create:${lockPath}`) && isTransientLockFileDenial(error, lockPath));
|
|
265
273
|
if (error instanceof FsSafeError && error.code === "already-exists") {
|
|
266
274
|
exclusiveCreateConflict = true;
|
|
267
275
|
throw Object.assign(new Error("sidecar lock exists"), { code: "EEXIST" });
|
|
@@ -289,23 +297,22 @@ export async function acquireSidecarLock(options, context) {
|
|
|
289
297
|
handle = opened.handle;
|
|
290
298
|
}
|
|
291
299
|
else {
|
|
292
|
-
const failedOpen = (createError) => {
|
|
293
|
-
lockFileCreateDenied = isTransientLockFileDenial(createError,
|
|
294
|
-
exclusiveCreateConflict = createError.code === "EEXIST";
|
|
300
|
+
const failedOpen = (createError, pathname = lockPath) => {
|
|
301
|
+
lockFileCreateDenied = isTransientLockFileDenial(createError, pathname);
|
|
302
|
+
exclusiveCreateConflict = pathname === lockPath && createError.code === "EEXIST";
|
|
295
303
|
throw createError;
|
|
296
304
|
};
|
|
297
|
-
|
|
298
|
-
if (!handle) {
|
|
305
|
+
const created = await createSidecarFile(lockPath, raw, async (pathname) => {
|
|
299
306
|
try {
|
|
300
|
-
|
|
307
|
+
return await createNativeExclusiveFile(pathname, 0o600) ?? await fs.open(pathname, fsSync.constants.O_WRONLY | fsSync.constants.O_CREAT | fsSync.constants.O_EXCL |
|
|
308
|
+
(process.platform !== "win32" ? fsSync.constants.O_NOFOLLOW ?? 0 : 0), 0o600);
|
|
301
309
|
}
|
|
302
310
|
catch (error) {
|
|
303
|
-
|
|
304
|
-
throw error;
|
|
311
|
+
return failedOpen(error, pathname);
|
|
305
312
|
}
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
313
|
+
}, { onConflict: failedOpen });
|
|
314
|
+
handle = created.handle;
|
|
315
|
+
createdSnapshot = { raw, payload, stat: created.identity, ownershipToken };
|
|
309
316
|
}
|
|
310
317
|
const snapshot = { raw, payload, stat: fsSync.fstatSync(handle.fd, { bigint: true }), ownershipToken };
|
|
311
318
|
createdSnapshot = snapshot;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type BigIntStats } from "node:fs";
|
|
2
|
+
import type { NativeWriteParent } from "./pinned-write-types.js";
|
|
3
|
+
export type SidecarPublicationOptions = {
|
|
4
|
+
nativeParent?: NativeWriteParent;
|
|
5
|
+
assertCurrent?: () => void;
|
|
6
|
+
assertCleanupCandidate?: (candidate: string) => void;
|
|
7
|
+
onConflict?: (error: unknown) => void;
|
|
8
|
+
prepare?: (fd: number) => void;
|
|
9
|
+
requireExactIdentity?: boolean;
|
|
10
|
+
};
|
|
11
|
+
export declare function createSidecarFileSync(targetPath: string, raw: string, open: (pathname: string) => number, options?: SidecarPublicationOptions): {
|
|
12
|
+
fd: number;
|
|
13
|
+
identity: BigIntStats;
|
|
14
|
+
};
|
|
15
|
+
export declare function createSidecarFile<T extends {
|
|
16
|
+
fd: number;
|
|
17
|
+
close(): Promise<void>;
|
|
18
|
+
writeFile(data: string, encoding: BufferEncoding): Promise<void>;
|
|
19
|
+
}>(targetPath: string, raw: string, open: (pathname: string) => Promise<T>, options?: SidecarPublicationOptions): Promise<{
|
|
20
|
+
handle: T;
|
|
21
|
+
identity: BigIntStats;
|
|
22
|
+
}>;
|
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
import fs, {} from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { sidecarStagingPath, cleanupSidecarStages } from "./sidecar-lock-staging.js";
|
|
4
|
+
import { createSuppressedError } from "./suppressed-error.js";
|
|
5
|
+
import { FsSafeError } from "./errors.js";
|
|
6
|
+
import { sameFileIdentity, sameFileIdentityForCleanup } from "./file-identity.js";
|
|
7
|
+
import { readSidecarLockRawSnapshotSync } from "./sidecar-lock-reclaim.js";
|
|
8
|
+
import { isHardlinkFallbackError } from "./hardlink-fallback.js";
|
|
9
|
+
import { getNativeBinding } from "./native.js";
|
|
10
|
+
import { noReplaceUnavailable } from "./native-noreplace.js";
|
|
11
|
+
import { getFsSafeTestHooks } from "./test-hooks.js";
|
|
12
|
+
function optionalDirectoryPersistence(error) {
|
|
13
|
+
return ["EACCES", "EPERM", "EINVAL", "ENOTSUP", "EOPNOTSUPP"].includes(error?.code ?? "");
|
|
14
|
+
}
|
|
15
|
+
function openPublicationParent(target) {
|
|
16
|
+
try {
|
|
17
|
+
return fs.openSync(path.dirname(target), fs.constants.O_RDONLY | (fs.constants.O_DIRECTORY ?? 0));
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
if (!optionalDirectoryPersistence(error))
|
|
21
|
+
throw error;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
// Final lock ownership never comes from staging cleanup or an observed PID.
|
|
25
|
+
class SidecarPublication {
|
|
26
|
+
targetPath;
|
|
27
|
+
raw;
|
|
28
|
+
options;
|
|
29
|
+
temporaryPath;
|
|
30
|
+
identity;
|
|
31
|
+
temporaryIdentity;
|
|
32
|
+
publishedIdentity;
|
|
33
|
+
published = false;
|
|
34
|
+
ownedParent;
|
|
35
|
+
parentIdentity;
|
|
36
|
+
close() {
|
|
37
|
+
const fd = this.ownedParent;
|
|
38
|
+
this.ownedParent = undefined;
|
|
39
|
+
if (fd !== undefined)
|
|
40
|
+
try {
|
|
41
|
+
fs.closeSync(fd);
|
|
42
|
+
}
|
|
43
|
+
catch { /* Preserve the creation outcome. */ }
|
|
44
|
+
}
|
|
45
|
+
constructor(targetPath, raw, options) {
|
|
46
|
+
this.targetPath = targetPath;
|
|
47
|
+
this.raw = raw;
|
|
48
|
+
this.options = options;
|
|
49
|
+
if (!options.nativeParent) {
|
|
50
|
+
const binding = getNativeBinding();
|
|
51
|
+
if (binding && (binding.renameNoReplace || binding.linkBeneath)) {
|
|
52
|
+
this.ownedParent = openPublicationParent(targetPath);
|
|
53
|
+
if (this.ownedParent !== undefined)
|
|
54
|
+
options = { ...options, nativeParent: { fd: this.ownedParent, binding } };
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
this.options = options;
|
|
58
|
+
try {
|
|
59
|
+
this.parentIdentity = options.nativeParent
|
|
60
|
+
? fs.fstatSync(options.nativeParent.fd, { bigint: true })
|
|
61
|
+
: fs.statSync(path.dirname(targetPath), { bigint: true });
|
|
62
|
+
this.temporaryPath = sidecarStagingPath(targetPath);
|
|
63
|
+
cleanupSidecarStages(targetPath, candidate => {
|
|
64
|
+
this.assertParent();
|
|
65
|
+
if (candidate)
|
|
66
|
+
options.assertCleanupCandidate?.(candidate);
|
|
67
|
+
}, options.nativeParent);
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
this.close();
|
|
71
|
+
throw error;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
assertParent() {
|
|
75
|
+
this.options.assertCurrent?.();
|
|
76
|
+
const parent = fs.statSync(path.dirname(this.targetPath), { bigint: true });
|
|
77
|
+
if (!parent.isDirectory() || !sameFileIdentityForCleanup(parent, this.parentIdentity)) {
|
|
78
|
+
throw new FsSafeError("path-mismatch", "sidecar publication parent changed");
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
remember(fd, exclusive = false) {
|
|
82
|
+
this.published = exclusive;
|
|
83
|
+
this.identity = fs.fstatSync(fd, { bigint: true });
|
|
84
|
+
if (this.options.requireExactIdentity && (!this.identity.isFile() || this.identity.nlink !== 1n ||
|
|
85
|
+
!sameFileIdentityForCleanup(this.identity, this.identity))) {
|
|
86
|
+
throw new FsSafeError("path-mismatch", "sidecar stage has no exact creation identity");
|
|
87
|
+
}
|
|
88
|
+
return this.identity;
|
|
89
|
+
}
|
|
90
|
+
assertNamed(name, fd, links) {
|
|
91
|
+
this.assertParent();
|
|
92
|
+
const opened = fs.fstatSync(fd, { bigint: true });
|
|
93
|
+
const named = fs.lstatSync(name, { bigint: true });
|
|
94
|
+
const previous = name === this.temporaryPath ? this.temporaryIdentity : this.publishedIdentity;
|
|
95
|
+
const pathStable = !previous || sameFileIdentityForCleanup(named, previous);
|
|
96
|
+
const heldMatches = this.identity && (this.options.requireExactIdentity
|
|
97
|
+
? sameFileIdentityForCleanup(opened, this.identity) : sameFileIdentity(opened, this.identity));
|
|
98
|
+
let namedMatches = this.identity && sameFileIdentityForCleanup(named, this.identity);
|
|
99
|
+
if (!namedMatches && !this.options.requireExactIdentity && named.isFile() && !named.isSymbolicLink()) {
|
|
100
|
+
// Raw lock ownership already tolerates descriptor/path identity drift:
|
|
101
|
+
// verify the complete in-memory owner token through a stable pathname.
|
|
102
|
+
const snapshot = readSidecarLockRawSnapshotSync(name, { allowDescriptorIdentityDrift: true });
|
|
103
|
+
namedMatches = !!snapshot?.stat && snapshot.raw === this.raw && sameFileIdentityForCleanup(named, snapshot.stat);
|
|
104
|
+
}
|
|
105
|
+
if (!opened.isFile() || !named.isFile() || named.isSymbolicLink() || !heldMatches ||
|
|
106
|
+
!namedMatches || !pathStable || opened.nlink !== links || named.nlink !== links) {
|
|
107
|
+
throw new FsSafeError("path-mismatch", "sidecar publication identity changed");
|
|
108
|
+
}
|
|
109
|
+
if (name === this.temporaryPath)
|
|
110
|
+
this.temporaryIdentity ??= named;
|
|
111
|
+
else
|
|
112
|
+
this.publishedIdentity ??= named;
|
|
113
|
+
}
|
|
114
|
+
publish(fd) {
|
|
115
|
+
this.assertNamed(this.temporaryPath, fd, 1n);
|
|
116
|
+
getFsSafeTestHooks()?.beforeSidecarLockPublish?.(this.targetPath, this.temporaryPath);
|
|
117
|
+
this.assertNamed(this.temporaryPath, fd, 1n);
|
|
118
|
+
const native = this.options.nativeParent;
|
|
119
|
+
const source = path.basename(this.temporaryPath), target = path.basename(this.targetPath);
|
|
120
|
+
if (native?.binding.renameNoReplace) {
|
|
121
|
+
try {
|
|
122
|
+
native.binding.renameNoReplace(native.fd, source, native.fd, target);
|
|
123
|
+
this.published = true;
|
|
124
|
+
}
|
|
125
|
+
catch (error) {
|
|
126
|
+
if (!noReplaceUnavailable(error, "sidecar publication", true)) {
|
|
127
|
+
if (error.code === "EEXIST")
|
|
128
|
+
this.options.onConflict?.(error);
|
|
129
|
+
throw error;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if (!this.published) {
|
|
134
|
+
try {
|
|
135
|
+
if (native?.binding.linkBeneath)
|
|
136
|
+
native.binding.linkBeneath(native.fd, source, native.fd, target);
|
|
137
|
+
else
|
|
138
|
+
fs.linkSync(this.temporaryPath, this.targetPath);
|
|
139
|
+
this.published = true;
|
|
140
|
+
}
|
|
141
|
+
catch (error) {
|
|
142
|
+
// These errors establish that linking cannot publish here. Permission
|
|
143
|
+
// refusals still have to pass the final exclusive open; never mask it.
|
|
144
|
+
if (isHardlinkFallbackError(error))
|
|
145
|
+
return false;
|
|
146
|
+
if (error.code === "EEXIST")
|
|
147
|
+
this.options.onConflict?.(error);
|
|
148
|
+
throw error;
|
|
149
|
+
}
|
|
150
|
+
this.assertNamed(this.targetPath, fd, 2n);
|
|
151
|
+
this.assertNamed(this.temporaryPath, fd, 2n);
|
|
152
|
+
this.removeTemporary(fd);
|
|
153
|
+
}
|
|
154
|
+
this.finish(fd);
|
|
155
|
+
return true;
|
|
156
|
+
}
|
|
157
|
+
finish(fd) {
|
|
158
|
+
this.assertNamed(this.targetPath, fd, 1n);
|
|
159
|
+
const native = this.options.nativeParent;
|
|
160
|
+
const parent = native?.fd ?? (process.platform !== "win32" ? openPublicationParent(this.targetPath) : undefined);
|
|
161
|
+
if (parent !== undefined) {
|
|
162
|
+
try {
|
|
163
|
+
this.assertParent();
|
|
164
|
+
try {
|
|
165
|
+
fs.fsyncSync(parent);
|
|
166
|
+
}
|
|
167
|
+
catch (error) {
|
|
168
|
+
if (!optionalDirectoryPersistence(error))
|
|
169
|
+
throw error;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
finally {
|
|
173
|
+
if (!native)
|
|
174
|
+
fs.closeSync(parent);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
this.assertNamed(this.targetPath, fd, 1n);
|
|
178
|
+
}
|
|
179
|
+
cleanup(fd) {
|
|
180
|
+
if (this.published)
|
|
181
|
+
this.removeName(this.targetPath, fd);
|
|
182
|
+
this.removeTemporary(fd);
|
|
183
|
+
}
|
|
184
|
+
removeTemporary(fd) {
|
|
185
|
+
this.removeName(this.temporaryPath, fd);
|
|
186
|
+
}
|
|
187
|
+
removeName(pathname, fd) {
|
|
188
|
+
if (!this.identity)
|
|
189
|
+
return;
|
|
190
|
+
this.assertParent();
|
|
191
|
+
const current = fs.lstatSync(pathname, { bigint: true, throwIfNoEntry: false });
|
|
192
|
+
if (!current)
|
|
193
|
+
return;
|
|
194
|
+
const expected = pathname === this.temporaryPath ? this.temporaryIdentity ?? this.identity
|
|
195
|
+
: this.publishedIdentity ?? this.identity;
|
|
196
|
+
if (!current.isFile() || current.isSymbolicLink() || !sameFileIdentityForCleanup(current, expected)) {
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
const native = this.options.nativeParent;
|
|
200
|
+
if (native?.binding.removeStagedFile) {
|
|
201
|
+
const removed = native.binding.removeStagedFile(native.fd, path.basename(pathname), fd);
|
|
202
|
+
if (removed !== "removed" && removed !== "name-absent") {
|
|
203
|
+
throw new FsSafeError("path-mismatch", "sidecar stage cleanup lost identity");
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
else
|
|
207
|
+
fs.unlinkSync(pathname);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
export function createSidecarFileSync(targetPath, raw, open, options = {}) {
|
|
211
|
+
const publication = new SidecarPublication(targetPath, raw, options);
|
|
212
|
+
let fd;
|
|
213
|
+
try {
|
|
214
|
+
publication.assertParent();
|
|
215
|
+
fd = open(publication.temporaryPath);
|
|
216
|
+
let identity = publication.remember(fd);
|
|
217
|
+
options.prepare?.(fd);
|
|
218
|
+
fs.writeFileSync(fd, raw, "utf8");
|
|
219
|
+
fs.fsyncSync(fd);
|
|
220
|
+
if (!publication.publish(fd)) {
|
|
221
|
+
publication.removeTemporary(fd);
|
|
222
|
+
const stagedFd = fd;
|
|
223
|
+
fd = undefined;
|
|
224
|
+
fs.closeSync(stagedFd);
|
|
225
|
+
publication.assertParent();
|
|
226
|
+
fd = open(targetPath);
|
|
227
|
+
identity = publication.remember(fd, true);
|
|
228
|
+
options.prepare?.(fd);
|
|
229
|
+
// Unwritten NUL padding keeps even a complete JSON prefix unverifiable
|
|
230
|
+
// until the trailing ownership token has also been written.
|
|
231
|
+
fs.ftruncateSync(fd, Buffer.byteLength(raw));
|
|
232
|
+
fs.writeFileSync(fd, raw, "utf8");
|
|
233
|
+
fs.fsyncSync(fd);
|
|
234
|
+
publication.finish(fd);
|
|
235
|
+
}
|
|
236
|
+
return { fd, identity };
|
|
237
|
+
}
|
|
238
|
+
catch (error) {
|
|
239
|
+
if (fd !== undefined) {
|
|
240
|
+
try {
|
|
241
|
+
try {
|
|
242
|
+
publication.cleanup(fd);
|
|
243
|
+
}
|
|
244
|
+
finally {
|
|
245
|
+
fs.closeSync(fd);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
catch (cleanupError) {
|
|
249
|
+
throw createSuppressedError(error, cleanupError, "sidecar preparation and cleanup both failed");
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
throw error;
|
|
253
|
+
}
|
|
254
|
+
finally {
|
|
255
|
+
publication.close();
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
export async function createSidecarFile(targetPath, raw, open, options = {}) {
|
|
259
|
+
const publication = new SidecarPublication(targetPath, raw, options);
|
|
260
|
+
let handle;
|
|
261
|
+
try {
|
|
262
|
+
publication.assertParent();
|
|
263
|
+
handle = await open(publication.temporaryPath);
|
|
264
|
+
let identity = publication.remember(handle.fd);
|
|
265
|
+
options.prepare?.(handle.fd);
|
|
266
|
+
await handle.writeFile(raw, "utf8");
|
|
267
|
+
fs.fsyncSync(handle.fd);
|
|
268
|
+
if (!publication.publish(handle.fd)) {
|
|
269
|
+
publication.removeTemporary(handle.fd);
|
|
270
|
+
const stagedHandle = handle;
|
|
271
|
+
handle = undefined;
|
|
272
|
+
await stagedHandle.close();
|
|
273
|
+
publication.assertParent();
|
|
274
|
+
handle = await open(targetPath);
|
|
275
|
+
identity = publication.remember(handle.fd, true);
|
|
276
|
+
options.prepare?.(handle.fd);
|
|
277
|
+
fs.ftruncateSync(handle.fd, Buffer.byteLength(raw));
|
|
278
|
+
await handle.writeFile(raw, "utf8");
|
|
279
|
+
fs.fsyncSync(handle.fd);
|
|
280
|
+
publication.finish(handle.fd);
|
|
281
|
+
}
|
|
282
|
+
return { handle, identity };
|
|
283
|
+
}
|
|
284
|
+
catch (error) {
|
|
285
|
+
if (handle) {
|
|
286
|
+
try {
|
|
287
|
+
try {
|
|
288
|
+
publication.cleanup(handle.fd);
|
|
289
|
+
}
|
|
290
|
+
finally {
|
|
291
|
+
await handle.close();
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
catch (cleanupError) {
|
|
295
|
+
throw createSuppressedError(cleanupError, error, "sidecar preparation and cleanup both failed");
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
throw error;
|
|
299
|
+
}
|
|
300
|
+
finally {
|
|
301
|
+
publication.close();
|
|
302
|
+
}
|
|
303
|
+
}
|
|
@@ -23,6 +23,7 @@ export declare function serializeSidecarLockPayload(payload: Record<string, unkn
|
|
|
23
23
|
};
|
|
24
24
|
export declare function relativeSidecarLockPath(lockRoot: Root, lockPath: string): string;
|
|
25
25
|
export declare function parseSidecarLockPayload(raw: string, parser?: (raw: string) => unknown): unknown;
|
|
26
|
+
export declare function isIncompleteSidecarLockRecord(raw: string | undefined): boolean;
|
|
26
27
|
export declare function readSidecarLockRawSnapshot(lockPath: string, options?: {
|
|
27
28
|
lockRoot?: Root;
|
|
28
29
|
rejectNonFile?: boolean;
|
|
@@ -33,6 +34,7 @@ export declare function readSidecarLockRawSnapshot(lockPath: string, options?: {
|
|
|
33
34
|
export declare function readSidecarLockSnapshotSync(lockPath: string, parsePayload?: (raw: string) => unknown, options?: Parameters<typeof readSidecarLockRawSnapshotSync>[1]): SidecarLockSnapshot | null;
|
|
34
35
|
export declare function readSidecarLockRawSnapshotSync(lockPath: string, options?: {
|
|
35
36
|
rejectNonFile?: boolean;
|
|
37
|
+
allowDescriptorIdentityDrift?: boolean;
|
|
36
38
|
onOpenFailure?: (error: unknown) => void;
|
|
37
39
|
}): SidecarLockRawSnapshot | null;
|
|
38
40
|
export declare function removeSidecarLockIfUnchangedSync(lockPath: string, observed: SidecarLockSnapshot, assertAuthorized?: () => void): boolean;
|
|
@@ -52,6 +52,8 @@ export function relativeSidecarLockPath(lockRoot, lockPath) {
|
|
|
52
52
|
return relative.split(path.sep).join(path.posix.sep);
|
|
53
53
|
}
|
|
54
54
|
export function parseSidecarLockPayload(raw, parser) {
|
|
55
|
+
if (isIncompleteSidecarLockRecord(raw))
|
|
56
|
+
return null;
|
|
55
57
|
if (parser) {
|
|
56
58
|
return parser(raw);
|
|
57
59
|
}
|
|
@@ -63,6 +65,11 @@ export function parseSidecarLockPayload(raw, parser) {
|
|
|
63
65
|
return null;
|
|
64
66
|
}
|
|
65
67
|
}
|
|
68
|
+
// Compatibility writes reserve their length before writing, so unwritten bytes
|
|
69
|
+
// remain NULs. Legacy formats still belong to the caller's parser.
|
|
70
|
+
export function isIncompleteSidecarLockRecord(raw) {
|
|
71
|
+
return raw === undefined || raw.length === 0 || raw.includes("\0");
|
|
72
|
+
}
|
|
66
73
|
async function readSidecarLockComparisonSnapshot(lockPath, options) {
|
|
67
74
|
const snapshot = await readSidecarLockRawSnapshot(lockPath, options);
|
|
68
75
|
const parsePayload = options?.parsePayload;
|
|
@@ -180,7 +187,8 @@ export function readSidecarLockRawSnapshotSync(lockPath, options = {}) {
|
|
|
180
187
|
}
|
|
181
188
|
const raw = readFileDescriptorBoundedSync(fd, MAX_LOCK_PAYLOAD_BYTES).toString("utf8");
|
|
182
189
|
const after = lstatSidecarLockSync(lockPath);
|
|
183
|
-
if (!after || !
|
|
190
|
+
if (!after || !after.isFile() || after.isSymbolicLink() || !sameFileIdentity(before, after) ||
|
|
191
|
+
(!options.allowDescriptorIdentityDrift && (!sameFileIdentity(before, opened) || !sameFileIdentity(opened, after))))
|
|
184
192
|
return null;
|
|
185
193
|
return {
|
|
186
194
|
raw,
|
|
@@ -1,2 +1,10 @@
|
|
|
1
1
|
import type { OpenResult, Root } from "./root-impl.js";
|
|
2
|
+
export declare function rootSidecarPublicationPending(lockRoot: Root, relative: string, options?: {
|
|
3
|
+
cleanAbandoned?: boolean;
|
|
4
|
+
requireStage?: boolean;
|
|
5
|
+
identity?: {
|
|
6
|
+
dev: bigint;
|
|
7
|
+
ino: bigint;
|
|
8
|
+
};
|
|
9
|
+
}): Promise<boolean>;
|
|
2
10
|
export declare function openSidecarRoot(lockRoot: Root, relative: string, discardObservation?: "unlinked" | "changed", onOpenFailure?: (error: unknown) => void): Promise<OpenResult | null>;
|