@openclaw/matrix 2026.11.6 → 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-CshxBDs7.mjs → approval-handler.runtime-LBvkygUK.mjs} +3 -3
- package/dist/.setup/{channel-OLndtGNE.mjs → channel-CHryi9FS.mjs} +7 -7
- package/dist/.setup/{channel.runtime-CFSou_MS.mjs → channel.runtime-DluXWaGb.mjs} +2 -2
- package/dist/.setup/{channel.setup-CqcEb6JR.mjs → channel.setup-BDbs0FLq.mjs} +2 -2
- package/dist/.setup/{cli-CkMedN4Y.mjs → cli-C7Jmy2x4.mjs} +6 -6
- package/dist/.setup/{cli-metadata-DN1E7yCf.mjs → cli-metadata-B0GHIn05.mjs} +1 -1
- package/dist/.setup/{client-Rlwtz1hG.mjs → client-mFRVrUt3.mjs} +1 -1
- package/dist/.setup/{draft-stream-DbTsJkoL.mjs → draft-stream-bVedfEB3.mjs} +1 -1
- package/dist/.setup/{exec-approvals-CiGrN-cV.mjs → exec-approvals-BeYF9-3o.mjs} +2 -2
- package/dist/.setup/{messages-DJDczJnC.mjs → messages-BqVczVlt.mjs} +2 -2
- package/dist/.setup/{monitor-ZDbuZRVB.mjs → monitor-BsSo3tCv.mjs} +29 -15
- package/dist/.setup/{onboarding-DwhMV1fp.mjs → onboarding-CoMpgTiK.mjs} +1 -1
- package/dist/.setup/{outbound-7iSmOloX.mjs → outbound-ntm0KOfK.mjs} +2 -2
- package/dist/.setup/{profile-update-Fu4u-aSC.mjs → profile-update-gC436enW.mjs} +8 -3
- package/dist/.setup/{reaction-events-CBltCP52.mjs → reaction-events-DTThoaJQ.mjs} +3 -3
- package/dist/.setup/{room-info-DFDDmkBC.mjs → room-info-CM3MKoh4.mjs} +3 -3
- package/dist/.setup/{send-DiS4anyi.mjs → send-DFB7JGg2.mjs} +6 -6
- package/dist/.setup/{setup-bootstrap-OfuocnF0.mjs → setup-bootstrap-razh2kSp.mjs} +2 -2
- package/dist/.setup/{setup-core-CEQJRnym.mjs → setup-core-BVbxltMM.mjs} +1 -1
- package/dist/.setup/setup-plugin-api-CQKySg7F.mjs +2 -0
- package/dist/.setup/{thread-bindings-BvoisBZE.mjs → thread-bindings-D5VJEDZV.mjs} +1 -1
- package/dist/.setup/{tool-actions-TYBYDIkj.mjs → tool-actions-DexlmVDf.mjs} +9 -9
- package/dist/.setup/{verification-BhFA9xF6.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/index.js +1 -1
- package/dist/plugin-entry.handlers.runtime.js +1 -1
- 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/package.json +5 -5
- package/dist/.setup/setup-plugin-api-4hHy1k4x.mjs +0 -2
|
@@ -11,6 +11,13 @@ import { rootFromDirectoryGuard } from "./root-impl.js";
|
|
|
11
11
|
import { prepareSecretFileWrite } from "./secret-file.js";
|
|
12
12
|
import { resolveSecureTempRoot } from "./secure-temp-dir.js";
|
|
13
13
|
import { recursiveMkdirPath } from "./recursive-mkdir-path.js";
|
|
14
|
+
import { AtomicIo, runAsync } from "./atomic-io.js";
|
|
15
|
+
import { prepareDirectoryMode } from "./prepare-directory-mode.js";
|
|
16
|
+
import { mkdirPathComponentsWithGuards } from "./guarded-mkdir.js";
|
|
17
|
+
import { rootHandleContext } from "./root-handle-context.js";
|
|
18
|
+
import { isFsSafeNativeRequired } from "./native-config.js";
|
|
19
|
+
import { tryMkdirNativeDirectChild } from "./root-create-native.js";
|
|
20
|
+
import { tryMkdirNativeParents } from "./root-mkdir-native.js";
|
|
14
21
|
import { readRegularFile } from "./regular-file.js";
|
|
15
22
|
import { assertExclusiveCreateLeaf } from "./exclusive-create.js";
|
|
16
23
|
import { errorCauseOptions } from "./root-errors.js";
|
|
@@ -20,13 +27,32 @@ export async function ensureParentInRoot(scopedRoot, relativePath, mode) {
|
|
|
20
27
|
if (parent === ".") {
|
|
21
28
|
return;
|
|
22
29
|
}
|
|
23
|
-
|
|
24
|
-
|
|
30
|
+
if (mode === "preserve") {
|
|
31
|
+
const context = rootHandleContext(scopedRoot);
|
|
32
|
+
const relativeParent = path.posix.dirname(relativePath);
|
|
33
|
+
if (isFsSafeNativeRequired() && (tryMkdirNativeDirectChild(context, relativeParent, 0o700) ||
|
|
34
|
+
tryMkdirNativeParents(context, relativeParent, 0o700)))
|
|
35
|
+
return;
|
|
36
|
+
await mkdirPathComponentsWithGuards({
|
|
37
|
+
rootReal: context.rootReal, rootIdentity: context.rootIdentity,
|
|
38
|
+
targetPath: path.join(context.rootReal, parent),
|
|
39
|
+
mode: 0o700, finalizeCreatedMode: true, rejectSymlinks: true,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
await scopedRoot.mkdir(parent);
|
|
44
|
+
await chmodDirectoryInRootBestEffort(scopedRoot, parent, mode).catch(() => undefined);
|
|
45
|
+
}
|
|
25
46
|
}
|
|
26
47
|
export async function openWritableStoreRoot(params) {
|
|
27
48
|
assertNoWindowsPathAlias(params.rootDir, "filesystem", "store root uses a Windows filesystem namespace alias");
|
|
28
|
-
|
|
29
|
-
|
|
49
|
+
if (params.dirMode === "preserve") {
|
|
50
|
+
await runAsync(prepareDirectoryMode(AtomicIo.async(fs), { dirPath: params.rootDir, mode: "preserve" }));
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
await fs.mkdir(recursiveMkdirPath(params.rootDir), { recursive: true, mode: params.dirMode });
|
|
54
|
+
await fs.chmod(params.rootDir, params.dirMode).catch(() => undefined);
|
|
55
|
+
}
|
|
30
56
|
return await root(params.rootDir, { hardlinks: "reject", maxBytes: params.maxBytes });
|
|
31
57
|
}
|
|
32
58
|
export async function openPrivateStoreLockRoot(params) {
|
|
@@ -6,6 +6,8 @@ import { literalStoreRootPath } from "./file-store-boundary.js";
|
|
|
6
6
|
import { isPathInside } from "./path.js";
|
|
7
7
|
import { realpathSync } from "./realpath.js";
|
|
8
8
|
import { recursiveMkdirPath } from "./recursive-mkdir-path.js";
|
|
9
|
+
import { AtomicIo, runAsync } from "./atomic-io.js";
|
|
10
|
+
import { prepareDirectoryMode } from "./prepare-directory-mode.js";
|
|
9
11
|
import { root } from "./root.js";
|
|
10
12
|
import { nonrecursiveRemovalKind } from "./root-remove.js";
|
|
11
13
|
import { getFsSafeTestHooks } from "./test-hooks.js";
|
|
@@ -17,7 +19,11 @@ export async function pruneExpiredStoreEntries(params) {
|
|
|
17
19
|
const recursive = params.options.recursive ?? false;
|
|
18
20
|
const maxDepth = params.options.maxDepth;
|
|
19
21
|
const pruneEmptyDirs = (recursive || maxDepth !== undefined) && (params.options.pruneEmptyDirs ?? false);
|
|
20
|
-
|
|
22
|
+
if (params.dirMode === "preserve") {
|
|
23
|
+
await runAsync(prepareDirectoryMode(AtomicIo.async(fs), { dirPath: params.rootDir, mode: "preserve" }));
|
|
24
|
+
}
|
|
25
|
+
else
|
|
26
|
+
await fs.mkdir(recursiveMkdirPath(params.rootDir), { recursive: true, mode: params.dirMode });
|
|
21
27
|
const rootReal = realpathSync.native(params.rootDir);
|
|
22
28
|
const scopedRoot = await root(rootReal);
|
|
23
29
|
const rootGuard = {
|
|
@@ -8,7 +8,7 @@ export type SyncStoreDirectoryReceipt = Readonly<{
|
|
|
8
8
|
export declare function ensureSyncStoreDirectory(params: {
|
|
9
9
|
rootDir: string;
|
|
10
10
|
targetDir: string;
|
|
11
|
-
mode: number;
|
|
11
|
+
mode: number | "preserve";
|
|
12
12
|
messagePrefix: StoreMessagePrefix;
|
|
13
13
|
}): SyncStoreDirectoryReceipt;
|
|
14
14
|
export declare function assertSyncStoreDirectoryReceipt(receipt: SyncStoreDirectoryReceipt): void;
|
|
@@ -4,6 +4,9 @@ import { FsSafeError } from "./errors.js";
|
|
|
4
4
|
import { isPathInside, isPathRelativeEscape } from "./path.js";
|
|
5
5
|
import { realpathSync } from "./realpath.js";
|
|
6
6
|
import { recursiveMkdirPath } from "./recursive-mkdir-path.js";
|
|
7
|
+
import { AtomicIo, runSync } from "./atomic-io.js";
|
|
8
|
+
import { prepareDirectoryMode } from "./prepare-directory-mode.js";
|
|
9
|
+
import { applyDirectoryMode } from "./replace-file-descriptor.js";
|
|
7
10
|
import { inspectFileIdentitySync } from "./strict-file-identity.js";
|
|
8
11
|
import { createSuppressedError } from "./suppressed-error.js";
|
|
9
12
|
import { assertNoWindowsPathAlias, pathForWindowsFilesystem, resolvePathPreservingWindowsRoot, } from "./windows-path-alias.js";
|
|
@@ -212,6 +215,14 @@ class StoreDirectoryChain {
|
|
|
212
215
|
throw changedStoreDirectory(this.messagePrefix, error);
|
|
213
216
|
}
|
|
214
217
|
}
|
|
218
|
+
preserveMode() {
|
|
219
|
+
const receipt = this.receipts.at(-1);
|
|
220
|
+
this.assertEdge();
|
|
221
|
+
runSync(applyDirectoryMode(AtomicIo.sync(fs), {
|
|
222
|
+
dirPath: pathForWindowsFilesystem(receipt.dir), mode: "preserve", expectedIdentity: receipt.stat,
|
|
223
|
+
}));
|
|
224
|
+
this.assertEdge();
|
|
225
|
+
}
|
|
215
226
|
finalizeMode(mode) {
|
|
216
227
|
const receipt = this.receipts.at(-1);
|
|
217
228
|
const requestedMode = BigInt(mode & 0o7777);
|
|
@@ -274,9 +285,18 @@ export function ensureSyncStoreDirectory(params) {
|
|
|
274
285
|
if (isPathRelativeEscape(relative)) {
|
|
275
286
|
throw new FsSafeError("outside-workspace", "file path escapes store root");
|
|
276
287
|
}
|
|
277
|
-
|
|
288
|
+
const preserve = (directory) => runSync(prepareDirectoryMode(AtomicIo.sync(fs, fs.fchmodSync), {
|
|
289
|
+
dirPath: pathForWindowsFilesystem(directory), mode: "preserve",
|
|
290
|
+
}));
|
|
291
|
+
if (params.mode === "preserve")
|
|
292
|
+
preserve(rootDir);
|
|
293
|
+
else
|
|
294
|
+
fs.mkdirSync(recursiveMkdirPath(pathForWindowsFilesystem(rootDir)), { recursive: true, mode: params.mode });
|
|
278
295
|
const chain = new StoreDirectoryChain(rootDir, params.messagePrefix);
|
|
279
|
-
|
|
296
|
+
if (params.mode === "preserve")
|
|
297
|
+
chain.preserveMode();
|
|
298
|
+
else
|
|
299
|
+
chain.finalizeMode(params.mode);
|
|
280
300
|
let current = rootDir;
|
|
281
301
|
for (const segment of relative.split(path.sep).filter(Boolean)) {
|
|
282
302
|
current = path.join(current, segment);
|
|
@@ -286,10 +306,16 @@ export function ensureSyncStoreDirectory(params) {
|
|
|
286
306
|
catch (error) {
|
|
287
307
|
if (error.code !== "ENOENT")
|
|
288
308
|
throw error;
|
|
289
|
-
|
|
309
|
+
if (params.mode === "preserve")
|
|
310
|
+
preserve(current);
|
|
311
|
+
else
|
|
312
|
+
fs.mkdirSync(pathForWindowsFilesystem(current), { mode: params.mode });
|
|
290
313
|
chain.observe(current);
|
|
291
314
|
}
|
|
292
|
-
|
|
315
|
+
if (params.mode === "preserve")
|
|
316
|
+
chain.preserveMode();
|
|
317
|
+
else
|
|
318
|
+
chain.finalizeMode(params.mode);
|
|
293
319
|
}
|
|
294
320
|
return chain.finish(dir);
|
|
295
321
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
2
|
import fs, {} from "node:fs";
|
|
3
3
|
import path from "node:path";
|
|
4
|
+
import { rejectPrivateDirectoryPreservation } from "./directory-mode-options.js";
|
|
4
5
|
import { syncDirectorySync } from "./directory-durability.js";
|
|
5
6
|
import { createDirectoryReceiptFromIdentity } from "./directory-receipt.js";
|
|
6
7
|
import { FsSafeError } from "./errors.js";
|
|
@@ -50,6 +51,7 @@ export function writeFileSyncAtomic(params) {
|
|
|
50
51
|
}
|
|
51
52
|
let parentGuard;
|
|
52
53
|
if (params.privateMode) {
|
|
54
|
+
rejectPrivateDirectoryPreservation(params.dirMode);
|
|
53
55
|
parentGuard = ensureStoreDirectorySync({
|
|
54
56
|
rootDir: params.rootDir,
|
|
55
57
|
targetDir: path.dirname(filePath),
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type DirectoryMode } from "./directory-mode-options.js";
|
|
1
2
|
import type { Readable } from "node:stream";
|
|
2
3
|
import { type FileStorePruneOptions } from "./file-store-prune.js";
|
|
3
4
|
export type { FileStorePruneOptions } from "./file-store-prune.js";
|
|
@@ -8,7 +9,7 @@ export type FileStoreOptions = {
|
|
|
8
9
|
private?: boolean;
|
|
9
10
|
/** Default for writes, streams, and copies; true syncs file and parent where supported. */
|
|
10
11
|
durable?: boolean;
|
|
11
|
-
dirMode?:
|
|
12
|
+
dirMode?: DirectoryMode;
|
|
12
13
|
mode?: number;
|
|
13
14
|
maxBytes?: number;
|
|
14
15
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import syncFs from "node:fs";
|
|
2
|
+
import { rejectPrivateDirectoryPreservation } from "./directory-mode-options.js";
|
|
2
3
|
import { normalizeMaxBytes } from "./byte-budget.js";
|
|
3
4
|
import { readFileDescriptorBoundedSync } from "./bounded-read.js";
|
|
4
5
|
import { FsSafeError } from "./errors.js";
|
|
@@ -84,6 +85,8 @@ export function fileStore(options) {
|
|
|
84
85
|
assertNoWindowsPathAlias(rootDir, "filesystem", "store root uses a Windows filesystem namespace alias");
|
|
85
86
|
const privateMode = options.private ?? false;
|
|
86
87
|
const dirMode = options.dirMode ?? 0o700;
|
|
88
|
+
if (privateMode)
|
|
89
|
+
rejectPrivateDirectoryPreservation(dirMode);
|
|
87
90
|
const mode = options.mode ?? 0o600;
|
|
88
91
|
const durable = options.durable ?? true;
|
|
89
92
|
const maxBytes = normalizeMaxBytes(options.maxBytes);
|
|
@@ -289,6 +292,8 @@ export function fileStoreSync(options) {
|
|
|
289
292
|
assertNoWindowsPathAlias(rootDir, "filesystem", "store root uses a Windows filesystem namespace alias");
|
|
290
293
|
const privateMode = options.private ?? false;
|
|
291
294
|
const dirMode = options.dirMode ?? 0o700;
|
|
295
|
+
if (privateMode)
|
|
296
|
+
rejectPrivateDirectoryPreservation(dirMode);
|
|
292
297
|
const mode = options.mode ?? 0o600;
|
|
293
298
|
const durable = options.durable ?? true;
|
|
294
299
|
const maxBytes = normalizeMaxBytes(options.maxBytes);
|
|
@@ -16,6 +16,8 @@ export declare function mkdirPathComponentsWithGuards(params: {
|
|
|
16
16
|
createMissing?: boolean;
|
|
17
17
|
synchronousMkdir?: boolean;
|
|
18
18
|
mode?: number;
|
|
19
|
+
/** Correct only directories this walk exclusively creates; never change existing entries. */
|
|
20
|
+
finalizeCreatedMode?: boolean;
|
|
19
21
|
private?: boolean;
|
|
20
22
|
rejectSymlinks?: boolean;
|
|
21
23
|
revalidateParentAfterBeforeComponent?: boolean;
|
|
@@ -2,6 +2,8 @@ import fsSync, {} from "node:fs";
|
|
|
2
2
|
import fs from "node:fs/promises";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { createDirectoryWithAdmission } from "./create.js";
|
|
5
|
+
import { AtomicIo, runAsync } from "./atomic-io.js";
|
|
6
|
+
import { applyDirectoryMode } from "./replace-file-descriptor.js";
|
|
5
7
|
import { assertDirectoryGuard, captureDirectoryGuard, inspectDirectoryIdentitySync, } from "./directory-guard.js";
|
|
6
8
|
import { FsSafeError } from "./errors.js";
|
|
7
9
|
import { hasNodeErrorCode, isNotFoundPathError, isPathRelativeEscape } from "./path.js";
|
|
@@ -270,6 +272,13 @@ export async function mkdirPathComponentsWithGuards(params) {
|
|
|
270
272
|
if (!createdAuthorization || !createdEvidence) {
|
|
271
273
|
assertDirectoryGuard(parentGuard, "native");
|
|
272
274
|
}
|
|
275
|
+
if (created && params.finalizeCreatedMode && params.mode !== undefined) {
|
|
276
|
+
await runAsync(applyDirectoryMode(AtomicIo.async(fs), {
|
|
277
|
+
dirPath: currentGuard.dir, mode: params.mode, expectedIdentity: currentGuard.stat,
|
|
278
|
+
}));
|
|
279
|
+
assertDirectoryGuard(parentGuard, "native");
|
|
280
|
+
assertDirectoryGuard(currentGuard, "native");
|
|
281
|
+
}
|
|
273
282
|
current = admittedNextPath;
|
|
274
283
|
}
|
|
275
284
|
return current;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import type { DirectoryMode } from "./directory-mode-options.js";
|
|
1
2
|
import { type JsonFileStoreOptions, type JsonStore, type JsonStoreLockOptions } from "./json-document-store.js";
|
|
2
3
|
export type JsonStoreOptions<T> = JsonFileStoreOptions & {
|
|
3
4
|
filePath: string;
|
|
4
|
-
dirMode?:
|
|
5
|
+
dirMode?: DirectoryMode;
|
|
5
6
|
mode?: number;
|
|
6
7
|
};
|
|
7
8
|
export type { JsonFileStoreOptions, JsonStore, JsonStoreLockOptions };
|
|
@@ -247,7 +247,10 @@ export interface NativeBinding {
|
|
|
247
247
|
stagedSymlinkMatches?(parentFd: number, basename: string, linkFd: number): boolean;
|
|
248
248
|
publishStagedSymlink?(parentFd: number, basename: string, linkFd: number, destination: string): void;
|
|
249
249
|
removeStagedSymlink?(parentFd: number, basename: string, linkFd: number): "removed" | "name-absent" | "preserved";
|
|
250
|
-
createStagedFile?(parentFd: number, basename: string): number
|
|
250
|
+
createStagedFile?(parentFd: number, basename: string): Promise<number>;
|
|
251
|
+
/** POSIX staging: caller retains both parents until the worker settles. */
|
|
252
|
+
renameReplaceAsync?(sourceFd: number, source: string, targetFd: number, target: string): Promise<void>;
|
|
253
|
+
renameNoReplaceAsync?(sourceFd: number, source: string, targetFd: number, target: string): Promise<void>;
|
|
251
254
|
stagedFileMetadata?(parentFd: number, basename: string, fd: number): {
|
|
252
255
|
mode: bigint;
|
|
253
256
|
nlink: bigint;
|
|
@@ -62,7 +62,7 @@ import { cachedNoReplaceUnavailable } from "./native-noreplace.js";
|
|
|
62
62
|
import { isFsSafeNativeRequired } from "./native-config.js";
|
|
63
63
|
import { copyLinkAtParent } from "./copy-link.js";
|
|
64
64
|
const writeCapabilities = ["openBeneath", "mkdirBeneath", "renameNoReplace", "renameReplace"];
|
|
65
|
-
const posixWriteCapabilities = [...writeCapabilities, "createStagedFile", "stagedFileMatches", "removeStagedFile"];
|
|
65
|
+
const posixWriteCapabilities = [...writeCapabilities, "createStagedFile", "stagedFileMatches", "removeStagedFile", "renameReplaceAsync", "renameNoReplaceAsync"];
|
|
66
66
|
function pinnedWriteCapabilities(params) {
|
|
67
67
|
const windows = process.platform === "win32";
|
|
68
68
|
const capabilities = windows ? [...writeCapabilities, "fstatIdentity"] : posixWriteCapabilities;
|
|
@@ -5,7 +5,7 @@ import type { FileIdentityStat } from "./file-identity.js";
|
|
|
5
5
|
import { type NativeBinding } from "./native-binding.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 type NativeStagingBinding = NativeBinding & Required<Pick<NativeBinding, "createStagedFile" | "stagedFileMatches" | "removeStagedFile" | "
|
|
8
|
+
export type NativeStagingBinding = NativeBinding & Required<Pick<NativeBinding, "createStagedFile" | "stagedFileMatches" | "removeStagedFile" | "renameReplaceAsync" | "renameNoReplaceAsync">>;
|
|
9
9
|
export declare function assertNativeStaging(binding: NativeBinding): asserts binding is NativeStagingBinding;
|
|
10
10
|
type StagedPermissionPolicy = "private-creation" | "mode-only";
|
|
11
11
|
type NativeStageOwner = Readonly<{
|
|
@@ -76,8 +76,8 @@ export function assertNativeStaging(binding) {
|
|
|
76
76
|
binding.createStagedFile,
|
|
77
77
|
binding.stagedFileMatches,
|
|
78
78
|
binding.removeStagedFile,
|
|
79
|
-
binding.
|
|
80
|
-
binding.
|
|
79
|
+
binding.renameReplaceAsync,
|
|
80
|
+
binding.renameNoReplaceAsync,
|
|
81
81
|
].some((fn) => typeof fn !== "function")) {
|
|
82
82
|
throw new FsSafeError("helper-unavailable", "native retained-directory staging is unavailable");
|
|
83
83
|
}
|
|
@@ -97,7 +97,7 @@ class NativeStagedFile {
|
|
|
97
97
|
#verifyMode;
|
|
98
98
|
#state = { status: "open", publication: NOT_PUBLISHED };
|
|
99
99
|
#receipt;
|
|
100
|
-
#
|
|
100
|
+
#publicationTask;
|
|
101
101
|
#rejectFinalSymlink = false;
|
|
102
102
|
#unsupportedNoReplace;
|
|
103
103
|
#fallbackCleanup;
|
|
@@ -288,7 +288,7 @@ class NativeStagedFile {
|
|
|
288
288
|
if (this.#private)
|
|
289
289
|
assertDarwinCreationAcl(this.#owner.parentFd, "file");
|
|
290
290
|
try {
|
|
291
|
-
state.fileFd = this.#owner.binding.createStagedFile(this.#owner.parentFd, this.#owner.name);
|
|
291
|
+
state.fileFd = await this.#owner.binding.createStagedFile(this.#owner.parentFd, this.#owner.name);
|
|
292
292
|
}
|
|
293
293
|
catch (error) {
|
|
294
294
|
annotateReadOnlyOpenError(error, path.join(this.#owner.directory.realPath, this.#owner.name));
|
|
@@ -337,7 +337,14 @@ class NativeStagedFile {
|
|
|
337
337
|
async assertCurrent() {
|
|
338
338
|
this.#assertCurrent();
|
|
339
339
|
}
|
|
340
|
-
|
|
340
|
+
publish(basename, options, onPublished) {
|
|
341
|
+
if (this.#publicationTask)
|
|
342
|
+
return Promise.reject(stagedFailure("file", new FsSafeError("helper-failed", "staged file publication is pending"), { phase: "publish", publication: this.#state.status === "closed" ? this.#state.receipt.publication : this.#state.publication }));
|
|
343
|
+
// Claim the operation before yielding so cleanup cannot recycle a worker's fds.
|
|
344
|
+
return this.#publicationTask = Promise.resolve().then(() => this.#publish(basename, options, onPublished))
|
|
345
|
+
.finally(() => { this.#publicationTask = undefined; });
|
|
346
|
+
}
|
|
347
|
+
async #publish(basename, options, onPublished) {
|
|
341
348
|
const overwrite = options?.overwrite;
|
|
342
349
|
try {
|
|
343
350
|
const state = this.#open();
|
|
@@ -354,10 +361,10 @@ class NativeStagedFile {
|
|
|
354
361
|
}
|
|
355
362
|
try {
|
|
356
363
|
if (overwrite) {
|
|
357
|
-
this.#owner.binding.
|
|
364
|
+
await this.#owner.binding.renameReplaceAsync(this.#owner.parentFd, this.#owner.name, this.#owner.parentFd, basename);
|
|
358
365
|
}
|
|
359
366
|
else {
|
|
360
|
-
this.#owner.binding.
|
|
367
|
+
await this.#owner.binding.renameNoReplaceAsync(this.#owner.parentFd, this.#owner.name, this.#owner.parentFd, basename);
|
|
361
368
|
}
|
|
362
369
|
}
|
|
363
370
|
catch (error) {
|
|
@@ -412,14 +419,13 @@ class NativeStagedFile {
|
|
|
412
419
|
};
|
|
413
420
|
if (this.#owner.sync === false)
|
|
414
421
|
return verify();
|
|
415
|
-
|
|
422
|
+
return Promise.resolve().then(async () => {
|
|
416
423
|
if ((this.#owner.mode & 0o600) !== 0o600 || (stagedMode & ~this.#owner.mode) !== 0) {
|
|
417
424
|
await (this.#owner.strictFileSync ? syncFile(fd) : syncFileBestEffort(fd));
|
|
418
425
|
}
|
|
419
426
|
await syncFileBestEffort(this.#owner.parentFd);
|
|
420
427
|
return verify();
|
|
421
|
-
})
|
|
422
|
-
return this.#publicationFlush;
|
|
428
|
+
});
|
|
423
429
|
}
|
|
424
430
|
#finalize() {
|
|
425
431
|
if (this.#state.status === "closed") {
|
|
@@ -474,9 +480,9 @@ class NativeStagedFile {
|
|
|
474
480
|
return this.#state;
|
|
475
481
|
}
|
|
476
482
|
async cleanup() {
|
|
477
|
-
// Native descriptors
|
|
478
|
-
if (this.#
|
|
479
|
-
await this.#
|
|
483
|
+
// Native descriptors stay owned through the rename and all durability fences.
|
|
484
|
+
if (this.#publicationTask)
|
|
485
|
+
await this.#publicationTask.catch(() => { });
|
|
480
486
|
const closed = this.#finalize();
|
|
481
487
|
if (closed.error) {
|
|
482
488
|
throw closed.error;
|
|
@@ -5,3 +5,5 @@ export type OverwriteFileHandleOptions = {
|
|
|
5
5
|
};
|
|
6
6
|
/** Overwrite a borrowed, non-append read/write handle with best-effort failure rollback. */
|
|
7
7
|
export declare function overwriteFileHandle(handle: FileHandle, data: Uint8Array, options?: OverwriteFileHandleOptions): Promise<void>;
|
|
8
|
+
/** Await authority preparation, then synchronously admit the whole borrowed-handle write. */
|
|
9
|
+
export declare function overwriteFileHandleWithAuthority(handle: FileHandle, data: Uint8Array, prepareAuthority: () => Promise<() => void>): Promise<void>;
|
|
@@ -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>;
|