@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
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { snapshotWriteOptions } from "./file-store-write-options.js";
|
|
1
2
|
import syncFs from "node:fs";
|
|
2
3
|
import { rejectPrivateDirectoryPreservation } from "./directory-mode-options.js";
|
|
3
4
|
import { normalizeMaxBytes } from "./byte-budget.js";
|
|
@@ -15,21 +16,6 @@ import { DEFAULT_ROOT_MAX_BYTES } from "./root-impl.js";
|
|
|
15
16
|
import { matchRootFileOpenFailure, openRootFileSync } from "./root-file.js";
|
|
16
17
|
import { writeSecretFileAtomic } from "./secret-file.js";
|
|
17
18
|
import { assertNoWindowsPathAlias, resolvePathPreservingWindowsRoot, } from "./windows-path-alias.js";
|
|
18
|
-
function snapshotWriteOptions(options, durabilityFirst = true) {
|
|
19
|
-
if (options == null)
|
|
20
|
-
return undefined;
|
|
21
|
-
return durabilityFirst ? {
|
|
22
|
-
maxBytes: options.maxBytes,
|
|
23
|
-
durable: options.durable,
|
|
24
|
-
dirMode: options.dirMode,
|
|
25
|
-
mode: options.mode,
|
|
26
|
-
} : {
|
|
27
|
-
maxBytes: options.maxBytes,
|
|
28
|
-
dirMode: options.dirMode,
|
|
29
|
-
mode: options.mode,
|
|
30
|
-
durable: options.durable,
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
19
|
function isNotFound(error) {
|
|
34
20
|
return error instanceof FsSafeError ? error.code === "not-found" : isNotFoundPathError(error);
|
|
35
21
|
}
|
|
@@ -72,6 +58,7 @@ async function copyIntoRoot(params) {
|
|
|
72
58
|
await ensureParentInRoot(scopedRoot, relativePath, params.dirMode);
|
|
73
59
|
await scopedRoot.copyIn(literalStoreRootPath(relativePath), params.sourcePath, {
|
|
74
60
|
durable: params.durable,
|
|
61
|
+
allowDrvfsRenameRecovery: params.allowDrvfsRenameRecovery,
|
|
75
62
|
maxBytes: params.maxBytes,
|
|
76
63
|
mkdir: false,
|
|
77
64
|
mode: params.mode,
|
|
@@ -84,6 +71,7 @@ export function fileStore(options) {
|
|
|
84
71
|
const rootDir = resolvePathPreservingWindowsRoot(rootDirInput);
|
|
85
72
|
assertNoWindowsPathAlias(rootDir, "filesystem", "store root uses a Windows filesystem namespace alias");
|
|
86
73
|
const privateMode = options.private ?? false;
|
|
74
|
+
const allowDrvfsRenameRecovery = options.allowDrvfsRenameRecovery;
|
|
87
75
|
const dirMode = options.dirMode ?? 0o700;
|
|
88
76
|
if (privateMode)
|
|
89
77
|
rejectPrivateDirectoryPreservation(dirMode);
|
|
@@ -103,6 +91,7 @@ export function fileStore(options) {
|
|
|
103
91
|
rootDir,
|
|
104
92
|
filePath: destination,
|
|
105
93
|
content,
|
|
94
|
+
allowDrvfsRenameRecovery: writeOptions?.allowDrvfsRenameRecovery ?? allowDrvfsRenameRecovery,
|
|
106
95
|
durable: writeOptions?.durable ?? durable,
|
|
107
96
|
dirMode: writeOptions?.dirMode ?? dirMode,
|
|
108
97
|
mode: writeOptions?.mode ?? mode,
|
|
@@ -122,6 +111,7 @@ export function fileStore(options) {
|
|
|
122
111
|
mkdir: false,
|
|
123
112
|
mode: writeMode,
|
|
124
113
|
durable: writeDurable,
|
|
114
|
+
allowDrvfsRenameRecovery: writeOptions?.allowDrvfsRenameRecovery ?? allowDrvfsRenameRecovery,
|
|
125
115
|
});
|
|
126
116
|
return destination;
|
|
127
117
|
}
|
|
@@ -151,6 +141,7 @@ export function fileStore(options) {
|
|
|
151
141
|
filePath: destination,
|
|
152
142
|
content: Buffer.concat(chunks),
|
|
153
143
|
durable: writeDurable,
|
|
144
|
+
allowDrvfsRenameRecovery: writeOptions?.allowDrvfsRenameRecovery ?? allowDrvfsRenameRecovery,
|
|
154
145
|
dirMode: writeDirMode,
|
|
155
146
|
mode: writeMode,
|
|
156
147
|
});
|
|
@@ -170,6 +161,7 @@ export function fileStore(options) {
|
|
|
170
161
|
relativePath,
|
|
171
162
|
sourcePath: staged.path,
|
|
172
163
|
durable: writeDurable,
|
|
164
|
+
allowDrvfsRenameRecovery: writeOptions?.allowDrvfsRenameRecovery ?? allowDrvfsRenameRecovery,
|
|
173
165
|
maxBytes: limit,
|
|
174
166
|
mode: writeMode,
|
|
175
167
|
tempPrefix: writeOptions?.tempPrefix,
|
|
@@ -187,6 +179,7 @@ export function fileStore(options) {
|
|
|
187
179
|
const policy = writeOptions == null
|
|
188
180
|
? undefined
|
|
189
181
|
: {
|
|
182
|
+
allowDrvfsRenameRecovery: writeOptions?.allowDrvfsRenameRecovery,
|
|
190
183
|
maxBytes: configuredLimit,
|
|
191
184
|
durable: writeOptions?.durable,
|
|
192
185
|
dirMode: writeOptions?.dirMode,
|
|
@@ -203,6 +196,7 @@ export function fileStore(options) {
|
|
|
203
196
|
relativePath,
|
|
204
197
|
sourcePath,
|
|
205
198
|
durable: writeOptions?.durable ?? durable,
|
|
199
|
+
allowDrvfsRenameRecovery: writeOptions?.allowDrvfsRenameRecovery ?? allowDrvfsRenameRecovery,
|
|
206
200
|
dirMode: writeOptions?.dirMode ?? dirMode,
|
|
207
201
|
maxBytes: configuredLimit,
|
|
208
202
|
mode: writeOptions?.mode ?? mode,
|
|
@@ -276,7 +270,7 @@ export function fileStore(options) {
|
|
|
276
270
|
readRequired: async () => await (await openRoot()).readJson(literalStoreRootPath(relativePath)),
|
|
277
271
|
write: async (value, options) => {
|
|
278
272
|
const json = stringifyJsonDocument(value, null, 2);
|
|
279
|
-
await write(relativePath, options?.trailingNewline === false ? json : `${json}\n`, { durable: options?.durable });
|
|
273
|
+
await write(relativePath, options?.trailingNewline === false ? json : `${json}\n`, { durable: options?.durable, allowDrvfsRenameRecovery: options?.allowDrvfsRenameRecovery });
|
|
280
274
|
},
|
|
281
275
|
}, jsonOptions);
|
|
282
276
|
},
|
|
@@ -291,6 +285,7 @@ export function fileStoreSync(options) {
|
|
|
291
285
|
const rootDir = resolvePathPreservingWindowsRoot(rootDirInput);
|
|
292
286
|
assertNoWindowsPathAlias(rootDir, "filesystem", "store root uses a Windows filesystem namespace alias");
|
|
293
287
|
const privateMode = options.private ?? false;
|
|
288
|
+
const allowDrvfsRenameRecovery = options.allowDrvfsRenameRecovery;
|
|
294
289
|
const dirMode = options.dirMode ?? 0o700;
|
|
295
290
|
if (privateMode)
|
|
296
291
|
rejectPrivateDirectoryPreservation(dirMode);
|
|
@@ -307,6 +302,7 @@ export function fileStoreSync(options) {
|
|
|
307
302
|
filePath: destination,
|
|
308
303
|
content,
|
|
309
304
|
privateMode,
|
|
305
|
+
allowDrvfsRenameRecovery: writeOptions?.allowDrvfsRenameRecovery ?? allowDrvfsRenameRecovery,
|
|
310
306
|
durable: writeOptions?.durable ?? durable,
|
|
311
307
|
dirMode: writeOptions?.dirMode ?? dirMode,
|
|
312
308
|
mode: writeOptions?.mode ?? mode,
|
|
@@ -5,7 +5,7 @@ export const GUEST_FILESYSTEM_CREATE_STAGING_PYTHON = [
|
|
|
5
5
|
" # also rewrite the destination immediately after publication.",
|
|
6
6
|
" prefix = '.openclaw-create-'",
|
|
7
7
|
" for _ in range(128):",
|
|
8
|
-
" candidate = prefix +
|
|
8
|
+
" candidate = prefix + os.urandom(6).hex()",
|
|
9
9
|
" try:",
|
|
10
10
|
" os.mkdir(candidate, 0o700, dir_fd=parent_fd)",
|
|
11
11
|
" except FileExistsError:",
|
|
@@ -13,7 +13,6 @@ export const GUEST_FILESYSTEM_PYTHON = [
|
|
|
13
13
|
"import errno",
|
|
14
14
|
"import json",
|
|
15
15
|
"import os",
|
|
16
|
-
"import secrets",
|
|
17
16
|
"import stat",
|
|
18
17
|
"import sys",
|
|
19
18
|
"",
|
|
@@ -72,7 +71,7 @@ export const GUEST_FILESYSTEM_PYTHON = [
|
|
|
72
71
|
"def create_temp_file(parent_fd):",
|
|
73
72
|
" prefix = '.openclaw-write-'",
|
|
74
73
|
" for _ in range(128):",
|
|
75
|
-
" candidate = prefix +
|
|
74
|
+
" candidate = prefix + os.urandom(6).hex()",
|
|
76
75
|
" try:",
|
|
77
76
|
" fd = os.open(candidate, WRITE_FLAGS, 0o600, dir_fd=parent_fd)",
|
|
78
77
|
" return candidate, fd",
|
|
@@ -83,7 +82,7 @@ export const GUEST_FILESYSTEM_PYTHON = [
|
|
|
83
82
|
"def create_temp_dir(parent_fd, mode):",
|
|
84
83
|
" prefix = '.openclaw-move-'",
|
|
85
84
|
" for _ in range(128):",
|
|
86
|
-
" candidate = prefix +
|
|
85
|
+
" candidate = prefix + os.urandom(6).hex()",
|
|
87
86
|
" try:",
|
|
88
87
|
" os.mkdir(candidate, mode, dir_fd=parent_fd)",
|
|
89
88
|
" return candidate",
|
|
@@ -152,7 +151,7 @@ export const GUEST_FILESYSTEM_PYTHON = [
|
|
|
152
151
|
" temp_name = None",
|
|
153
152
|
" try:",
|
|
154
153
|
" for _ in range(128):",
|
|
155
|
-
" candidate = prefix +
|
|
154
|
+
" candidate = prefix + os.urandom(6).hex()",
|
|
156
155
|
" try:",
|
|
157
156
|
" copy_regular_file(src_parent_fd, src_basename, dst_parent_fd, candidate)",
|
|
158
157
|
" temp_name = candidate",
|
|
@@ -4,6 +4,7 @@ export type JsonStoreLockOptions = Partial<FsSafeLockConfig & {
|
|
|
4
4
|
managerKey: string;
|
|
5
5
|
}>;
|
|
6
6
|
export type JsonFileStoreOptions = {
|
|
7
|
+
allowDrvfsRenameRecovery?: boolean;
|
|
7
8
|
/** Overrides the parent store's durability for every JSON mutation. */
|
|
8
9
|
durable?: boolean;
|
|
9
10
|
trailingNewline?: boolean;
|
|
@@ -27,6 +28,7 @@ export type JsonStoreAdapter<T> = {
|
|
|
27
28
|
write(value: T, options?: {
|
|
28
29
|
trailingNewline?: boolean;
|
|
29
30
|
durable?: boolean;
|
|
31
|
+
allowDrvfsRenameRecovery?: boolean;
|
|
30
32
|
}): Promise<void>;
|
|
31
33
|
};
|
|
32
34
|
export declare function createJsonStore<T>(adapter: JsonStoreAdapter<T>, options?: JsonFileStoreOptions): JsonStore<T>;
|
|
@@ -39,6 +39,7 @@ export function createJsonStore(adapter, options = {}) {
|
|
|
39
39
|
return {
|
|
40
40
|
trailingNewline: options.trailingNewline ?? true,
|
|
41
41
|
durable: options.durable,
|
|
42
|
+
allowDrvfsRenameRecovery: options.allowDrvfsRenameRecovery,
|
|
42
43
|
};
|
|
43
44
|
}
|
|
44
45
|
async function withSerializedMutation(run) {
|
|
@@ -9,6 +9,7 @@ export function jsonStore(options) {
|
|
|
9
9
|
return fileStore({
|
|
10
10
|
rootDir: path.dirname(filePath),
|
|
11
11
|
private: true,
|
|
12
|
+
allowDrvfsRenameRecovery: options.allowDrvfsRenameRecovery,
|
|
12
13
|
mode: options.mode,
|
|
13
14
|
dirMode: options.dirMode,
|
|
14
15
|
}).json(path.basename(filePath), options);
|
|
@@ -5,7 +5,10 @@ export type ReadJsonOptions = {
|
|
|
5
5
|
maxBytes?: number;
|
|
6
6
|
};
|
|
7
7
|
export declare function tryReadJsonSync<T = unknown>(pathname: string, options?: ReadJsonOptions): T | null;
|
|
8
|
-
export
|
|
8
|
+
export type WriteJsonSyncOptions = {
|
|
9
|
+
allowDrvfsRenameRecovery?: boolean;
|
|
10
|
+
};
|
|
11
|
+
export declare function writeJsonSync(pathname: string, data: unknown, options?: WriteJsonSyncOptions): void;
|
|
9
12
|
export declare class JsonFileReadError extends Error {
|
|
10
13
|
readonly filePath: string;
|
|
11
14
|
readonly reason: "read" | "parse";
|
|
@@ -45,5 +48,5 @@ export declare function tryReadJson<T>(filePath: string, options?: ReadJsonOptio
|
|
|
45
48
|
export declare function readJson<T>(filePath: string, options?: ReadJsonOptions): Promise<T>;
|
|
46
49
|
export declare function readJsonIfExists<T>(filePath: string, options?: ReadJsonOptions): Promise<T | null>;
|
|
47
50
|
export declare function readJsonSync<T = unknown>(filePath: string, options?: ReadJsonOptions): T;
|
|
48
|
-
export type WriteJsonOptions = Pick<WriteTextAtomicOptions, "dirMode" | "durable" | "mode" | "trailingNewline">;
|
|
51
|
+
export type WriteJsonOptions = Pick<WriteTextAtomicOptions, "dirMode" | "durable" | "mode" | "trailingNewline" | "allowDrvfsRenameRecovery">;
|
|
49
52
|
export declare function writeJson(filePath: string, value: unknown, options?: WriteJsonOptions): Promise<void>;
|
|
@@ -88,7 +88,8 @@ export function tryReadJsonSync(pathname, options = {}) {
|
|
|
88
88
|
return null;
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
|
-
export function writeJsonSync(pathname, data) {
|
|
91
|
+
export function writeJsonSync(pathname, data, options) {
|
|
92
|
+
const allowDrvfsRenameRecovery = options?.allowDrvfsRenameRecovery === true;
|
|
92
93
|
const filePath = admitStandalonePublicationPath(pathname);
|
|
93
94
|
// Keep literal parent segments so staging follows the same symlinks as the target.
|
|
94
95
|
const tmpPath = path.format({ ...path.parse(filePath), base: `.fs-safe-${randomUUID()}.tmp` });
|
|
@@ -107,10 +108,12 @@ export function writeJsonSync(pathname, data) {
|
|
|
107
108
|
runSync(owner.assertCurrent());
|
|
108
109
|
trySetSecureMode(temp.file.fd);
|
|
109
110
|
fsSync.fsyncSync(temp.file.fd);
|
|
111
|
+
if (allowDrvfsRenameRecovery)
|
|
112
|
+
runSync(owner.prepareRecovery(payload, path.dirname(filePath)));
|
|
110
113
|
renameJsonFileWithFallback(owner, filePath);
|
|
111
114
|
owner.markRenamed();
|
|
112
115
|
runSync(owner.assertPublished(filePath));
|
|
113
|
-
trySetSecureMode(
|
|
116
|
+
trySetSecureMode(owner.fd);
|
|
114
117
|
runSync(syncDirectoryBestEffort(io, path.dirname(filePath)));
|
|
115
118
|
runSync(owner.assertPublished(filePath));
|
|
116
119
|
}
|
|
@@ -300,6 +303,7 @@ export async function writeJson(filePath, value, options) {
|
|
|
300
303
|
mode: options?.mode,
|
|
301
304
|
dirMode: options?.dirMode,
|
|
302
305
|
trailingNewline: options?.trailingNewline,
|
|
306
|
+
allowDrvfsRenameRecovery: options?.allowDrvfsRenameRecovery,
|
|
303
307
|
durable: options?.durable,
|
|
304
308
|
});
|
|
305
309
|
}
|
|
@@ -6,7 +6,7 @@ import { recordFileOpenFailure, recordPreOpenFileChange } from "./opened-file-fa
|
|
|
6
6
|
import { assertNoUnsafeDeviceReadPath, hasNodeErrorCode, isNotFoundPathError, isSymlinkOpenError, } from "./path.js";
|
|
7
7
|
import { resolveReadOpenFlags } from "./read-open-flags.js";
|
|
8
8
|
import { fileNotFoundError, hardlinkedPathNotAllowedError } from "./root-errors.js";
|
|
9
|
-
import { inspectFileIdentitySync } from "./strict-file-identity.js";
|
|
9
|
+
import { inspectFileIdentity, inspectFileIdentitySync } from "./strict-file-identity.js";
|
|
10
10
|
import { getFsSafeTestHooks } from "./test-hooks.js";
|
|
11
11
|
const OPEN_READ_FLAGS = resolveReadOpenFlags();
|
|
12
12
|
const OPEN_READ_FOLLOW_FLAGS = resolveReadOpenFlags({ followSymlinks: true });
|
|
@@ -20,8 +20,7 @@ export async function openLocalFileDescriptor(filePath, options) {
|
|
|
20
20
|
// Reject directories before opening so we never surface EISDIR to callers (e.g. tool
|
|
21
21
|
// results that get sent to messaging channels). See openclaw/openclaw#31186.
|
|
22
22
|
try {
|
|
23
|
-
|
|
24
|
-
const stat = fsSync.lstatSync(filePath, { bigint: true });
|
|
23
|
+
const inspect = (stat) => {
|
|
25
24
|
observedBeforeOpen = true;
|
|
26
25
|
if (stat.isSymbolicLink() && options?.symlinks !== "follow-within-root") {
|
|
27
26
|
throw new FsSafeError("symlink", "symlink not allowed");
|
|
@@ -30,7 +29,10 @@ export async function openLocalFileDescriptor(filePath, options) {
|
|
|
30
29
|
throw new FsSafeError("not-file", "not a file");
|
|
31
30
|
}
|
|
32
31
|
return stat;
|
|
33
|
-
}
|
|
32
|
+
};
|
|
33
|
+
preOpenStat = process.platform === "win32"
|
|
34
|
+
? inspectFileIdentitySync(() => inspect(fsSync.lstatSync(filePath, { bigint: true })))
|
|
35
|
+
: await inspectFileIdentity(async () => inspect(await fs.lstat(filePath, { bigint: true })));
|
|
34
36
|
}
|
|
35
37
|
catch (err) {
|
|
36
38
|
if (err instanceof FsSafeError || observedBeforeOpen) {
|
|
@@ -67,15 +69,19 @@ export async function openLocalFileDescriptor(filePath, options) {
|
|
|
67
69
|
let openedIdentity;
|
|
68
70
|
let identity;
|
|
69
71
|
try {
|
|
70
|
-
|
|
71
|
-
openedIdentity =
|
|
72
|
-
if (!
|
|
72
|
+
const inspect = (stat) => {
|
|
73
|
+
openedIdentity = stat;
|
|
74
|
+
if (!stat.isFile())
|
|
73
75
|
throw new FsSafeError("not-file", "not a file");
|
|
74
|
-
return
|
|
75
|
-
}
|
|
76
|
+
return stat;
|
|
77
|
+
};
|
|
78
|
+
const expected = preOpenStat && !preOpenStat.isSymbolicLink() ? preOpenStat : undefined;
|
|
79
|
+
identity = process.platform === "win32"
|
|
80
|
+
? inspectFileIdentitySync(() => inspect(fsSync.fstatSync(handle.fd, { bigint: true })), expected)
|
|
81
|
+
: await inspectFileIdentity(async () => inspect(await handle.stat({ bigint: true })), expected);
|
|
76
82
|
}
|
|
77
83
|
catch (error) {
|
|
78
|
-
if (openedIdentity && [0n, 1n].includes(openedIdentity.nlink)) {
|
|
84
|
+
if (openedIdentity && [0n, 1n, 2n].includes(openedIdentity.nlink)) {
|
|
79
85
|
await recordPreOpenFileChange(error, handle, filePath, preOpenStat, openedIdentity);
|
|
80
86
|
}
|
|
81
87
|
throw error;
|
|
@@ -219,6 +219,10 @@ export interface NativeBinding {
|
|
|
219
219
|
path?: string;
|
|
220
220
|
errno?: number;
|
|
221
221
|
};
|
|
222
|
+
canonicalizePathAsync?(path: string, ordinary: boolean): Promise<{
|
|
223
|
+
path?: string;
|
|
224
|
+
errno?: number;
|
|
225
|
+
}>;
|
|
222
226
|
/** Internal Windows normalized name resolution after a denied DOS-name query. */
|
|
223
227
|
resolveWindowsCanonicalPath?(path: string): string | null;
|
|
224
228
|
/** Internal immutable primary-token membership, cached across Workers. */
|
|
@@ -305,6 +309,8 @@ export interface NativeBinding {
|
|
|
305
309
|
/** Local filesystem admission for one-way cooperative entry publication. */
|
|
306
310
|
retainWindowsEntryPublication?(sourcePath: string, name: string, sourceDev: bigint, sourceIno: bigint, targetPath: string, targetName: string, targetDev: bigint, targetIno: bigint, dev: bigint, ino: bigint, kind: "file" | "directory" | "symlink"): NativeWindowsEntryPublication;
|
|
307
311
|
entryPublicationFilesystem?(parentFd: number): string;
|
|
312
|
+
/** Internal negative-only DrvFS preparation probe; never grants recovery. */
|
|
313
|
+
is9pFilesystem?(parentFd: number): boolean;
|
|
308
314
|
publishRetainedEntryNoReplace?(sourceParentFd: number, sourceBasename: string, sourceFd: number, targetParentFd: number, targetBasename: string): NativePublicationTransition;
|
|
309
315
|
renameNoReplace?(...args: NativeTwoPathArgs): void;
|
|
310
316
|
/** Linux auto-mode fallback through already-admitted direct-child parents. */
|
|
@@ -60,6 +60,7 @@ import { assertNativeCapabilities, getNativeBinding } from "./native.js";
|
|
|
60
60
|
import { captureNativeFdClose } from "./native-binding.js";
|
|
61
61
|
import { cachedNoReplaceUnavailable } from "./native-noreplace.js";
|
|
62
62
|
import { isFsSafeNativeRequired } from "./native-config.js";
|
|
63
|
+
import { writeSidecarAtParent } from "./sidecar-lock-write.js";
|
|
63
64
|
import { copyLinkAtParent } from "./copy-link.js";
|
|
64
65
|
const writeCapabilities = ["openBeneath", "mkdirBeneath", "renameNoReplace", "renameReplace"];
|
|
65
66
|
const posixWriteCapabilities = [...writeCapabilities, "createStagedFile", "stagedFileMatches", "removeStagedFile", "renameReplaceAsync", "renameNoReplaceAsync"];
|
|
@@ -142,6 +143,9 @@ export async function runPinnedWriteNative(binding, params, fallback) {
|
|
|
142
143
|
}
|
|
143
144
|
}
|
|
144
145
|
}
|
|
146
|
+
if (params.input.kind === "buffer" && params.input.sidecar) {
|
|
147
|
+
return await writeSidecarAtParent(params, verificationGuard, { fd: parentFd, binding });
|
|
148
|
+
}
|
|
145
149
|
if (windows) {
|
|
146
150
|
// The Windows leaf owns both directories after admission.
|
|
147
151
|
windowsOwnsDirectories = true;
|
|
@@ -1,3 +1,23 @@
|
|
|
1
|
+
import type { StagedFileReceipt } from "./staged-file-types.js";
|
|
1
2
|
import type { NativeBinding } from "./native-binding.js";
|
|
2
3
|
/** Exact nonprivate stage facts from one fresh named/retained observation. */
|
|
3
4
|
export declare function nativeStagedFileMode(binding: NativeBinding, parentFd: number, name: string, fd: number, expectedMode?: number): number | undefined;
|
|
5
|
+
export type NativeStagingBinding = NativeBinding & Required<Pick<NativeBinding, "createStagedFile" | "stagedFileMatches" | "removeStagedFile" | "renameReplaceAsync" | "renameNoReplaceAsync">>;
|
|
6
|
+
export declare function assertNativeStaging(binding: NativeBinding): asserts binding is NativeStagingBinding;
|
|
7
|
+
export declare function assertStagedFileBasename(name: string, portable: boolean): void;
|
|
8
|
+
type StagedPermissionPolicy = "private-creation" | "mode-only";
|
|
9
|
+
export type NativeStageOwner = Readonly<{
|
|
10
|
+
binding: NativeStagingBinding;
|
|
11
|
+
parentFd: number;
|
|
12
|
+
closeParentFd: (fd: number) => void;
|
|
13
|
+
directory: StagedFileReceipt["directory"];
|
|
14
|
+
portableNames?: boolean;
|
|
15
|
+
mode: number;
|
|
16
|
+
sync?: boolean;
|
|
17
|
+
allowDrvfsRenameRecovery?: boolean;
|
|
18
|
+
strictFileSync?: boolean;
|
|
19
|
+
assertBeforeMutation?: () => void;
|
|
20
|
+
permissionPolicy?: StagedPermissionPolicy;
|
|
21
|
+
name?: string;
|
|
22
|
+
}>;
|
|
23
|
+
export {};
|
|
@@ -14,3 +14,21 @@ export function nativeStagedFileMode(binding, parentFd, name, fd, expectedMode)
|
|
|
14
14
|
}
|
|
15
15
|
return mode;
|
|
16
16
|
}
|
|
17
|
+
export function assertNativeStaging(binding) {
|
|
18
|
+
if ([
|
|
19
|
+
binding.closeOwnedFd,
|
|
20
|
+
binding.createStagedFile,
|
|
21
|
+
binding.stagedFileMatches,
|
|
22
|
+
binding.removeStagedFile,
|
|
23
|
+
binding.renameReplaceAsync,
|
|
24
|
+
binding.renameNoReplaceAsync,
|
|
25
|
+
].some((fn) => typeof fn !== "function")) {
|
|
26
|
+
throw new FsSafeError("helper-unavailable", "native retained-directory staging is unavailable");
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export function assertStagedFileBasename(name, portable) {
|
|
30
|
+
if (!name || name === "." || name === ".." || name.includes("/") || name.includes("\0") ||
|
|
31
|
+
(portable && /[\\:\u0000-\u001f\u007f-\u009f\u2028\u2029]/u.test(name))) {
|
|
32
|
+
throw new FsSafeError("invalid-path", "publication requires one direct-child basename");
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -2,25 +2,10 @@ import type { DirectoryReceipt } from "./directory-durability.js";
|
|
|
2
2
|
import { type BigIntStats, type Stats } from "node:fs";
|
|
3
3
|
import type { AnyAsyncDirectoryGuard } from "./directory-guard.js";
|
|
4
4
|
import type { FileIdentityStat } from "./file-identity.js";
|
|
5
|
-
import { type
|
|
5
|
+
import { type NativeStagingBinding, type NativeStageOwner } from "./native-staged-file-metadata.js";
|
|
6
6
|
import type { PinnedWriteInput, PinnedWriteParams } from "./pinned-write-types.js";
|
|
7
7
|
import type { PublishedFileReceipt, StagedFile, StagedFileCleanupReceipt, StagedFileReceipt } from "./staged-file-types.js";
|
|
8
|
-
export
|
|
9
|
-
export declare function assertNativeStaging(binding: NativeBinding): asserts binding is NativeStagingBinding;
|
|
10
|
-
type StagedPermissionPolicy = "private-creation" | "mode-only";
|
|
11
|
-
type NativeStageOwner = Readonly<{
|
|
12
|
-
binding: NativeStagingBinding;
|
|
13
|
-
parentFd: number;
|
|
14
|
-
closeParentFd: (fd: number) => void;
|
|
15
|
-
directory: StagedFileReceipt["directory"];
|
|
16
|
-
portableNames?: boolean;
|
|
17
|
-
mode: number;
|
|
18
|
-
sync?: boolean;
|
|
19
|
-
strictFileSync?: boolean;
|
|
20
|
-
assertBeforeMutation?: () => void;
|
|
21
|
-
permissionPolicy?: StagedPermissionPolicy;
|
|
22
|
-
name?: string;
|
|
23
|
-
}>;
|
|
8
|
+
export { assertNativeStaging, type NativeStagingBinding } from "./native-staged-file-metadata.js";
|
|
24
9
|
declare class NativeStagedFile implements StagedFile {
|
|
25
10
|
#private;
|
|
26
11
|
constructor(owner: NativeStageOwner);
|
|
@@ -39,7 +24,7 @@ export declare const writeNativeStage: typeof NativeStagedFile.write;
|
|
|
39
24
|
export declare function stageFileInDirectory(options: {
|
|
40
25
|
directory: string | DirectoryReceipt<Stats | BigIntStats>;
|
|
41
26
|
content: string | Uint8Array;
|
|
27
|
+
allowDrvfsRenameRecovery?: boolean;
|
|
42
28
|
/** Published mode; the unpublished stage stays at 0600. Defaults to 0600. */
|
|
43
29
|
mode?: number;
|
|
44
30
|
}): Promise<StagedFile>;
|
|
45
|
-
export {};
|
|
@@ -60,7 +60,7 @@ import { FsSafeError } from "./errors.js";
|
|
|
60
60
|
import { assertSynchronousCallbackResult, isMutationAuthorityError } from "./mutation-authority.js";
|
|
61
61
|
import { captureNativeFdClose } from "./native-binding.js";
|
|
62
62
|
import { replayPinnedInput, writePinnedInput } from "./pinned-write-input.js";
|
|
63
|
-
import { nativeStagedFileMode } from "./native-staged-file-metadata.js";
|
|
63
|
+
import { assertNativeStaging, assertStagedFileBasename, nativeStagedFileMode } from "./native-staged-file-metadata.js";
|
|
64
64
|
import { assertNativeCopyCompleted, createNativeCopyFile } from "./copy-file-input.js";
|
|
65
65
|
import { assertNativeStagedDirectoryCurrent, openStagedDirectory } from "./staged-directory.js";
|
|
66
66
|
import { assertFinalSymlinkRejected } from "./root-symlink-policy.js";
|
|
@@ -70,24 +70,9 @@ import { noReplaceUnavailable, rememberNoReplaceUnavailable } from "./native-nor
|
|
|
70
70
|
import { isFsSafeNativeRequired } from "./native-config.js";
|
|
71
71
|
import { restoreCopyMetadata } from "./copy-metadata.js";
|
|
72
72
|
import { annotateReadOnlyOpenError } from "./file-open-error.js";
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
binding.createStagedFile,
|
|
77
|
-
binding.stagedFileMatches,
|
|
78
|
-
binding.removeStagedFile,
|
|
79
|
-
binding.renameReplaceAsync,
|
|
80
|
-
binding.renameNoReplaceAsync,
|
|
81
|
-
].some((fn) => typeof fn !== "function")) {
|
|
82
|
-
throw new FsSafeError("helper-unavailable", "native retained-directory staging is unavailable");
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
function assertBasename(name, portable) {
|
|
86
|
-
if (!name || name === "." || name === ".." || name.includes("/") || name.includes("\0") ||
|
|
87
|
-
(portable && /[\\:\u0000-\u001f\u007f-\u009f\u2028\u2029]/u.test(name))) {
|
|
88
|
-
throw new FsSafeError("invalid-path", "publication requires one direct-child basename");
|
|
89
|
-
}
|
|
90
|
-
}
|
|
73
|
+
import { hasErrorCode } from "./file-cleanup.js";
|
|
74
|
+
import { reopenRecoveredNativeFile, assertRecoveredPublication, recoverAfterHiddenRenameSync, shouldPrepareDrvfsRecovery, mayPrepareDrvfsRecoveryAtFd } from "./publication-recovery.js";
|
|
75
|
+
export { assertNativeStaging } from "./native-staged-file-metadata.js";
|
|
91
76
|
const NOT_PUBLISHED = Object.freeze({ status: "not-published" });
|
|
92
77
|
class NativeStagedFile {
|
|
93
78
|
#owner;
|
|
@@ -97,6 +82,10 @@ class NativeStagedFile {
|
|
|
97
82
|
#verifyMode;
|
|
98
83
|
#state = { status: "open", publication: NOT_PUBLISHED };
|
|
99
84
|
#receipt;
|
|
85
|
+
#recoveryIdentity;
|
|
86
|
+
#recoveryContent;
|
|
87
|
+
#recovered = false;
|
|
88
|
+
#prepareRecovery;
|
|
100
89
|
#publicationTask;
|
|
101
90
|
#rejectFinalSymlink = false;
|
|
102
91
|
#unsupportedNoReplace;
|
|
@@ -104,14 +93,15 @@ class NativeStagedFile {
|
|
|
104
93
|
#fallbackCleanupError;
|
|
105
94
|
constructor(owner) {
|
|
106
95
|
const name = owner.name ?? `.fs-safe-${randomUUID()}.tmp`;
|
|
107
|
-
|
|
96
|
+
assertStagedFileBasename(name, owner.portableNames !== false);
|
|
108
97
|
this.#closeFd = captureNativeFdClose(owner.binding);
|
|
109
98
|
this.#owner = { ...owner, name };
|
|
110
99
|
this.#assertBeforeMutation = owner.assertBeforeMutation;
|
|
111
100
|
this.#private = owner.permissionPolicy === "private-creation";
|
|
112
101
|
this.#verifyMode = owner.permissionPolicy !== undefined;
|
|
102
|
+
this.#prepareRecovery = shouldPrepareDrvfsRecovery(owner.allowDrvfsRenameRecovery, owner.directory.identity.dev) &&
|
|
103
|
+
mayPrepareDrvfsRecoveryAtFd(owner.parentFd, owner.directory.identity.dev);
|
|
113
104
|
}
|
|
114
|
-
// Public staging supplies a Node parent; pinned writes supply a native parent.
|
|
115
105
|
// The supplied closer owns parentFd even on construction or preparation failure.
|
|
116
106
|
static async create(owner, input, maxBytes) {
|
|
117
107
|
let staged;
|
|
@@ -127,6 +117,9 @@ class NativeStagedFile {
|
|
|
127
117
|
}
|
|
128
118
|
throw error;
|
|
129
119
|
}
|
|
120
|
+
if (staged.#prepareRecovery && input.kind === "buffer") {
|
|
121
|
+
staged.#recoveryContent = typeof input.data === "string" ? Buffer.from(input.data, input.encoding) : Buffer.from(input.data);
|
|
122
|
+
}
|
|
130
123
|
await staged.#prepare(input, maxBytes);
|
|
131
124
|
return staged;
|
|
132
125
|
}
|
|
@@ -137,6 +130,7 @@ class NativeStagedFile {
|
|
|
137
130
|
// This owner never escapes; only the internal verifier borrows its fd.
|
|
138
131
|
const staged = __addDisposableResource(env_1, await NativeStagedFile.create({
|
|
139
132
|
binding, parentFd, closeParentFd, directory, mode: params.mode, sync: params.sync,
|
|
133
|
+
allowDrvfsRenameRecovery: params.allowDrvfsRenameRecovery,
|
|
140
134
|
// Public staging uses portable names; existing POSIX writes accept literal names.
|
|
141
135
|
portableNames: false, assertBeforeMutation: params.assertBeforeMutation,
|
|
142
136
|
name: exclusive ? params.basename : undefined, strictFileSync: params.strictFileSync,
|
|
@@ -225,6 +219,8 @@ class NativeStagedFile {
|
|
|
225
219
|
}
|
|
226
220
|
#assertNamed(name, expectedMode) {
|
|
227
221
|
const fd = this.#file();
|
|
222
|
+
if (this.#recovered)
|
|
223
|
+
assertRecoveredPublication(fs.fstatSync(fd, { bigint: true }), this.#recoveryIdentity);
|
|
228
224
|
const mode = !this.#private ? nativeStagedFileMode(this.#owner.binding, this.#owner.parentFd, name, fd, this.#verifyMode ? expectedMode : undefined) : undefined;
|
|
229
225
|
if (mode !== undefined)
|
|
230
226
|
return mode;
|
|
@@ -348,7 +344,7 @@ class NativeStagedFile {
|
|
|
348
344
|
const overwrite = options?.overwrite;
|
|
349
345
|
try {
|
|
350
346
|
const state = this.#open();
|
|
351
|
-
|
|
347
|
+
assertStagedFileBasename(basename, this.#owner.portableNames !== false);
|
|
352
348
|
if (basename === this.#owner.name || typeof overwrite !== "boolean") {
|
|
353
349
|
throw new FsSafeError("invalid-path", "publication needs a distinct basename and explicit overwrite policy");
|
|
354
350
|
}
|
|
@@ -359,6 +355,12 @@ class NativeStagedFile {
|
|
|
359
355
|
this.#assertCurrent();
|
|
360
356
|
assertFinalSymlinkRejected(path.join(this.#owner.directory.realPath, basename), this.#rejectFinalSymlink);
|
|
361
357
|
}
|
|
358
|
+
if (this.#prepareRecovery) {
|
|
359
|
+
// Apply restrictive modes before exposing the name or releasing its last fd.
|
|
360
|
+
if ((this.#owner.mode & 0o600) !== 0o600)
|
|
361
|
+
fs.fchmodSync(this.#file(), this.#owner.mode);
|
|
362
|
+
this.#recoveryIdentity = fs.fstatSync(this.#file(), { bigint: true });
|
|
363
|
+
}
|
|
362
364
|
try {
|
|
363
365
|
if (overwrite) {
|
|
364
366
|
await this.#owner.binding.renameReplaceAsync(this.#owner.parentFd, this.#owner.name, this.#owner.parentFd, basename);
|
|
@@ -403,13 +405,15 @@ class NativeStagedFile {
|
|
|
403
405
|
const receipt = Object.freeze({ status: "published", staged: this.receipt, basename, overwrite });
|
|
404
406
|
this.#open().publication = receipt;
|
|
405
407
|
onPublished?.(receipt.staged.identity);
|
|
406
|
-
const stagedMode = this.#
|
|
408
|
+
const stagedMode = this.#publishedMode(basename);
|
|
407
409
|
this.#assertDirectory();
|
|
408
410
|
// Keep contents private until the name passes its identity fence. Mode
|
|
409
411
|
// changes use the owned fd, including for final mode 000.
|
|
410
412
|
const fd = this.#file();
|
|
411
413
|
if (this.#owner.mode !== 0o600 || stagedMode !== 0o600)
|
|
412
414
|
fs.fchmodSync(fd, this.#owner.mode);
|
|
415
|
+
if (this.#recovered)
|
|
416
|
+
this.#recoveryIdentity.mode = (this.#recoveryIdentity.mode & ~4095n) | BigInt(this.#owner.mode);
|
|
413
417
|
// Content was synced during preparation. A lost chmod leaves 0600, no wider
|
|
414
418
|
// than modes retaining owner rw; restrictive modes still need a durable correction.
|
|
415
419
|
const verify = () => {
|
|
@@ -427,6 +431,26 @@ class NativeStagedFile {
|
|
|
427
431
|
return verify();
|
|
428
432
|
});
|
|
429
433
|
}
|
|
434
|
+
#publishedMode(basename) {
|
|
435
|
+
try {
|
|
436
|
+
return this.#assertNamed(basename, this.#recoveryIdentity ? Number(this.#recoveryIdentity.mode & 4095n) : 0o600);
|
|
437
|
+
}
|
|
438
|
+
catch (error) {
|
|
439
|
+
if (!hasErrorCode(error, "ENOENT") || !this.#recoveryIdentity)
|
|
440
|
+
throw error;
|
|
441
|
+
const state = this.#open();
|
|
442
|
+
const fd = this.#file();
|
|
443
|
+
return recoverAfterHiddenRenameSync({
|
|
444
|
+
parentFd: this.#owner.parentFd,
|
|
445
|
+
closeWriter: () => { state.fileFd = undefined; this.#closeFd(fd); this.#assertDirectory(); },
|
|
446
|
+
reopen: () => {
|
|
447
|
+
state.fileFd = reopenRecoveredNativeFile(this.#owner.binding, this.#owner.parentFd, basename, this.#recoveryIdentity, this.#recoveryContent);
|
|
448
|
+
this.#recovered = true;
|
|
449
|
+
return Number(this.#recoveryIdentity.mode & 4095n);
|
|
450
|
+
},
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
}
|
|
430
454
|
#finalize() {
|
|
431
455
|
if (this.#state.status === "closed") {
|
|
432
456
|
return this.#state;
|
|
@@ -480,7 +504,6 @@ class NativeStagedFile {
|
|
|
480
504
|
return this.#state;
|
|
481
505
|
}
|
|
482
506
|
async cleanup() {
|
|
483
|
-
// Native descriptors stay owned through the rename and all durability fences.
|
|
484
507
|
if (this.#publicationTask)
|
|
485
508
|
await this.#publicationTask.catch(() => { });
|
|
486
509
|
const closed = this.#finalize();
|
|
@@ -512,5 +535,6 @@ export async function stageFileInDirectory(options) {
|
|
|
512
535
|
return await createNativeStage({
|
|
513
536
|
binding, parentFd: parent.fd, closeParentFd: fs.closeSync,
|
|
514
537
|
directory: parent.receipt, mode, permissionPolicy: "mode-only",
|
|
538
|
+
allowDrvfsRenameRecovery: options.allowDrvfsRenameRecovery,
|
|
515
539
|
}, input);
|
|
516
540
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import fsSync, {} from "node:fs";
|
|
2
2
|
import { FsSafeError } from "./errors.js";
|
|
3
3
|
import { inspectFileIdentity } from "./strict-file-identity.js";
|
|
4
|
-
import { isFileObservationFailure, recordFileObservationFailure } from "./file-observation.js";
|
|
4
|
+
import { isFileObservationFailure, observedFilePublicationPending, recordFileObservationFailure } from "./file-observation.js";
|
|
5
5
|
export function recordFileOpenFailure(error, filePath) {
|
|
6
6
|
recordFileObservationFailure(error, `open:${filePath}`);
|
|
7
7
|
throw error;
|
|
@@ -16,15 +16,26 @@ export function openedPathResolutionError(error = new FsSafeError("path-mismatch
|
|
|
16
16
|
}
|
|
17
17
|
export async function recordPreOpenFileChange(error, handle, filePath, before, opened) {
|
|
18
18
|
if (!isFileObservationFailure(error, "identity") || !before?.isFile() || !opened?.isFile() ||
|
|
19
|
-
![0n, 1n].includes(before.nlink) || ![0n, 1n].includes(opened.nlink))
|
|
19
|
+
![0n, 1n].includes(before.nlink) || ![0n, 1n, 2n].includes(opened.nlink))
|
|
20
20
|
return;
|
|
21
21
|
try {
|
|
22
22
|
await inspectFileIdentity(async () => before);
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
// A fresh exact descriptor distinguishes a completed handoff from a
|
|
24
|
+
// still-linked generation that needs separate publication proof.
|
|
25
|
+
const inspectCurrent = () => inspectFileIdentity(() => process.platform === "win32"
|
|
26
|
+
? fsSync.fstatSync(handle.fd, { bigint: true }) : handle.stat({ bigint: true }), opened);
|
|
27
|
+
let current = await inspectCurrent();
|
|
28
|
+
let publication = false;
|
|
29
|
+
if (current.isFile() && current.nlink === 2n) {
|
|
30
|
+
publication = await observedFilePublicationPending(filePath, current);
|
|
31
|
+
current = await inspectCurrent();
|
|
32
|
+
}
|
|
33
|
+
if (current.isFile() && (before.dev !== current.dev || before.ino !== current.ino)) {
|
|
26
34
|
// A stale pathname sample is not proof that its former inode was unlinked.
|
|
27
|
-
|
|
35
|
+
if ([0n, 1n].includes(current.nlink))
|
|
36
|
+
recordFileObservationFailure(error, `changed:${filePath}`);
|
|
37
|
+
else if (current.nlink === 2n && publication)
|
|
38
|
+
recordFileObservationFailure(error, `linked-change:${filePath}`);
|
|
28
39
|
}
|
|
29
40
|
}
|
|
30
41
|
catch {
|
|
@@ -36,7 +47,8 @@ export async function recordOpenedFileFailure(error, handle, filePath, identity)
|
|
|
36
47
|
!identity.isFile() || identity.nlink > 1n)
|
|
37
48
|
return;
|
|
38
49
|
try {
|
|
39
|
-
const current = await inspectFileIdentity(() =>
|
|
50
|
+
const current = await inspectFileIdentity(() => process.platform === "win32"
|
|
51
|
+
? fsSync.fstatSync(handle.fd, { bigint: true }) : handle.stat({ bigint: true }), identity);
|
|
40
52
|
if (current.isFile() && current.nlink === 0n)
|
|
41
53
|
recordFileObservationFailure(error, `unlinked:${filePath}`);
|
|
42
54
|
}
|