@openclaw/matrix 2026.11.5 → 2026.11.7
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-Ca12_7Qa.mjs → approval-handler.runtime-LBvkygUK.mjs} +3 -3
- package/dist/.setup/{channel-FfaEmyIU.mjs → channel-CHryi9FS.mjs} +8 -8
- package/dist/.setup/{channel.runtime-CkkHG8zy.mjs → channel.runtime-DluXWaGb.mjs} +5 -5
- package/dist/.setup/{channel.setup-B00zzOOL.mjs → channel.setup-BDbs0FLq.mjs} +2 -2
- package/dist/.setup/{cli-dz9hd2dR.mjs → cli-C7Jmy2x4.mjs} +15 -40
- package/dist/.setup/cli-doctor-BVstkgJE.mjs +36 -0
- package/dist/.setup/{cli-metadata-CwUhA9CY.mjs → cli-metadata-B0GHIn05.mjs} +1 -1
- package/dist/.setup/{client-D1bsidwU.mjs → client-Bk_tBqNp.mjs} +2 -2
- package/dist/.setup/{client-bootstrap-CTT0VF6v.mjs → client-bootstrap-Bhhri97J.mjs} +1 -1
- package/dist/.setup/{client-CFPYqaYK.mjs → client-mFRVrUt3.mjs} +2 -2
- package/dist/.setup/{create-client-Ccf5wyS3.mjs → create-client-CzUtZgYF.mjs} +2 -2
- package/dist/.setup/{crypto-runtime-DZNytKX5.mjs → crypto-runtime-BI9Pc344.mjs} +1 -1
- package/dist/.setup/{crypto-unsafe-state-doctor-Dh1dtuSz.mjs → crypto-unsafe-state-doctor-CmF1X1dZ.mjs} +3 -4
- package/dist/.setup/{directory-live-ufzRheWx.mjs → directory-live-DmkH9hcp.mjs} +1 -1
- package/dist/.setup/{draft-stream-BPjjKSoI.mjs → draft-stream-bVedfEB3.mjs} +1 -1
- package/dist/.setup/{exec-approvals-BwEOyI1-.mjs → exec-approvals-BeYF9-3o.mjs} +2 -2
- package/dist/.setup/{messages-DpJ9naJa.mjs → messages-BqVczVlt.mjs} +2 -2
- package/dist/.setup/{monitor-vpzawYrB.mjs → monitor-BsSo3tCv.mjs} +31 -17
- package/dist/.setup/{onboarding-BK-V2ZLT.mjs → onboarding-CoMpgTiK.mjs} +3 -3
- package/dist/.setup/{outbound-DydCDuvM.mjs → outbound-ntm0KOfK.mjs} +2 -2
- package/dist/.setup/{profile-update-RLsY-gu6.mjs → profile-update-gC436enW.mjs} +9 -4
- package/dist/.setup/{reaction-events-lcgVF3M5.mjs → reaction-events-DTThoaJQ.mjs} +3 -3
- package/dist/.setup/{resolve-targets-DYW8ULZS.mjs → resolve-targets-CWW9zTYp.mjs} +1 -1
- package/dist/.setup/{room-info-Dhc4efkA.mjs → room-info-CM3MKoh4.mjs} +3 -3
- package/dist/.setup/{sdk-DPXiQ3jr.mjs → sdk-ByFgA6Il.mjs} +4 -3
- package/dist/.setup/{send-HHAbKARg.mjs → send-DFB7JGg2.mjs} +7 -7
- package/dist/.setup/{setup-bootstrap-DaT2j28V.mjs → setup-bootstrap-razh2kSp.mjs} +2 -2
- package/dist/.setup/{setup-core-DcqQbLZv.mjs → setup-core-BVbxltMM.mjs} +1 -1
- package/dist/.setup/setup-plugin-api-CQKySg7F.mjs +2 -0
- package/dist/.setup/{thread-bindings-891JsKXF.mjs → thread-bindings-D5VJEDZV.mjs} +1 -1
- package/dist/.setup/{tool-actions-8mXdq9OV.mjs → tool-actions-DexlmVDf.mjs} +10 -10
- package/dist/.setup/{verification-CcZIVL8P.mjs → verification-B122bsH2.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/doctor-contract-api.js +7 -3
- 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 +45 -1
- package/node_modules/@openclaw/fs-safe/README.md +4 -0
- package/node_modules/@openclaw/fs-safe/dist/absolute-path.js +2 -2
- package/node_modules/@openclaw/fs-safe/dist/advanced.d.ts +2 -2
- package/node_modules/@openclaw/fs-safe/dist/advanced.js +2 -2
- 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 +6 -0
- package/node_modules/@openclaw/fs-safe/dist/atomic.d.ts +1 -0
- package/node_modules/@openclaw/fs-safe/dist/directory-mode-node.d.ts +5 -0
- package/node_modules/@openclaw/fs-safe/dist/directory-mode-node.js +13 -0
- package/node_modules/@openclaw/fs-safe/dist/directory-mode-options.d.ts +3 -0
- package/node_modules/@openclaw/fs-safe/dist/directory-mode-options.js +6 -0
- package/node_modules/@openclaw/fs-safe/dist/errors.d.ts +1 -1
- package/node_modules/@openclaw/fs-safe/dist/errors.js +1 -0
- package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-admission.d.ts +0 -1
- package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-admission.js +1 -11
- package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-root-acquire.js +3 -3
- package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-stale-admission.js +2 -3
- package/node_modules/@openclaw/fs-safe/dist/file-store-boundary.d.ts +3 -3
- package/node_modules/@openclaw/fs-safe/dist/file-store-boundary.js +30 -4
- package/node_modules/@openclaw/fs-safe/dist/file-store-prune.d.ts +1 -1
- package/node_modules/@openclaw/fs-safe/dist/file-store-prune.js +7 -1
- package/node_modules/@openclaw/fs-safe/dist/file-store-sync-directory.d.ts +1 -1
- package/node_modules/@openclaw/fs-safe/dist/file-store-sync-directory.js +30 -4
- package/node_modules/@openclaw/fs-safe/dist/file-store-sync-write.d.ts +1 -1
- package/node_modules/@openclaw/fs-safe/dist/file-store-sync-write.js +2 -0
- package/node_modules/@openclaw/fs-safe/dist/file-store.d.ts +2 -1
- package/node_modules/@openclaw/fs-safe/dist/file-store.js +5 -0
- package/node_modules/@openclaw/fs-safe/dist/guarded-mkdir.d.ts +2 -0
- package/node_modules/@openclaw/fs-safe/dist/guarded-mkdir.js +9 -0
- package/node_modules/@openclaw/fs-safe/dist/json-store.d.ts +2 -1
- package/node_modules/@openclaw/fs-safe/dist/native-binding.d.ts +4 -1
- package/node_modules/@openclaw/fs-safe/dist/native-pinned-write.js +1 -1
- package/node_modules/@openclaw/fs-safe/dist/native-staged-file.d.ts +1 -1
- package/node_modules/@openclaw/fs-safe/dist/native-staged-file.js +19 -13
- package/node_modules/@openclaw/fs-safe/dist/overwrite-file-handle.d.ts +2 -0
- package/node_modules/@openclaw/fs-safe/dist/overwrite-file-handle.js +27 -5
- package/node_modules/@openclaw/fs-safe/dist/path-prefix.d.ts +1 -0
- package/node_modules/@openclaw/fs-safe/dist/path-prefix.js +84 -7
- package/node_modules/@openclaw/fs-safe/dist/pinned-write-input.js +0 -11
- package/node_modules/@openclaw/fs-safe/dist/prepare-directory-mode.d.ts +9 -0
- package/node_modules/@openclaw/fs-safe/dist/prepare-directory-mode.js +61 -0
- package/node_modules/@openclaw/fs-safe/dist/private-temp-workspace.js +2 -1
- package/node_modules/@openclaw/fs-safe/dist/realpath.d.ts +2 -0
- package/node_modules/@openclaw/fs-safe/dist/realpath.js +16 -0
- package/node_modules/@openclaw/fs-safe/dist/replace-file-descriptor.d.ts +2 -1
- package/node_modules/@openclaw/fs-safe/dist/replace-file-descriptor.js +8 -6
- package/node_modules/@openclaw/fs-safe/dist/replace-file-types.d.ts +2 -1
- package/node_modules/@openclaw/fs-safe/dist/replace-file.js +20 -13
- package/node_modules/@openclaw/fs-safe/dist/root-context.js +4 -1
- package/node_modules/@openclaw/fs-safe/dist/root-create-native.d.ts +1 -1
- package/node_modules/@openclaw/fs-safe/dist/root-create-native.js +18 -9
- package/node_modules/@openclaw/fs-safe/dist/root-errors.d.ts +2 -0
- package/node_modules/@openclaw/fs-safe/dist/root-errors.js +9 -0
- package/node_modules/@openclaw/fs-safe/dist/root-impl.js +4 -1
- package/node_modules/@openclaw/fs-safe/dist/root-mkdir-native.d.ts +1 -1
- package/node_modules/@openclaw/fs-safe/dist/root-mkdir-native.js +35 -16
- package/node_modules/@openclaw/fs-safe/dist/root-path-existing.d.ts +6 -2
- package/node_modules/@openclaw/fs-safe/dist/root-path-existing.js +32 -20
- package/node_modules/@openclaw/fs-safe/dist/root-path.js +32 -26
- package/node_modules/@openclaw/fs-safe/dist/root-write-admission.js +4 -1
- package/node_modules/@openclaw/fs-safe/dist/secret-file.d.ts +2 -1
- package/node_modules/@openclaw/fs-safe/dist/secret-file.js +2 -0
- package/node_modules/@openclaw/fs-safe/dist/sibling-temp.d.ts +2 -1
- package/node_modules/@openclaw/fs-safe/dist/sibling-temp.js +5 -4
- package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-policy.d.ts +3 -2
- package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-policy.js +8 -9
- package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-stale-admission.js +3 -1
- package/node_modules/@openclaw/fs-safe/dist/temp-workspace-types.d.ts +2 -1
- package/node_modules/@openclaw/fs-safe/dist/text-atomic.d.ts +2 -1
- package/node_modules/@openclaw/fs-safe/dist/types.d.ts +1 -0
- package/node_modules/@openclaw/fs-safe/dist/watch-hints.js +12 -3
- package/node_modules/@openclaw/fs-safe/dist/windows-security-helper.exe +0 -0
- package/node_modules/@openclaw/fs-safe/dist/write-file-handle.d.ts +0 -1
- package/node_modules/@openclaw/fs-safe/dist/write-file-handle.js +10 -12
- package/node_modules/@openclaw/fs-safe/docs/advanced.md +3 -3
- package/node_modules/@openclaw/fs-safe/docs/atomic.md +16 -3
- package/node_modules/@openclaw/fs-safe/docs/compiler-qualification.md +1 -1
- package/node_modules/@openclaw/fs-safe/docs/contributing.md +27 -18
- package/node_modules/@openclaw/fs-safe/docs/errors.md +3 -1
- package/node_modules/@openclaw/fs-safe/docs/file-store.md +14 -2
- package/node_modules/@openclaw/fs-safe/docs/in-place-write.md +31 -0
- package/node_modules/@openclaw/fs-safe/docs/install.md +1 -1
- package/node_modules/@openclaw/fs-safe/docs/json-store.md +6 -1
- package/node_modules/@openclaw/fs-safe/docs/json.md +5 -1
- package/node_modules/@openclaw/fs-safe/docs/path-prefix.md +14 -4
- package/node_modules/@openclaw/fs-safe/docs/public-api.md +4 -2
- package/node_modules/@openclaw/fs-safe/docs/secret-file.md +5 -1
- package/node_modules/@openclaw/fs-safe/docs/sidecar-lock.md +4 -0
- package/node_modules/@openclaw/fs-safe/docs/temp.md +9 -1
- package/node_modules/@openclaw/fs-safe/docs/types.md +5 -1
- package/node_modules/@openclaw/fs-safe/package.json +12 -12
- 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/openclaw.plugin.json +6 -0
- package/package.json +5 -5
- package/dist/.setup/setup-plugin-api-Cg4TelGZ.mjs +0 -2
|
@@ -9,11 +9,21 @@ export async function overwriteFileHandle(handle, data, options = {}) {
|
|
|
9
9
|
// former method-call receiver while preventing a later getter mutation from
|
|
10
10
|
// replacing authority after rollback preparation.
|
|
11
11
|
const beforeWrite = options.beforeWrite;
|
|
12
|
+
return overwrite(handle, data, options, beforeWrite);
|
|
13
|
+
}
|
|
14
|
+
/** Await authority preparation, then synchronously admit the whole borrowed-handle write. */
|
|
15
|
+
export async function overwriteFileHandleWithAuthority(handle, data, prepareAuthority) {
|
|
16
|
+
if (typeof prepareAuthority !== "function") {
|
|
17
|
+
throw new TypeError("prepareAuthority must be a function");
|
|
18
|
+
}
|
|
19
|
+
return overwrite(handle, data, undefined, undefined, prepareAuthority);
|
|
20
|
+
}
|
|
21
|
+
async function overwrite(handle, data, receiver, beforeWrite, prepareAuthority) {
|
|
12
22
|
const payload = data.subarray(0, data.byteLength);
|
|
13
23
|
const payloadBytes = payload.byteLength;
|
|
14
24
|
const fd = handle.fd;
|
|
15
|
-
//
|
|
16
|
-
const stat = fd < 0 ? await handle.stat() : fs.fstatSync(fd);
|
|
25
|
+
// The awaited API keeps metadata I/O off-thread; preserve the legacy fast path.
|
|
26
|
+
const stat = prepareAuthority || fd < 0 ? await handle.stat() : fs.fstatSync(fd);
|
|
17
27
|
if (!stat.isFile()) {
|
|
18
28
|
throw new FsSafeError("not-file", "overwrite handle must be a regular file");
|
|
19
29
|
}
|
|
@@ -26,15 +36,27 @@ export async function overwriteFileHandle(handle, data, options = {}) {
|
|
|
26
36
|
if (await readFileWindowFully(handle, originalPrefix, 0) !== prefixBytes) {
|
|
27
37
|
throw new FsSafeError("read-failed", "file ended before overwrite rollback preparation completed");
|
|
28
38
|
}
|
|
29
|
-
|
|
39
|
+
if (prepareAuthority) {
|
|
40
|
+
const assertCurrent = await prepareAuthority();
|
|
41
|
+
if (typeof assertCurrent !== "function") {
|
|
42
|
+
throw new TypeError("prepareAuthority must return a synchronous assertion");
|
|
43
|
+
}
|
|
44
|
+
assertSynchronousCallbackResult(assertCurrent(), "prepared authority assertion");
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
assertSynchronousCallbackResult(beforeWrite === undefined ? undefined : Reflect.apply(beforeWrite, receiver, []), "beforeWrite");
|
|
48
|
+
}
|
|
30
49
|
let prefixStarted = false;
|
|
31
50
|
try {
|
|
32
51
|
// Leave existing bytes intact until any additional storage has been written.
|
|
33
52
|
if (payloadBytes > originalSize) {
|
|
34
53
|
await writeAllToFile(handle, payload.subarray(originalSize), { position: originalSize });
|
|
35
54
|
}
|
|
36
|
-
|
|
37
|
-
|
|
55
|
+
// An empty prepared write must dispatch truncation before yielding after admission.
|
|
56
|
+
if (prefixBytes > 0 || !prepareAuthority) {
|
|
57
|
+
prefixStarted = true;
|
|
58
|
+
await writeAllToFile(handle, payload.subarray(0, prefixBytes), { position: 0 });
|
|
59
|
+
}
|
|
38
60
|
if (payloadBytes < originalSize) {
|
|
39
61
|
await handle.truncate(payloadBytes);
|
|
40
62
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
|
+
import asyncFs from "node:fs/promises";
|
|
2
3
|
import path from "node:path";
|
|
3
4
|
import { formatErrorDetail } from "./error-detail.js";
|
|
4
5
|
import { assertNoNulPathInput, hasNodeErrorCode } from "./path.js";
|
|
5
|
-
import { realpathSync } from "./realpath.js";
|
|
6
|
+
import { realpathNative, realpathSync } from "./realpath.js";
|
|
6
7
|
import { absolutePathWithRawSegments } from "./root-path-existing.js";
|
|
7
8
|
import { pathForWindowsFilesystem } from "./windows-path-alias.js";
|
|
8
9
|
function rawRoot(absolutePath) {
|
|
@@ -23,7 +24,12 @@ function resolutionError(code, absolutePath) {
|
|
|
23
24
|
// path. At 32 components, repeated front removal can reindex at most 496 array
|
|
24
25
|
// positions per constructed queue; longer queues use a forward cursor instead.
|
|
25
26
|
const SHIFT_QUEUE_COMPONENT_LIMIT = 32;
|
|
26
|
-
|
|
27
|
+
function* read(operation) {
|
|
28
|
+
let value;
|
|
29
|
+
yield async () => { value = await operation(); };
|
|
30
|
+
return value;
|
|
31
|
+
}
|
|
32
|
+
function* resolvePrefix(input, synchronous = false) {
|
|
27
33
|
assertNoNulPathInput(input);
|
|
28
34
|
const absolutePath = absolutePathWithRawSegments(input);
|
|
29
35
|
let resolved = rawRoot(absolutePath);
|
|
@@ -43,7 +49,11 @@ export function resolvePathPrefixSync(input) {
|
|
|
43
49
|
const lookup = segment === ".." && atRoot ? "." : segment;
|
|
44
50
|
// lstat(dir) does not test search permission, and realpath may erase dots.
|
|
45
51
|
const operationBase = pathForWindowsFilesystem(resolved);
|
|
46
|
-
|
|
52
|
+
const lookupPath = `${operationBase}${operationBase.endsWith(path.sep) ? "" : path.sep}${lookup}`;
|
|
53
|
+
if (synchronous)
|
|
54
|
+
fs.lstatSync(lookupPath, { bigint: true });
|
|
55
|
+
else
|
|
56
|
+
yield* read(() => asyncFs.lstat(lookupPath, { bigint: true }));
|
|
47
57
|
if (segment === ".." && !atRoot)
|
|
48
58
|
resolved = path.dirname(resolved);
|
|
49
59
|
continue;
|
|
@@ -51,14 +61,16 @@ export function resolvePathPrefixSync(input) {
|
|
|
51
61
|
const candidate = path.join(resolved, segment);
|
|
52
62
|
let stat;
|
|
53
63
|
try {
|
|
54
|
-
stat = fs.lstatSync(candidate, { bigint: true })
|
|
64
|
+
stat = synchronous ? fs.lstatSync(candidate, { bigint: true })
|
|
65
|
+
: yield* read(() => asyncFs.lstat(candidate, { bigint: true }));
|
|
55
66
|
}
|
|
56
67
|
catch (error) {
|
|
57
68
|
if (!hasNodeErrorCode(error, "ENOENT"))
|
|
58
69
|
throw error;
|
|
59
70
|
return {
|
|
60
71
|
absolutePath,
|
|
61
|
-
existingPath: realpathSync.native(pathForWindowsFilesystem(resolved))
|
|
72
|
+
existingPath: synchronous ? realpathSync.native(pathForWindowsFilesystem(resolved))
|
|
73
|
+
: yield* read(() => realpathNative(pathForWindowsFilesystem(resolved))),
|
|
62
74
|
unresolvedSegments: shiftQueue ? [segment, ...remaining] : remaining.slice(nextSegment - 1),
|
|
63
75
|
};
|
|
64
76
|
}
|
|
@@ -74,7 +86,7 @@ export function resolvePathPrefixSync(input) {
|
|
|
74
86
|
throw resolutionError("ELOOP", absolutePath);
|
|
75
87
|
visitedStates.add(state);
|
|
76
88
|
symlinkHops++;
|
|
77
|
-
const target = fs.readlinkSync(candidate);
|
|
89
|
+
const target = synchronous ? fs.readlinkSync(candidate) : yield* read(() => asyncFs.readlink(candidate));
|
|
78
90
|
const rawTarget = path.sep === "\\" ? target.replaceAll("/", "\\") : target;
|
|
79
91
|
let targetSegments;
|
|
80
92
|
if (path.isAbsolute(rawTarget)) {
|
|
@@ -100,5 +112,70 @@ export function resolvePathPrefixSync(input) {
|
|
|
100
112
|
shiftQueue = remainingCount <= SHIFT_QUEUE_COMPONENT_LIMIT;
|
|
101
113
|
nextSegment = 0;
|
|
102
114
|
}
|
|
103
|
-
return { absolutePath, existingPath: realpathSync.native(pathForWindowsFilesystem(resolved))
|
|
115
|
+
return { absolutePath, existingPath: synchronous ? realpathSync.native(pathForWindowsFilesystem(resolved))
|
|
116
|
+
: yield* read(() => realpathNative(pathForWindowsFilesystem(resolved))), unresolvedSegments: [] };
|
|
117
|
+
}
|
|
118
|
+
export function resolvePathPrefixSync(input) {
|
|
119
|
+
const result = resolvePrefix(input, true).next();
|
|
120
|
+
if (!result.done)
|
|
121
|
+
throw new Error("Synchronous path prefix resolution yielded asynchronous IO");
|
|
122
|
+
return result.value;
|
|
123
|
+
}
|
|
124
|
+
export async function resolvePathPrefix(input) {
|
|
125
|
+
if (process.platform !== "win32" && !process.versions.bun) {
|
|
126
|
+
assertNoNulPathInput(input);
|
|
127
|
+
const absolutePath = absolutePathWithRawSegments(input);
|
|
128
|
+
let entry;
|
|
129
|
+
try {
|
|
130
|
+
entry = await asyncFs.lstat(absolutePath);
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
if (hasNodeErrorCode(error, "ENOENT") && absolutePath === path.resolve(absolutePath)) {
|
|
134
|
+
// The leaf is absent, so only its nearest existing directory is needed.
|
|
135
|
+
// Stop at aliases: dangling targets still require physical expansion.
|
|
136
|
+
for (let parent = path.dirname(absolutePath);; parent = path.dirname(parent)) {
|
|
137
|
+
let stat;
|
|
138
|
+
try {
|
|
139
|
+
stat = await asyncFs.lstat(parent);
|
|
140
|
+
}
|
|
141
|
+
catch (error) {
|
|
142
|
+
if (hasNodeErrorCode(error, "ENOENT") && path.dirname(parent) !== parent)
|
|
143
|
+
continue;
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
if (!stat.isDirectory())
|
|
147
|
+
break;
|
|
148
|
+
return {
|
|
149
|
+
absolutePath,
|
|
150
|
+
existingPath: await realpathNative(parent),
|
|
151
|
+
unresolvedSegments: absolutePath.slice(parent.length + (parent.endsWith(path.sep) ? 0 : 1)).split(path.sep),
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
if (entry) {
|
|
157
|
+
try {
|
|
158
|
+
// lstat checked raw parent traversal; a final link also needs its target's search permissions.
|
|
159
|
+
if (entry.isSymbolicLink())
|
|
160
|
+
await asyncFs.access(absolutePath);
|
|
161
|
+
return { absolutePath, existingPath: await realpathNative(absolutePath), unresolvedSegments: [] };
|
|
162
|
+
}
|
|
163
|
+
catch {
|
|
164
|
+
// Raw suffixes, dangling links and uncertain failures retain the walker.
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
const reads = resolvePrefix(input);
|
|
169
|
+
let step = reads.next();
|
|
170
|
+
while (!step.done) {
|
|
171
|
+
try {
|
|
172
|
+
await step.value();
|
|
173
|
+
}
|
|
174
|
+
catch (error) {
|
|
175
|
+
step = reads.throw(error);
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
step = reads.next();
|
|
179
|
+
}
|
|
180
|
+
return step.value;
|
|
104
181
|
}
|
|
@@ -21,7 +21,6 @@ export function replayPinnedInput(fd, input) {
|
|
|
21
21
|
})() };
|
|
22
22
|
}
|
|
23
23
|
const isUint8Array = types.isUint8Array;
|
|
24
|
-
const SMALL_BUFFER_BYTES = 64 * 1024;
|
|
25
24
|
function streamChunkBytes(chunk) {
|
|
26
25
|
if (Buffer.isBuffer(chunk))
|
|
27
26
|
return chunk;
|
|
@@ -36,16 +35,6 @@ export async function writePinnedInput(target, input, maxBytes, assertBeforeMuta
|
|
|
36
35
|
await writeCopyFileToFd(typeof target === "number" ? target : target.fd, input, maxBytes, assertBeforeMutation);
|
|
37
36
|
return;
|
|
38
37
|
}
|
|
39
|
-
if (typeof target === "number" && input.kind === "buffer" &&
|
|
40
|
-
input.stageBeforePublish !== false && !assertBeforeMutation) {
|
|
41
|
-
const data = typeof input.data === "string" ? Buffer.from(input.data, input.encoding ?? "utf8") : input.data;
|
|
42
|
-
if (data.byteLength <= SMALL_BUFFER_BYTES) {
|
|
43
|
-
if (maxBytes !== undefined && data.byteLength > maxBytes) {
|
|
44
|
-
throw new FsSafeError("too-large", `file exceeds limit of ${maxBytes} bytes (got at least ${data.byteLength})`);
|
|
45
|
-
}
|
|
46
|
-
return writeAllToFile(target, data, { synchronous: true });
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
38
|
let bytes = 0;
|
|
50
39
|
const write = async (data) => {
|
|
51
40
|
bytes += data.byteLength;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type AtomicIo, type Procedure } from "./atomic-io.js";
|
|
2
|
+
import type { AtomicMutation } from "./replace-file-mutation.js";
|
|
3
|
+
/** Retain numeric compatibility; preservation distinguishes exclusive creation from EEXIST. */
|
|
4
|
+
export declare function prepareDirectoryMode(io: AtomicIo, params: {
|
|
5
|
+
dirPath: string;
|
|
6
|
+
mode: number | "preserve";
|
|
7
|
+
mutation?: AtomicMutation;
|
|
8
|
+
ignoreChmodError?: boolean;
|
|
9
|
+
}): Procedure<void>;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { inspectAtomicIdentity } from "./atomic-io.js";
|
|
3
|
+
import { FsSafeError } from "./errors.js";
|
|
4
|
+
import { hasErrorCode } from "./file-cleanup.js";
|
|
5
|
+
import { applyDirectoryMode } from "./replace-file-descriptor.js";
|
|
6
|
+
/** Retain numeric compatibility; preservation distinguishes exclusive creation from EEXIST. */
|
|
7
|
+
export function* prepareDirectoryMode(io, params) {
|
|
8
|
+
if (params.mode !== "preserve") {
|
|
9
|
+
params.mutation?.assert();
|
|
10
|
+
yield* io.mkdir(params.dirPath, params.mode);
|
|
11
|
+
yield* applyDirectoryMode(io, params);
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
const inspect = function* (expected) {
|
|
15
|
+
const observed = inspectAtomicIdentity(io, () => io.lstatExact(params.dirPath), expected, false, stat => {
|
|
16
|
+
if (stat.isSymbolicLink() || !stat.isDirectory()) {
|
|
17
|
+
throw new FsSafeError("not-file", `Atomic replace parent must be a real directory: ${params.dirPath}`);
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
return (io.asynchronous ? yield observed : observed);
|
|
21
|
+
};
|
|
22
|
+
let expectedIdentity;
|
|
23
|
+
let created = false;
|
|
24
|
+
try {
|
|
25
|
+
expectedIdentity = yield* inspect();
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
if (!hasErrorCode(error, "ENOENT"))
|
|
29
|
+
throw error;
|
|
30
|
+
if (!io.asynchronous && !io.fchmodSync && process.platform !== "win32") {
|
|
31
|
+
throw new TypeError("fileSystem.fchmodSync is required to finalize a created directory with dirMode: preserve");
|
|
32
|
+
}
|
|
33
|
+
const parent = path.dirname(params.dirPath);
|
|
34
|
+
if (parent === params.dirPath)
|
|
35
|
+
throw error;
|
|
36
|
+
yield* prepareDirectoryMode(io, { ...params, dirPath: parent });
|
|
37
|
+
params.mutation?.assert();
|
|
38
|
+
try {
|
|
39
|
+
yield* io.mkdirExclusive(params.dirPath, 0o700);
|
|
40
|
+
created = true;
|
|
41
|
+
}
|
|
42
|
+
catch (mkdirError) {
|
|
43
|
+
if (!hasErrorCode(mkdirError, "EEXIST"))
|
|
44
|
+
throw mkdirError;
|
|
45
|
+
}
|
|
46
|
+
expectedIdentity = yield* inspect();
|
|
47
|
+
}
|
|
48
|
+
yield* applyDirectoryMode(io, {
|
|
49
|
+
...params,
|
|
50
|
+
mode: created ? 0o700 : "preserve",
|
|
51
|
+
expectedIdentity,
|
|
52
|
+
// A successfully created directory must finish at 0700 even for best-effort callers.
|
|
53
|
+
ignoreChmodError: created ? false : params.ignoreChmodError,
|
|
54
|
+
});
|
|
55
|
+
if (created && process.platform !== "win32") {
|
|
56
|
+
const finalized = yield* inspect(expectedIdentity);
|
|
57
|
+
if ((finalized.mode & 4095n) !== 448n) {
|
|
58
|
+
throw new FsSafeError("path-mismatch", "created directory mode could not be finalized");
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -130,7 +130,8 @@ function throwTempWorkspaceOpenFailure(failure) {
|
|
|
130
130
|
function tempWorkspaceSettings(options) {
|
|
131
131
|
const rootDir = options.rootDir;
|
|
132
132
|
assertNoWindowsPathAlias(rootDir, "filesystem", "temp workspace root uses a Windows filesystem namespace alias");
|
|
133
|
-
const
|
|
133
|
+
const requestedDirMode = options.dirMode;
|
|
134
|
+
const dirMode = requestedDirMode === "preserve" ? 0o700 : requestedDirMode ?? 0o700;
|
|
134
135
|
validateTempWorkspaceDirMode(dirMode);
|
|
135
136
|
const mode = options.mode ?? 0o600;
|
|
136
137
|
const cleanupSafety = resolveTempWorkspaceCleanupSafety(options.cleanupSafety);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
|
+
import asyncFs from "node:fs/promises";
|
|
2
3
|
import { platform } from "node:os";
|
|
3
4
|
import { getSystemErrorName } from "node:util";
|
|
4
5
|
import { FsSafeError } from "./errors.js";
|
|
@@ -73,3 +74,18 @@ function resolve(input, native) {
|
|
|
73
74
|
export const realpathSync = Object.assign((input) => resolve(input, false), {
|
|
74
75
|
native: (input) => resolve(input, true),
|
|
75
76
|
});
|
|
77
|
+
/** Async on Node; retain runtime-specific native canonicalization guarantees. */
|
|
78
|
+
export async function realpathNative(input) {
|
|
79
|
+
if (bunPosix)
|
|
80
|
+
return realpathSync.native(input);
|
|
81
|
+
try {
|
|
82
|
+
return await asyncFs.realpath(input);
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
if (process.platform !== "win32" || error.code !== "EPERM" ||
|
|
86
|
+
error.syscall !== "realpath")
|
|
87
|
+
throw error;
|
|
88
|
+
// AppContainer DOS-name translation still belongs to the native sync owner.
|
|
89
|
+
return realpathSync.native(input);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
@@ -4,7 +4,8 @@ import { type AtomicFile, type AtomicIo, type Procedure } from "./atomic-io.js";
|
|
|
4
4
|
export declare function syncDirectoryBestEffort(io: AtomicIo, dirPath: string): Procedure<void>;
|
|
5
5
|
export declare function applyDirectoryMode(io: AtomicIo, params: {
|
|
6
6
|
dirPath: string;
|
|
7
|
-
mode: number;
|
|
7
|
+
mode: number | "preserve";
|
|
8
|
+
expectedIdentity?: BigIntStats;
|
|
8
9
|
ignoreChmodError?: boolean;
|
|
9
10
|
mutation?: AtomicMutation;
|
|
10
11
|
}): Procedure<void>;
|
|
@@ -46,9 +46,9 @@ async function pinDirectoryForMode(params) {
|
|
|
46
46
|
if (process.platform === "win32") {
|
|
47
47
|
return;
|
|
48
48
|
}
|
|
49
|
-
const expected = params.fsModule === fs
|
|
49
|
+
const expected = params.expectedIdentity ?? (params.fsModule === fs
|
|
50
50
|
? inspectFileIdentitySync(() => assertDirectory(syncFs.lstatSync(params.dirPath, { bigint: true }), params.dirPath))
|
|
51
|
-
: await inspectFileIdentity(async () => assertDirectory(await params.fsModule.lstat(params.dirPath, { bigint: true }), params.dirPath));
|
|
51
|
+
: await inspectFileIdentity(async () => assertDirectory(await params.fsModule.lstat(params.dirPath, { bigint: true }), params.dirPath)));
|
|
52
52
|
const handle = await params.fsModule.open(params.dirPath, directoryOpenFlags());
|
|
53
53
|
try {
|
|
54
54
|
const owner = ownDirectoryMode({
|
|
@@ -86,7 +86,7 @@ export function* applyDirectoryMode(io, params) {
|
|
|
86
86
|
}));
|
|
87
87
|
let primary;
|
|
88
88
|
try {
|
|
89
|
-
if (owner)
|
|
89
|
+
if (owner && params.mode !== "preserve")
|
|
90
90
|
yield* wait(owner.apply(params.mode));
|
|
91
91
|
}
|
|
92
92
|
catch (error) {
|
|
@@ -107,13 +107,15 @@ export function* applyDirectoryMode(io, params) {
|
|
|
107
107
|
if (process.platform === "win32")
|
|
108
108
|
return;
|
|
109
109
|
const admit = (stat) => assertDirectory(stat, params.dirPath);
|
|
110
|
-
const expected = inspectAtomicIdentity(io, () => io.lstatExact(params.dirPath), undefined, false, admit);
|
|
110
|
+
const expected = params.expectedIdentity ?? inspectAtomicIdentity(io, () => io.lstatExact(params.dirPath), undefined, false, admit);
|
|
111
111
|
const file = yield* io.open(params.dirPath, directoryOpenFlags());
|
|
112
112
|
let primary;
|
|
113
113
|
try {
|
|
114
114
|
inspectAtomicIdentity(io, () => file.statExact(), expected, false, admit);
|
|
115
|
-
params.
|
|
116
|
-
|
|
115
|
+
if (params.mode !== "preserve") {
|
|
116
|
+
params.mutation?.assert();
|
|
117
|
+
file.chmod(params.mode & 0o7777);
|
|
118
|
+
}
|
|
117
119
|
}
|
|
118
120
|
catch (error) {
|
|
119
121
|
primary = { error };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type syncFs from "node:fs";
|
|
2
|
+
import type { DirectoryMode } from "./directory-mode-options.js";
|
|
2
3
|
import type fs from "node:fs/promises";
|
|
3
4
|
import type { RenameIdentityPolicy } from "./pinned-write-types.js";
|
|
4
5
|
import type { AtomicMutationOptions } from "./replace-file-mutation.js";
|
|
@@ -12,7 +13,7 @@ export type ReplaceFileAtomicSyncFileSystem = Pick<typeof syncFs, "mkdirSync" |
|
|
|
12
13
|
export type ReplaceFileAtomicBaseOptions = AtomicMutationOptions & {
|
|
13
14
|
filePath: string;
|
|
14
15
|
content: string | Uint8Array;
|
|
15
|
-
dirMode?:
|
|
16
|
+
dirMode?: DirectoryMode;
|
|
16
17
|
mode?: number;
|
|
17
18
|
/** Inherit only rwx bits from an existing non-symlink regular file. */
|
|
18
19
|
preserveExistingMode?: boolean;
|
|
@@ -4,7 +4,8 @@ import fs from "node:fs/promises";
|
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import { recursiveMkdirPath } from "./recursive-mkdir-path.js";
|
|
6
6
|
import { assertDestinationHardlinkPolicy, copyFallbackReplace } from "./replace-file-copy-fallback.js";
|
|
7
|
-
import {
|
|
7
|
+
import { syncDirectoryBestEffort, writeTempFile } from "./replace-file-descriptor.js";
|
|
8
|
+
import { prepareDirectoryMode } from "./prepare-directory-mode.js";
|
|
8
9
|
import { inheritedRegularFileMode } from "./replace-file-mode.js";
|
|
9
10
|
import { atomicExpectedContentHash, validateRenameIdentity, withAtomicRenameIdentityLock, withAtomicRenameIdentityLockSync, } from "./replace-file-rename-policy.js";
|
|
10
11
|
import { AtomicTempOwner } from "./replace-file-temp-owner.js";
|
|
@@ -109,10 +110,14 @@ export async function replaceFileAtomicWithDirectorySync(options, syncParent) {
|
|
|
109
110
|
const fsModule = options.fileSystem?.promises ?? fs;
|
|
110
111
|
const dir = path.dirname(filePath);
|
|
111
112
|
mutation.assert();
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
mode:
|
|
115
|
-
}
|
|
113
|
+
const dirMode = options.dirMode ?? 0o700;
|
|
114
|
+
if (dirMode === "preserve") {
|
|
115
|
+
await runAsync(prepareDirectoryMode(AtomicIo.async(fsModule), { dirPath: dir, mode: "preserve", mutation }));
|
|
116
|
+
}
|
|
117
|
+
else
|
|
118
|
+
await fsModule.mkdir(fsModule === fs ? recursiveMkdirPath(dir) : dir, {
|
|
119
|
+
recursive: true, mode: dirMode,
|
|
120
|
+
});
|
|
116
121
|
mutation.assert();
|
|
117
122
|
return await withAtomicRenameIdentityLock(filePath, () => replaceAsync(options, filePath, renameIdentity, mutation, syncParent));
|
|
118
123
|
});
|
|
@@ -132,10 +137,14 @@ export function replaceFileAtomicSync(options) {
|
|
|
132
137
|
const fsModule = options.fileSystem ?? syncFs;
|
|
133
138
|
const dir = path.dirname(filePath);
|
|
134
139
|
mutation.assert();
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
mode:
|
|
138
|
-
}
|
|
140
|
+
const dirMode = options.dirMode ?? 0o700;
|
|
141
|
+
if (dirMode === "preserve") {
|
|
142
|
+
runSync(prepareDirectoryMode(AtomicIo.sync(fsModule, fsModule.fchmodSync), { dirPath: dir, mode: "preserve", mutation }));
|
|
143
|
+
}
|
|
144
|
+
else
|
|
145
|
+
fsModule.mkdirSync(fsModule === syncFs ? recursiveMkdirPath(dir) : dir, {
|
|
146
|
+
recursive: true, mode: dirMode,
|
|
147
|
+
});
|
|
139
148
|
mutation.assert();
|
|
140
149
|
return withAtomicRenameIdentityLockSync(filePath, () => replaceSync(options, filePath, renameIdentity, mutation));
|
|
141
150
|
}
|
|
@@ -151,7 +160,7 @@ function* replace(io, options, filePath, renameIdentity, mutation, syncParent) {
|
|
|
151
160
|
const syncOptions = options;
|
|
152
161
|
io.fchmodSync = syncOptions.fileSystem?.fchmodSync ?? (syncOptions.fileSystem === undefined ? syncFs.fchmodSync : undefined);
|
|
153
162
|
if (!io.fchmodSync && (options.mode !== undefined || options.preserveExistingMode === true ||
|
|
154
|
-
(process.platform !== "win32" && options.dirMode
|
|
163
|
+
(process.platform !== "win32" && typeof options.dirMode === "number"))) {
|
|
155
164
|
throw new TypeError("fileSystem.fchmodSync is required when mode, dirMode, or preserveExistingMode is specified");
|
|
156
165
|
}
|
|
157
166
|
}
|
|
@@ -159,9 +168,7 @@ function* replace(io, options, filePath, renameIdentity, mutation, syncParent) {
|
|
|
159
168
|
const tempOwner = new AtomicTempOwner(tempPath, io);
|
|
160
169
|
let originalFailure;
|
|
161
170
|
try {
|
|
162
|
-
mutation
|
|
163
|
-
yield* io.mkdir(dir, dirMode);
|
|
164
|
-
yield* applyDirectoryMode(io, { dirPath: dir, mode: dirMode, mutation });
|
|
171
|
+
yield* prepareDirectoryMode(io, { dirPath: dir, mode: dirMode, mutation });
|
|
165
172
|
tempOwner.start();
|
|
166
173
|
tempOwner.adopt(yield* writeTempFile(io, {
|
|
167
174
|
tempPath,
|
|
@@ -6,7 +6,7 @@ import { FsSafeError } from "./errors.js";
|
|
|
6
6
|
import { assertNoNulPathInput, assertNoUnsafeDeviceReadPath, hasNodeErrorCode, isNotFoundPathError, isPathInside, } from "./path.js";
|
|
7
7
|
import { ROOT_PATH_ALIAS_POLICIES, resolveRootPath } from "./root-path.js";
|
|
8
8
|
import { admitPathInsideRoot } from "./root-boundary.js";
|
|
9
|
-
import { errorCauseOptions, outsideWorkspaceError, rootPathChangedError } from "./root-errors.js";
|
|
9
|
+
import { errorCauseOptions, outsideWorkspaceError, pathTraversalPermissionError, rootPathChangedError } from "./root-errors.js";
|
|
10
10
|
import { isDriveRelativePath } from "./safe-path-segment.js";
|
|
11
11
|
import { realpathSync } from "./realpath.js";
|
|
12
12
|
import { inspectFileIdentity } from "./strict-file-identity.js";
|
|
@@ -205,6 +205,9 @@ export async function resolvePathInRoot(root, relativePath, options) {
|
|
|
205
205
|
}
|
|
206
206
|
}
|
|
207
207
|
catch (error) {
|
|
208
|
+
const permissionError = pathTraversalPermissionError(error, rawAbsolutePath);
|
|
209
|
+
if (permissionError)
|
|
210
|
+
throw permissionError;
|
|
208
211
|
if (error instanceof FsSafeError && error.code === "symlink") {
|
|
209
212
|
throw error;
|
|
210
213
|
}
|
|
@@ -32,7 +32,7 @@ export type MissingWritableFileInRoot = {
|
|
|
32
32
|
};
|
|
33
33
|
export declare function isNativeCreateCollision(error: unknown): boolean;
|
|
34
34
|
/** Admit only an ordinary direct child; aliases keep the full resolver. */
|
|
35
|
-
export declare function tryMkdirNativeDirectChild(root: RootContext, relativePath: string): boolean;
|
|
35
|
+
export declare function tryMkdirNativeDirectChild(root: RootContext, relativePath: string, mode?: number): boolean;
|
|
36
36
|
export declare function tryMkdirRootNative(params: Creation): Promise<boolean>;
|
|
37
37
|
export declare function verifyMkdirDirectory(binding: NativeBinding, fd: number, pathname: string): void;
|
|
38
38
|
export declare function ensureNativeRootCurrent(root: RootContext): void;
|
|
@@ -56,7 +56,7 @@ import { randomUUID } from "node:crypto";
|
|
|
56
56
|
import fsAsync from "node:fs/promises";
|
|
57
57
|
import path from "node:path";
|
|
58
58
|
import { assertSyncDirectoryGuard, inspectDirectoryIdentitySync } from "./directory-guard.js";
|
|
59
|
-
import { nodeDirectorySearchOnlyFlags } from "./directory-mode-node.js";
|
|
59
|
+
import { finalizeCreatedDirectoryModeSync, nodeDirectorySearchOnlyFlags } from "./directory-mode-node.js";
|
|
60
60
|
import { assertDarwinCreationAcl, assertPrivateDirectory } from "./creation-boundary.js";
|
|
61
61
|
import { assertMutationNotDenied } from "./deny-mutations.js";
|
|
62
62
|
import { FsSafeError } from "./errors.js";
|
|
@@ -295,7 +295,7 @@ async function withNativeDirectory(params, operation, discard) {
|
|
|
295
295
|
}
|
|
296
296
|
}
|
|
297
297
|
/** Admit only an ordinary direct child; aliases keep the full resolver. */
|
|
298
|
-
export function tryMkdirNativeDirectChild(root, relativePath) {
|
|
298
|
+
export function tryMkdirNativeDirectChild(root, relativePath, mode) {
|
|
299
299
|
if (!isSafePathSegment(relativePath, { allowDotPrefix: true }) || relativePath.endsWith(".") ||
|
|
300
300
|
getFsSafeTestHooks()?.beforeRootFallbackMutation)
|
|
301
301
|
return false;
|
|
@@ -311,7 +311,7 @@ export function tryMkdirNativeDirectChild(root, relativePath) {
|
|
|
311
311
|
return false;
|
|
312
312
|
}
|
|
313
313
|
try {
|
|
314
|
-
mkdirNativeRootChild({ root, target });
|
|
314
|
+
mkdirNativeRootChild({ root, target }, mode);
|
|
315
315
|
return true;
|
|
316
316
|
}
|
|
317
317
|
catch (error) {
|
|
@@ -420,7 +420,7 @@ function ensureNativeRootCurrentLegacy(root, binding) {
|
|
|
420
420
|
__disposeResources(env_4);
|
|
421
421
|
}
|
|
422
422
|
}
|
|
423
|
-
function mkdirNativeRootChild(params) {
|
|
423
|
+
function mkdirNativeRootChild(params, mode) {
|
|
424
424
|
const env_5 = { stack: [], error: void 0, hasError: false };
|
|
425
425
|
try {
|
|
426
426
|
const binding = getNativeBinding("openBeneath", "mkdirChildBeneath");
|
|
@@ -430,19 +430,28 @@ function mkdirNativeRootChild(params) {
|
|
|
430
430
|
rootPath: params.root.rootReal, rootIdentity: params.root.rootIdentity,
|
|
431
431
|
}), false);
|
|
432
432
|
verifyMkdirDirectory(binding, rootOwner.fd, params.root.rootReal);
|
|
433
|
-
const flags = (nodeDirectorySearchOnlyFlags()?.flags ?? fs.constants.O_RDONLY) |
|
|
433
|
+
const flags = (mode === undefined ? nodeDirectorySearchOnlyFlags()?.flags ?? fs.constants.O_RDONLY : fs.constants.O_RDONLY) |
|
|
434
434
|
(fs.constants.O_DIRECTORY ?? 0) | (fs.constants.O_NOFOLLOW ?? 0);
|
|
435
435
|
const name = path.basename(params.target);
|
|
436
436
|
// The admitted Root is already this operation's immediate parent. Retain
|
|
437
437
|
// both handles through the same fresh pathname and canonical identity fences.
|
|
438
438
|
const child = binding.mkdirOpenChildBeneath
|
|
439
|
-
? binding.mkdirOpenChildBeneath(rootOwner.fd, name, 0o777, flags)
|
|
440
|
-
:
|
|
439
|
+
? binding.mkdirOpenChildBeneath(rootOwner.fd, name, mode ?? 0o777, flags)
|
|
440
|
+
: {
|
|
441
|
+
created: binding.mkdirChildBeneath(rootOwner.fd, name, mode ?? 0o777),
|
|
442
|
+
fd: binding.openBeneath(rootOwner.fd, name, flags).fd,
|
|
443
|
+
};
|
|
441
444
|
const close = captureNativeFdClose(binding);
|
|
442
|
-
const childOwner = __addDisposableResource(env_5, { [Symbol.dispose]() { close(child); } }, false);
|
|
445
|
+
const childOwner = __addDisposableResource(env_5, { [Symbol.dispose]() { close(child.fd); } }, false);
|
|
443
446
|
assertRootIdentityCurrentSync(params.root);
|
|
444
|
-
verifyMkdirDirectory(binding, child, params.target);
|
|
447
|
+
verifyMkdirDirectory(binding, child.fd, params.target);
|
|
445
448
|
verifyMkdirDirectory(binding, rootOwner.fd, params.root.rootReal);
|
|
449
|
+
if (mode !== undefined && child.created) {
|
|
450
|
+
finalizeCreatedDirectoryModeSync(child, mode);
|
|
451
|
+
verifyMkdirDirectory(binding, child.fd, params.target);
|
|
452
|
+
verifyMkdirDirectory(binding, rootOwner.fd, params.root.rootReal);
|
|
453
|
+
assertRootIdentityCurrentSync(params.root);
|
|
454
|
+
}
|
|
446
455
|
}
|
|
447
456
|
catch (e_5) {
|
|
448
457
|
env_5.error = e_5;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { FsSafeError, type FsSafeErrorDetails } from "./errors.js";
|
|
2
2
|
export declare function fileNotFoundError(cause?: unknown, details?: FsSafeErrorDetails): FsSafeError;
|
|
3
3
|
export declare function outsideWorkspaceError(): FsSafeError;
|
|
4
|
+
/** Classify raw traversal denials without disguising an established policy failure. */
|
|
5
|
+
export declare function pathTraversalPermissionError(error: unknown, targetPath: string): FsSafeError | undefined;
|
|
4
6
|
export declare function rootPathChangedError(cause?: Error): FsSafeError;
|
|
5
7
|
export declare function directoryComponentNotDirectoryError(cause?: unknown): FsSafeError;
|
|
6
8
|
export declare function hardlinkedPathNotAllowedError(): FsSafeError;
|
|
@@ -15,6 +15,15 @@ export function fileNotFoundError(cause, details) {
|
|
|
15
15
|
export function outsideWorkspaceError() {
|
|
16
16
|
return new FsSafeError("outside-workspace", "file is outside workspace root");
|
|
17
17
|
}
|
|
18
|
+
/** Classify raw traversal denials without disguising an established policy failure. */
|
|
19
|
+
export function pathTraversalPermissionError(error, targetPath) {
|
|
20
|
+
if (error instanceof FsSafeError)
|
|
21
|
+
return error.code === "permission-denied" ? error : undefined;
|
|
22
|
+
if (!hasNodeErrorCode(error, "EACCES") && !hasNodeErrorCode(error, "EPERM"))
|
|
23
|
+
return;
|
|
24
|
+
const deniedPath = isNodeError(error) && typeof error.path === "string" ? error.path : targetPath;
|
|
25
|
+
return new FsSafeError("permission-denied", `permission denied while resolving ${deniedPath}`, errorCauseOptions(error));
|
|
26
|
+
}
|
|
18
27
|
export function rootPathChangedError(cause) {
|
|
19
28
|
return new FsSafeError("path-mismatch", "root path changed during operation", { cause });
|
|
20
29
|
}
|
|
@@ -90,7 +90,7 @@ import { listDirectoryPath, openRootDirectoryListing } from "./root-directory-li
|
|
|
90
90
|
import { statResolvedPathInRoot } from "./root-path-stat.js";
|
|
91
91
|
import { entriesInRoot } from "./root-entries.js";
|
|
92
92
|
import { assertRootIdentityCurrent, assertRootIdentityCurrentSync, assertValidRootDestinationPath, assertValidRootRelativePath, createRootObservationGuard, ensureTrailingSep, expandRelativePathWithHome, resolvePathInRoot, resolveRootContext, rootRelativeReadPath, } from "./root-context.js";
|
|
93
|
-
import { errorCauseOptions, fileNotFoundError, hardlinkedPathNotAllowedError, isAlreadyExistsError, normalizePinnedPathError, normalizePinnedWriteError, outsideWorkspaceError, } from "./root-errors.js";
|
|
93
|
+
import { errorCauseOptions, fileNotFoundError, hardlinkedPathNotAllowedError, isAlreadyExistsError, normalizePinnedPathError, normalizePinnedWriteError, outsideWorkspaceError, pathTraversalPermissionError, } from "./root-errors.js";
|
|
94
94
|
import { getFsSafeTestHooks } from "./test-hooks.js";
|
|
95
95
|
import { stringifyJsonDocument } from "./json-stringify.js";
|
|
96
96
|
import { walkRoot } from "./root-walk.js";
|
|
@@ -1078,6 +1078,9 @@ async function resolvePinnedRootPathInRoot(root, params) {
|
|
|
1078
1078
|
resolved = await (params.removalReceipts ? resolveRootPathForRemoval(resolution, params.removalReceipts) : resolveRootPath(resolution));
|
|
1079
1079
|
}
|
|
1080
1080
|
catch (err) {
|
|
1081
|
+
const permissionError = pathTraversalPermissionError(err, params.relativePath);
|
|
1082
|
+
if (permissionError)
|
|
1083
|
+
throw permissionError;
|
|
1081
1084
|
if (err instanceof FsSafeError && err.code === "symlink")
|
|
1082
1085
|
throw err;
|
|
1083
1086
|
throw new FsSafeError("path-alias", "path alias escape blocked", { cause: err });
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { type RootContext } from "./root-context.js";
|
|
2
|
-
export declare function tryMkdirNativeParents(root: RootContext, relativePath: string): boolean;
|
|
2
|
+
export declare function tryMkdirNativeParents(root: RootContext, relativePath: string, mode?: number): boolean;
|