@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,24 +1,28 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
|
+
import asyncFs from "node:fs/promises";
|
|
3
|
+
import { runAsync, runSync, wait } from "./atomic-io.js";
|
|
2
4
|
import { FsSafeError } from "./errors.js";
|
|
3
5
|
import { isExpectedPathError } from "./pinned-open.js";
|
|
4
|
-
import { realpathSync } from "./realpath.js";
|
|
6
|
+
import { realpathNative, realpathSync } from "./realpath.js";
|
|
5
7
|
import { admitPathInsideRoot } from "./root-boundary.js";
|
|
6
8
|
import { hardlinkedPathNotAllowedError } from "./root-errors.js";
|
|
7
|
-
import { inspectFileIdentitySync } from "./strict-file-identity.js";
|
|
9
|
+
import { inspectFileIdentity, inspectFileIdentitySync } from "./strict-file-identity.js";
|
|
8
10
|
import { assertNoWindowsPathAlias, pathForWindowsFilesystem } from "./windows-path-alias.js";
|
|
9
11
|
function rootIdentityMismatch(cause) {
|
|
10
12
|
return new FsSafeError("path-mismatch", "canonical root directory identity changed or could not be verified", cause === undefined ? {} : { cause });
|
|
11
13
|
}
|
|
12
|
-
function inspectCanonicalRoot(ioFs, rootPath, expected) {
|
|
14
|
+
function* inspectCanonicalRoot(ioFs, rootPath, expected, asynchronous = false) {
|
|
13
15
|
try {
|
|
14
16
|
assertNoWindowsPathAlias(rootPath);
|
|
15
17
|
const operationPath = ioFs === fs ? pathForWindowsFilesystem(rootPath) : rootPath;
|
|
16
|
-
|
|
17
|
-
const stat = ioFs.lstatSync(operationPath, { bigint: true });
|
|
18
|
+
const inspect = (stat) => {
|
|
18
19
|
if (!stat.isDirectory() || stat.isSymbolicLink())
|
|
19
20
|
throw rootIdentityMismatch();
|
|
20
21
|
return stat;
|
|
21
|
-
}
|
|
22
|
+
};
|
|
23
|
+
return asynchronous
|
|
24
|
+
? yield* wait(inspectFileIdentity(async () => inspect(await asyncFs.lstat(operationPath, { bigint: true })), expected))
|
|
25
|
+
: inspectFileIdentitySync(() => inspect(ioFs.lstatSync(operationPath, { bigint: true })), expected);
|
|
22
26
|
}
|
|
23
27
|
catch (error) {
|
|
24
28
|
if (expected && isExpectedPathError(error))
|
|
@@ -27,16 +31,23 @@ function inspectCanonicalRoot(ioFs, rootPath, expected) {
|
|
|
27
31
|
}
|
|
28
32
|
}
|
|
29
33
|
export function observeCanonicalRoot(ioFs, rootPath) {
|
|
34
|
+
return runSync(observeCanonicalRootProcedure(ioFs, rootPath, false));
|
|
35
|
+
}
|
|
36
|
+
export function observeCanonicalRootAsync(rootPath) {
|
|
37
|
+
return runAsync(observeCanonicalRootProcedure(fs, rootPath, true));
|
|
38
|
+
}
|
|
39
|
+
function* observeCanonicalRootProcedure(ioFs, rootPath, asynchronous) {
|
|
30
40
|
try {
|
|
31
|
-
const stat = inspectCanonicalRoot(ioFs, rootPath);
|
|
41
|
+
const stat = yield* inspectCanonicalRoot(ioFs, rootPath, undefined, asynchronous);
|
|
32
42
|
const identity = Object.freeze({ dev: stat.dev, ino: stat.ino });
|
|
33
43
|
let observedPath = rootPath;
|
|
34
44
|
if (ioFs === fs) {
|
|
35
45
|
// Match native leaf resolution (including case and Windows short names)
|
|
36
46
|
// without replacing the already observed root identity.
|
|
37
|
-
|
|
47
|
+
const operationPath = pathForWindowsFilesystem(rootPath);
|
|
48
|
+
observedPath = asynchronous ? yield* wait(realpathNative(operationPath)) : realpathSync.native(operationPath);
|
|
38
49
|
if (observedPath !== rootPath)
|
|
39
|
-
inspectCanonicalRoot(ioFs, observedPath, identity);
|
|
50
|
+
yield* inspectCanonicalRoot(ioFs, observedPath, identity, asynchronous);
|
|
40
51
|
}
|
|
41
52
|
return { ok: true, path: observedPath, identity };
|
|
42
53
|
}
|
|
@@ -48,34 +59,40 @@ function resolveConsumedPath(ioFs, filePath) {
|
|
|
48
59
|
return ioFs === fs ? realpathSync.native(filePath) : ioFs.realpathSync(filePath);
|
|
49
60
|
}
|
|
50
61
|
export function createRootFileFinalAdmission(ioFs, root, boundaryLabel, rejectHardlinks = true) {
|
|
62
|
+
return params => runSync(admitRootFile(ioFs, root, boundaryLabel, rejectHardlinks, params, false));
|
|
63
|
+
}
|
|
64
|
+
export function createRootFileFinalAdmissionAsync(root, boundaryLabel, rejectHardlinks) {
|
|
65
|
+
return params => runAsync(admitRootFile(fs, root, boundaryLabel, rejectHardlinks, params, true));
|
|
66
|
+
}
|
|
67
|
+
function* admitRootFile(ioFs, root, boundaryLabel, rejectHardlinks, { path: consumedPath, descriptorIdentity }, asynchronous) {
|
|
51
68
|
const inspectRoot = (candidateRootPath, expected) => {
|
|
52
|
-
inspectCanonicalRoot(ioFs, candidateRootPath, expected);
|
|
69
|
+
runSync(inspectCanonicalRoot(ioFs, candidateRootPath, expected));
|
|
53
70
|
};
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
throw error;
|
|
71
|
+
yield* inspectCanonicalRoot(ioFs, root.path, root.identity, asynchronous);
|
|
72
|
+
const canonicalPath = asynchronous ? yield* wait(realpathNative(consumedPath)) : resolveConsumedPath(ioFs, consumedPath);
|
|
73
|
+
assertNoWindowsPathAlias(canonicalPath, "filesystem", "resolved file path uses a Windows filesystem namespace alias");
|
|
74
|
+
const admitted = admitPathInsideRoot({
|
|
75
|
+
rootPath: root.path,
|
|
76
|
+
candidatePath: canonicalPath,
|
|
77
|
+
rootIdentity: root.identity,
|
|
78
|
+
inspectCandidateRoot: inspectRoot,
|
|
79
|
+
});
|
|
80
|
+
if (!admitted) {
|
|
81
|
+
throw new FsSafeError("outside-workspace", `resolved path escapes ${boundaryLabel}`);
|
|
82
|
+
}
|
|
83
|
+
try {
|
|
84
|
+
const current = asynchronous
|
|
85
|
+
? yield* wait(inspectFileIdentity(() => asyncFs.lstat(admitted.path, { bigint: true }), descriptorIdentity))
|
|
86
|
+
: inspectFileIdentitySync(() => ioFs.lstatSync(admitted.path, { bigint: true }), descriptorIdentity);
|
|
87
|
+
if (rejectHardlinks && current.isFile() && current.nlink > 1n)
|
|
88
|
+
throw hardlinkedPathNotAllowedError();
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
if (isExpectedPathError(error)) {
|
|
92
|
+
throw new FsSafeError("path-mismatch", "canonical file identity changed or could not be verified", { cause: error });
|
|
77
93
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
94
|
+
throw error;
|
|
95
|
+
}
|
|
96
|
+
yield* inspectCanonicalRoot(ioFs, root.path, root.identity, asynchronous);
|
|
97
|
+
return admitted.path;
|
|
81
98
|
}
|
|
@@ -2,6 +2,7 @@ import fs from "node:fs";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { inspectDirectoryIdentitySync } from "./directory-guard.js";
|
|
4
4
|
import { FsSafeError } from "./errors.js";
|
|
5
|
+
import { captureNativeFdClose } from "./native-binding.js";
|
|
5
6
|
import { getNativeBinding } from "./native.js";
|
|
6
7
|
import { openExactNativeRootSync } from "./native-parent-admission.js";
|
|
7
8
|
import { isExpectedPathError } from "./pinned-open.js";
|
|
@@ -84,6 +85,7 @@ export function createRootFileOpenBatchSync() {
|
|
|
84
85
|
}
|
|
85
86
|
const { owner, observation } = retained;
|
|
86
87
|
inspectDirectoryIdentitySync(observation.path, observation.identity);
|
|
88
|
+
const closeFd = captureNativeFdClose(binding);
|
|
87
89
|
let admittedFd;
|
|
88
90
|
try {
|
|
89
91
|
// Reject reparses before any full-leaf pathname observation can follow them.
|
|
@@ -96,7 +98,7 @@ export function createRootFileOpenBatchSync() {
|
|
|
96
98
|
}
|
|
97
99
|
throw error;
|
|
98
100
|
}
|
|
99
|
-
return openRootFileWithRetainedRootSync(params, observation, admittedFd);
|
|
101
|
+
return openRootFileWithRetainedRootSync(params, observation, admittedFd, closeFd);
|
|
100
102
|
}
|
|
101
103
|
catch (error) {
|
|
102
104
|
return failure(error);
|
|
@@ -13,6 +13,7 @@ export type RootFileOpenResult = {
|
|
|
13
13
|
stat: fs.Stats;
|
|
14
14
|
exactIdentity: ExactFileIdentity;
|
|
15
15
|
rootRealPath: string;
|
|
16
|
+
close?: () => void;
|
|
16
17
|
} | {
|
|
17
18
|
ok: false;
|
|
18
19
|
reason: RootFileOpenFailureReason;
|
|
@@ -48,6 +49,6 @@ export declare function matchRootFileOpenFailure<T>(failure: RootFileOpenFailure
|
|
|
48
49
|
/** Internal retained-root adapter; the native opener owns component admission. */
|
|
49
50
|
export declare function openRootFileWithRetainedRootSync(params: OpenRootFileSyncParams, root: Extract<CanonicalRootObservation, {
|
|
50
51
|
ok: true;
|
|
51
|
-
}>, admittedFd: number): RootFileOpenResult;
|
|
52
|
+
}>, admittedFd: number, closeFd: (fd: number) => void): RootFileOpenResult;
|
|
52
53
|
export declare function openRootFile(params: OpenRootFileParams): Promise<RootFileOpenResult>;
|
|
53
54
|
export {};
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { exactFileIdentity } from "./exact-identity.js";
|
|
2
2
|
import fs from "node:fs";
|
|
3
3
|
import path from "node:path";
|
|
4
|
+
import { runAsync, runSync, wait } from "./atomic-io.js";
|
|
4
5
|
import { resolveRootPathSyncWithCanonicalRootObservation, resolveRootPathWithCanonicalRootObservation, } from "./root-path.js";
|
|
5
6
|
import { readSymlinkResolution } from "./root-symlink-policy.js";
|
|
6
|
-
import { isExpectedPathError, openPinnedFileSync, } from "./pinned-open.js";
|
|
7
|
+
import { isExpectedPathError, openPinnedFileSync, openPinnedFile, } from "./pinned-open.js";
|
|
7
8
|
import { assertNoWindowsPathAlias } from "./windows-path-alias.js";
|
|
8
9
|
import { FsSafeError } from "./errors.js";
|
|
9
|
-
import {
|
|
10
|
+
import { ownFileDescriptorSync } from "./create-owned-file.js";
|
|
11
|
+
import { createRootFileFinalAdmission, createRootFileFinalAdmissionAsync, observeCanonicalRoot, observeCanonicalRootAsync, } from "./root-file-final-admission.js";
|
|
10
12
|
export function canUseRootFileOpen(ioFs) {
|
|
11
13
|
return (typeof ioFs.openSync === "function" &&
|
|
12
14
|
typeof ioFs.closeSync === "function" &&
|
|
@@ -71,22 +73,27 @@ export function matchRootFileOpenFailure(failure, handlers) {
|
|
|
71
73
|
return handlers.fallback(failure);
|
|
72
74
|
}
|
|
73
75
|
function finalizeRootFileOpen(params) {
|
|
76
|
+
return runSync(finalizeRootFileOpenProcedure(params, false));
|
|
77
|
+
}
|
|
78
|
+
function* finalizeRootFileOpenProcedure(params, asynchronous) {
|
|
74
79
|
if ("ok" in params.resolved) {
|
|
75
80
|
return params.resolved;
|
|
76
81
|
}
|
|
77
82
|
const resolved = params.resolved;
|
|
78
83
|
const rejectHardlinks = params.rejectHardlinks ?? true;
|
|
79
|
-
const
|
|
84
|
+
const input = {
|
|
80
85
|
filePath: resolved.absolutePath,
|
|
81
86
|
resolvedPath: resolved.resolvedPath,
|
|
82
87
|
rejectHardlinks,
|
|
83
88
|
maxBytes: params.maxBytes,
|
|
84
89
|
allowedType: params.allowedType,
|
|
85
90
|
ioFs: params.ioFs,
|
|
86
|
-
|
|
91
|
+
admittedFile: params.admittedFile,
|
|
87
92
|
rejectLeafSymlinks: params.rejectLeafSymlinks,
|
|
88
|
-
|
|
89
|
-
|
|
93
|
+
};
|
|
94
|
+
const opened = asynchronous
|
|
95
|
+
? yield* wait(openPinnedFile({ ...input, finalAdmission: createRootFileFinalAdmissionAsync(resolved.rootObservation, resolved.boundaryLabel, rejectHardlinks) }))
|
|
96
|
+
: openPinnedFileSync({ ...input, finalAdmission: createRootFileFinalAdmission(params.ioFs, resolved.rootObservation, resolved.boundaryLabel, rejectHardlinks) });
|
|
90
97
|
if (!opened.ok) {
|
|
91
98
|
return opened;
|
|
92
99
|
}
|
|
@@ -97,21 +104,25 @@ function finalizeRootFileOpen(params) {
|
|
|
97
104
|
stat: opened.stat,
|
|
98
105
|
exactIdentity: exactFileIdentity(opened.identity),
|
|
99
106
|
rootRealPath: resolved.rootRealPath,
|
|
107
|
+
...(opened.close ? { close: opened.close } : {}),
|
|
100
108
|
};
|
|
101
109
|
}
|
|
102
110
|
/** Internal retained-root adapter; the native opener owns component admission. */
|
|
103
|
-
export function openRootFileWithRetainedRootSync(params, root, admittedFd) {
|
|
111
|
+
export function openRootFileWithRetainedRootSync(params, root, admittedFd, closeFd) {
|
|
104
112
|
return finalizeRootFileOpen({
|
|
105
113
|
resolved: {
|
|
106
114
|
absolutePath: params.absolutePath, resolvedPath: params.absolutePath,
|
|
107
115
|
rootRealPath: root.path, rootObservation: root, boundaryLabel: params.boundaryLabel,
|
|
108
116
|
},
|
|
109
117
|
maxBytes: params.maxBytes, rejectHardlinks: params.rejectHardlinks,
|
|
110
|
-
allowedType: params.allowedType, ioFs: fs,
|
|
118
|
+
allowedType: params.allowedType, ioFs: fs,
|
|
119
|
+
admittedFile: ownFileDescriptorSync(admittedFd, closeFd), rejectLeafSymlinks: true,
|
|
111
120
|
});
|
|
112
121
|
}
|
|
113
122
|
export async function openRootFile(params) {
|
|
114
123
|
const ioFs = params.ioFs ?? fs;
|
|
124
|
+
// Windows sharing and explicit synchronous adapters retain their existing owner.
|
|
125
|
+
const asynchronous = process.platform !== "win32" && ioFs === fs;
|
|
115
126
|
const rawAbsolutePath = params.absolutePath;
|
|
116
127
|
let resolutionSnapshot;
|
|
117
128
|
try {
|
|
@@ -143,22 +154,22 @@ export async function openRootFile(params) {
|
|
|
143
154
|
rejectSymlinks: resolutionSnapshot.rejectSymlinks,
|
|
144
155
|
rejectFinalSymlink: resolutionSnapshot.rejectFinalSymlink,
|
|
145
156
|
skipLexicalRootCheck: resolutionSnapshot.skipLexicalRootCheck,
|
|
146
|
-
},
|
|
147
|
-
rootObservation =
|
|
148
|
-
|
|
157
|
+
}, asynchronous
|
|
158
|
+
? async (rootCanonicalPath) => { rootObservation = await observeCanonicalRootAsync(rootCanonicalPath); }
|
|
159
|
+
: rootCanonicalPath => { rootObservation = observeCanonicalRoot(ioFs, rootCanonicalPath); });
|
|
149
160
|
resolved = mapResolvedRootPath(resolutionSnapshot.absolutePath, resolutionSnapshot.boundaryLabel, resolvedPath, rootObservation);
|
|
150
161
|
}
|
|
151
162
|
catch (error) {
|
|
152
163
|
resolved = toBoundaryValidationError(error);
|
|
153
164
|
}
|
|
154
165
|
}
|
|
155
|
-
return
|
|
166
|
+
return runAsync(finalizeRootFileOpenProcedure({
|
|
156
167
|
resolved,
|
|
157
168
|
maxBytes: openSnapshot.maxBytes,
|
|
158
169
|
rejectHardlinks: openSnapshot.rejectHardlinks,
|
|
159
170
|
allowedType: openSnapshot.allowedType,
|
|
160
171
|
ioFs,
|
|
161
|
-
});
|
|
172
|
+
}, asynchronous));
|
|
162
173
|
}
|
|
163
174
|
function toBoundaryValidationError(error) {
|
|
164
175
|
return { ok: false, reason: "validation", error };
|
|
@@ -50,6 +50,7 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres
|
|
|
50
50
|
var e = new Error(message);
|
|
51
51
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
52
52
|
});
|
|
53
|
+
import { SidecarFallbackWriteError } from "./sidecar-lock-write.js";
|
|
53
54
|
import { exactFileIdentity, numberStats } from "./exact-identity.js";
|
|
54
55
|
import { registerRootHandleContext } from "./root-handle-context.js";
|
|
55
56
|
import fsSync, { constants as fsConstants } from "node:fs";
|
|
@@ -313,6 +314,7 @@ export class RootHandle {
|
|
|
313
314
|
mkdir: this.defaults.mkdir,
|
|
314
315
|
mode: this.defaults.mode,
|
|
315
316
|
renameIdentity: this.defaults.renameIdentity,
|
|
317
|
+
allowDrvfsRenameRecovery: this.defaults.allowDrvfsRenameRecovery,
|
|
316
318
|
...this.mutationOptions(options),
|
|
317
319
|
atomic: undefined,
|
|
318
320
|
private: undefined,
|
|
@@ -328,6 +330,7 @@ export class RootHandle {
|
|
|
328
330
|
await writeFileInRoot(this.context, {
|
|
329
331
|
mkdir: this.defaults.mkdir,
|
|
330
332
|
mode: this.defaults.mode,
|
|
333
|
+
allowDrvfsRenameRecovery: this.defaults.allowDrvfsRenameRecovery,
|
|
331
334
|
...this.mutationOptions(createInputOptions(data, options, this.defaults.maxBytes)),
|
|
332
335
|
relativePath,
|
|
333
336
|
data,
|
|
@@ -354,6 +357,7 @@ export class RootHandle {
|
|
|
354
357
|
await copyFileInRoot(this.context, {
|
|
355
358
|
maxBytes: normalizeMaxBytes(maxBytes, { defaultValue: this.defaults.maxBytes }),
|
|
356
359
|
mkdir: this.defaults.mkdir,
|
|
360
|
+
allowDrvfsRenameRecovery: this.defaults.allowDrvfsRenameRecovery,
|
|
357
361
|
...copyOptions,
|
|
358
362
|
source: copySource,
|
|
359
363
|
relativePath,
|
|
@@ -954,8 +958,11 @@ async function writeFileInRoot(root, params) {
|
|
|
954
958
|
params = { ...params, private: permissions.private, mode: permissions.mode };
|
|
955
959
|
}
|
|
956
960
|
const input = rootWriteInput(params);
|
|
961
|
+
if (input.kind === "buffer" && input.sidecar) {
|
|
962
|
+
params = { ...params, ...snapshotPinnedMutationPolicy(params.denyMutations, params.mutationSymlinks) };
|
|
963
|
+
}
|
|
957
964
|
await serializePathWrite(rootWriteQueueKey(root, params.relativePath), async () => {
|
|
958
|
-
if (!params.private && input.kind === "buffer" && !input.stageBeforePublish && process.platform === "win32" &&
|
|
965
|
+
if (!params.private && input.kind === "buffer" && !input.sidecar && !input.stageBeforePublish && process.platform === "win32" &&
|
|
959
966
|
(params.renameIdentity === "verify-content-with-lock" || !getPinnedWriteNativeBinding({ input }))) {
|
|
960
967
|
await writeFileFallback(root, { ...params, data: input.data });
|
|
961
968
|
return;
|
|
@@ -983,6 +990,7 @@ async function commitPinnedWriteInRoot(root, pinned, params, input) {
|
|
|
983
990
|
basename: pinned.basename,
|
|
984
991
|
targetPath: pinned.targetPath,
|
|
985
992
|
renameIdentity: params.renameIdentity,
|
|
993
|
+
allowDrvfsRenameRecovery: params.allowDrvfsRenameRecovery,
|
|
986
994
|
mkdir: !params.private && params.mkdir !== false,
|
|
987
995
|
private: params.private,
|
|
988
996
|
mode: params.mode ?? pinned.mode,
|
|
@@ -995,6 +1003,8 @@ async function commitPinnedWriteInRoot(root, pinned, params, input) {
|
|
|
995
1003
|
rootIdentity: root.rootIdentity,
|
|
996
1004
|
mutationAdmission: pinned.mutationAdmission,
|
|
997
1005
|
assertBeforeMutation: params.assertBeforeMutation,
|
|
1006
|
+
assertSidecarCleanupCandidate: input.kind === "buffer" && input.sidecar
|
|
1007
|
+
? candidate => assertMutationNotDenied(candidate, params.denyMutations) : undefined,
|
|
998
1008
|
verifyPublished: async (fd, expectedIdentity, parentGuard, nativeParent) => {
|
|
999
1009
|
verifyingPublication = true;
|
|
1000
1010
|
try {
|
|
@@ -1012,6 +1022,12 @@ async function commitPinnedWriteInRoot(root, pinned, params, input) {
|
|
|
1012
1022
|
});
|
|
1013
1023
|
}
|
|
1014
1024
|
catch (error) {
|
|
1025
|
+
if (error instanceof SidecarFallbackWriteError) {
|
|
1026
|
+
// Windows keeps its historical direct-write error identity.
|
|
1027
|
+
if (process.platform === "win32")
|
|
1028
|
+
throw error.failure;
|
|
1029
|
+
error = error.failure;
|
|
1030
|
+
}
|
|
1015
1031
|
if (verifyingPublication)
|
|
1016
1032
|
throw error;
|
|
1017
1033
|
const errorCode = error?.code;
|
|
@@ -20,19 +20,21 @@ export type RootDefaults = {
|
|
|
20
20
|
mode?: number;
|
|
21
21
|
denyMutations?: DenyMutationPolicy;
|
|
22
22
|
renameIdentity?: RenameIdentityPolicy;
|
|
23
|
+
/** Explicit verified-DrvFS close-all recovery; off by default. */
|
|
24
|
+
allowDrvfsRenameRecovery?: boolean;
|
|
23
25
|
symlinks?: SymlinkPolicy;
|
|
24
26
|
mutationSymlinks?: MutationSymlinkPolicy;
|
|
25
27
|
};
|
|
26
28
|
export type RootReadOptions = Pick<RootDefaults, "hardlinks" | "maxBytes" | "symlinks">;
|
|
27
29
|
export type RootOpenOptions = Omit<RootReadOptions, "maxBytes">;
|
|
28
|
-
export type RootWriteOptions = Pick<RootDefaults, "assertBeforeMutation" | "denyMutations" | "mutationSymlinks" | "durable" | "mkdir" | "mode" | "renameIdentity"> & {
|
|
30
|
+
export type RootWriteOptions = Pick<RootDefaults, "assertBeforeMutation" | "denyMutations" | "mutationSymlinks" | "durable" | "mkdir" | "mode" | "renameIdentity" | "allowDrvfsRenameRecovery"> & {
|
|
29
31
|
encoding?: BufferEncoding;
|
|
30
32
|
overwrite?: boolean;
|
|
31
33
|
};
|
|
32
34
|
export type RootOpenWritableOptions = Pick<RootDefaults, "assertBeforeMutation" | "denyMutations" | "mutationSymlinks" | "mkdir" | "mode"> & {
|
|
33
35
|
writeMode?: WritableOpenMode;
|
|
34
36
|
};
|
|
35
|
-
export type RootCopyOptions = Pick<RootDefaults, "assertBeforeMutation" | "denyMutations" | "mutationSymlinks" | "durable" | "maxBytes" | "mkdir" | "mode"> & {
|
|
37
|
+
export type RootCopyOptions = Pick<RootDefaults, "assertBeforeMutation" | "denyMutations" | "mutationSymlinks" | "durable" | "maxBytes" | "mkdir" | "mode" | "allowDrvfsRenameRecovery"> & {
|
|
36
38
|
sourceHardlinks?: HardlinkPolicy;
|
|
37
39
|
overwrite?: boolean;
|
|
38
40
|
clone?: CopyCloneMode;
|
|
@@ -46,7 +46,7 @@ export type ObservedRootPath = {
|
|
|
46
46
|
receipt?: RootPathObservationReceipt;
|
|
47
47
|
};
|
|
48
48
|
export declare function resolveRootPath(params: ResolveRootPathParams): Promise<ResolvedRootPath>;
|
|
49
|
-
export declare function resolveRootPathWithCanonicalRootObservation(params: ResolveRootPathParams, observeRoot: (rootCanonicalPath: string) => void): Promise<ResolvedRootPath>;
|
|
49
|
+
export declare function resolveRootPathWithCanonicalRootObservation(params: ResolveRootPathParams, observeRoot: (rootCanonicalPath: string) => void | Promise<void>): Promise<ResolvedRootPath>;
|
|
50
50
|
export declare function resolveRootPathWithObservation(params: ResolveRootPathParams, request: RootPathObservationRequest): Promise<ObservedRootPath>;
|
|
51
51
|
export declare function resolveRootPathForRemoval(params: ResolveRootPathParams, receipts: RemovalPathReceipts): Promise<ResolvedRootPath>;
|
|
52
52
|
export declare function resolveRootPathSync(params: ResolveRootPathParams): ResolvedRootPath;
|
|
@@ -273,7 +273,8 @@ function* traverseRootPath(params, { mode = "native", observation: observationOu
|
|
|
273
273
|
assertNoWindowsPathAlias(rootPath);
|
|
274
274
|
assertNoWindowsPathAlias(absolutePath);
|
|
275
275
|
assertNoWindowsPathAlias(rootCanonicalPath);
|
|
276
|
-
observeRoot
|
|
276
|
+
if (observeRoot)
|
|
277
|
+
yield* wait(observeRoot(rootCanonicalPath));
|
|
277
278
|
const context = createLexicalTraversalContext(yield* prepareRootTraversal(input, rootPath, rootCanonicalPath, absolutePath, rawAbsolutePath, synchronous));
|
|
278
279
|
const { state } = context;
|
|
279
280
|
const observation = createLexicalTraversalObservation(context, observationOutput?.request);
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import fsSync, {} from "node:fs";
|
|
2
|
+
import fs from "node:fs/promises";
|
|
2
3
|
import { FsSafeError } from "./errors.js";
|
|
3
4
|
import { openedPathResolutionError, recordOpenedFileFailure } from "./opened-file-failure.js";
|
|
4
5
|
import { isNotFoundPathError } from "./path.js";
|
|
5
6
|
import { admitPathInsideRoot } from "./root-boundary.js";
|
|
6
|
-
import { assertRootIdentityCurrentSync } from "./root-context.js";
|
|
7
|
+
import { assertRootIdentityCurrent, assertRootIdentityCurrentSync } from "./root-context.js";
|
|
8
|
+
import { runAsync, runSync, wait } from "./atomic-io.js";
|
|
7
9
|
import { fileNotFoundError, hardlinkedPathNotAllowedError, outsideWorkspaceError } from "./root-errors.js";
|
|
8
|
-
import { realpathSync } from "./realpath.js";
|
|
9
|
-
import { inspectFileIdentitySync } from "./strict-file-identity.js";
|
|
10
|
+
import { realpathNative, realpathSync } from "./realpath.js";
|
|
11
|
+
import { inspectFileIdentity, inspectFileIdentitySync } from "./strict-file-identity.js";
|
|
10
12
|
import { assertNoWindowsPathAlias } from "./windows-path-alias.js";
|
|
11
13
|
function resolveFinalOpenedRealPath(filePath) {
|
|
12
14
|
try {
|
|
@@ -31,6 +33,12 @@ export function inspectOpenedPathIdentitySync(filePath, symlinks) {
|
|
|
31
33
|
}
|
|
32
34
|
return stat;
|
|
33
35
|
}
|
|
36
|
+
async function inspectOpenedPathIdentity(filePath, symlinks) {
|
|
37
|
+
const stat = await (symlinks === "follow-within-root" ? fs.stat(filePath, { bigint: true }) : fs.lstat(filePath, { bigint: true }));
|
|
38
|
+
if (stat.isSymbolicLink() && symlinks !== "follow-within-root")
|
|
39
|
+
throw new FsSafeError("symlink", "symlink not allowed");
|
|
40
|
+
return stat;
|
|
41
|
+
}
|
|
34
42
|
export async function admitRootReadHandle(params) {
|
|
35
43
|
try {
|
|
36
44
|
if (params.hardlinks !== "allow" && params.opened.stat.nlink > 1) {
|
|
@@ -39,14 +47,20 @@ export async function admitRootReadHandle(params) {
|
|
|
39
47
|
if (params.beforeFinalFence) {
|
|
40
48
|
await params.beforeFinalFence(params.filePath, params.opened.handle);
|
|
41
49
|
}
|
|
42
|
-
|
|
43
|
-
|
|
50
|
+
function* admit() {
|
|
51
|
+
const synchronous = process.platform === "win32";
|
|
52
|
+
if (synchronous)
|
|
53
|
+
assertRootIdentityCurrentSync(params.root);
|
|
54
|
+
else
|
|
55
|
+
yield* wait(assertRootIdentityCurrent(params.root));
|
|
44
56
|
let realPath;
|
|
45
57
|
try {
|
|
46
|
-
const current =
|
|
58
|
+
const current = synchronous
|
|
59
|
+
? inspectFileIdentitySync(() => inspectOpenedPathIdentitySync(params.filePath, params.symlinks), params.identity)
|
|
60
|
+
: yield* wait(inspectFileIdentity(() => inspectOpenedPathIdentity(params.filePath, params.symlinks), params.identity));
|
|
47
61
|
if (params.hardlinks !== "allow" && current.nlink > 1n)
|
|
48
62
|
throw hardlinkedPathNotAllowedError();
|
|
49
|
-
const canonicalPath = resolveFinalOpenedRealPath(params.filePath);
|
|
63
|
+
const canonicalPath = synchronous ? resolveFinalOpenedRealPath(params.filePath) : yield* wait(realpathNative(params.filePath));
|
|
50
64
|
assertNoWindowsPathAlias(canonicalPath, "filesystem", "resolved file path uses a Windows filesystem namespace alias");
|
|
51
65
|
const admittedRealPath = admitPathInsideRoot({
|
|
52
66
|
rootPath: params.root.rootReal,
|
|
@@ -58,7 +72,9 @@ export async function admitRootReadHandle(params) {
|
|
|
58
72
|
}
|
|
59
73
|
// This is a fresh no-follow observation even when canonicalPath and
|
|
60
74
|
// filePath have the same spelling; realpath may have raced a replacement.
|
|
61
|
-
const canonical =
|
|
75
|
+
const canonical = synchronous
|
|
76
|
+
? inspectFileIdentitySync(() => inspectOpenedPathIdentitySync(canonicalPath, undefined), params.identity)
|
|
77
|
+
: yield* wait(inspectFileIdentity(() => inspectOpenedPathIdentity(canonicalPath), params.identity));
|
|
62
78
|
if (params.hardlinks !== "allow" && canonical.nlink > 1n)
|
|
63
79
|
throw hardlinkedPathNotAllowedError();
|
|
64
80
|
realPath = admittedRealPath.path;
|
|
@@ -69,9 +85,15 @@ export async function admitRootReadHandle(params) {
|
|
|
69
85
|
: error;
|
|
70
86
|
}
|
|
71
87
|
params.afterPathIdentityCheck?.(params.filePath, params.opened.handle);
|
|
72
|
-
|
|
88
|
+
if (synchronous)
|
|
89
|
+
assertRootIdentityCurrentSync(params.root);
|
|
90
|
+
else
|
|
91
|
+
yield* wait(assertRootIdentityCurrent(params.root));
|
|
73
92
|
return { ...params.opened, realPath };
|
|
74
93
|
}
|
|
94
|
+
try {
|
|
95
|
+
return process.platform === "win32" ? runSync(admit()) : await runAsync(admit());
|
|
96
|
+
}
|
|
75
97
|
catch (error) {
|
|
76
98
|
if (params.identity.nlink <= 1n) {
|
|
77
99
|
await recordOpenedFileFailure(error, params.opened.handle, params.filePath, params.identity);
|
|
@@ -3,6 +3,7 @@ import path from "node:path";
|
|
|
3
3
|
import { assertMutationNotDenied } from "./deny-mutations.js";
|
|
4
4
|
import { assertAsyncDirectoryGuard, assertSyncDirectoryGuard, createAsyncDirectoryGuard, } from "./directory-guard.js";
|
|
5
5
|
import { FsSafeError } from "./errors.js";
|
|
6
|
+
import { recordFileObservationFailure } from "./file-observation.js";
|
|
6
7
|
import { isNotFoundPathError } from "./path.js";
|
|
7
8
|
import { assertNoPathAliasEscape } from "./path-policy.js";
|
|
8
9
|
import { preparePinnedWriteMutationAdmission, snapshotPinnedMutationPolicy, } from "./pinned-mutation-admission.js";
|
|
@@ -267,8 +268,11 @@ export async function resolvePinnedWriteTargetInRoot(root, relativePath, request
|
|
|
267
268
|
if (existing) {
|
|
268
269
|
if (!existing.isFile() && !existing.isDirectory())
|
|
269
270
|
throw new FsSafeError("not-file", "not a file");
|
|
270
|
-
if (existing.isFile() && existing.nlink > 1)
|
|
271
|
-
|
|
271
|
+
if (existing.isFile() && existing.nlink > 1) {
|
|
272
|
+
const error = hardlinkedPathNotAllowedError();
|
|
273
|
+
recordFileObservationFailure(error, "hardlink");
|
|
274
|
+
throw error;
|
|
275
|
+
}
|
|
272
276
|
throw new FsSafeError("already-exists", "file already exists");
|
|
273
277
|
}
|
|
274
278
|
}
|
|
@@ -7,6 +7,7 @@ export declare const PRIVATE_SECRET_FILE_MODE = 384;
|
|
|
7
7
|
export declare function readSecretFileSync(filePath: string, label: string, options?: SecretFileReadOptions): string;
|
|
8
8
|
export declare function tryReadSecretFileSync(filePath: string | undefined, label: string, options?: SecretFileReadOptions): string | undefined;
|
|
9
9
|
type SecretFileWriteParams = {
|
|
10
|
+
allowDrvfsRenameRecovery?: boolean;
|
|
10
11
|
rootDir: string;
|
|
11
12
|
filePath: string;
|
|
12
13
|
content: string | Uint8Array;
|
|
@@ -209,6 +209,7 @@ function snapshotSecretFileWriteParams(params) {
|
|
|
209
209
|
rootDir,
|
|
210
210
|
filePath,
|
|
211
211
|
content: params.content,
|
|
212
|
+
allowDrvfsRenameRecovery: params.allowDrvfsRenameRecovery,
|
|
212
213
|
mode: params.mode,
|
|
213
214
|
dirMode: params.dirMode,
|
|
214
215
|
durable: params.durable,
|
|
@@ -289,6 +290,7 @@ async function materializeSecretFileAtomic(params, createOnly) {
|
|
|
289
290
|
mkdir: false,
|
|
290
291
|
mode,
|
|
291
292
|
verifyPosixMode: true,
|
|
293
|
+
allowDrvfsRenameRecovery: params.allowDrvfsRenameRecovery,
|
|
292
294
|
sync: params.durable !== false,
|
|
293
295
|
strictFileSync: createOnly && params.durable === "file",
|
|
294
296
|
overwrite: !createOnly,
|