@openclaw/feishu 2026.10.1-beta.2 → 2026.10.5-beta.1
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/{app-registration-BB6TubaW.mjs → app-registration-DQOq5urV.mjs} +13 -32
- package/dist/.setup/{channel-CX62T71S.mjs → channel-CjGGyrdx.mjs} +87 -174
- package/dist/.setup/{channel.runtime-COiaq-Rv.mjs → channel.runtime-SaC_uTPM.mjs} +57 -74
- package/dist/.setup/{chat-BdyvImsY.mjs → chat-fC3dvxFs.mjs} +16 -28
- package/dist/.setup/{client-BsBVWJzN.mjs → client-wwr8PGPH.mjs} +24 -30
- package/dist/.setup/{conversation-id-C1ofUfU8.mjs → conversation-id-D00i9uy5.mjs} +5 -10
- package/dist/.setup/{doctor-contract-B1B9ogdd.mjs → doctor-contract-oIpUWtNO.mjs} +23 -20
- package/dist/.setup/{monitor-7DvwUs4Y.mjs → monitor-Yt__BUki.mjs} +33 -54
- package/dist/.setup/{monitor.account-7xVu7XWY.mjs → monitor.account-CVz16781.mjs} +377 -664
- package/dist/.setup/{probe-B9o7iey6.mjs → probe-DXnFxq5j.mjs} +14 -17
- package/dist/.setup/{reply-delivery-result-Bt-BWBEA.mjs → reply-delivery-result-iCCrdxE1.mjs} +153 -181
- package/dist/.setup/{session-conversation-C53IEUWt.mjs → session-conversation-BSBNK5Mq.mjs} +1 -1
- package/dist/.setup/{setup-api-DmzX9S01.mjs → setup-api-B_LFQQ-Q.mjs} +1 -1
- package/dist/.setup/{subagent-hooks-CUXg0pC-.mjs → subagent-hooks-9Pc1-k37.mjs} +7 -17
- package/dist/.setup/{thread-bindings-jW2x5VuN.mjs → thread-bindings-DdNLxoL3.mjs} +21 -44
- package/dist/api.js +218 -326
- package/dist/channel-plugin-api.js +1 -1
- package/dist/contract-api.js +1 -1
- package/dist/doctor-contract-api.js +2 -2
- package/dist/session-binding-contract-api.js +1 -1
- package/dist/session-key-api.js +1 -1
- package/dist/setup-api.js +1 -1
- package/dist/setup-entry.js +1 -1
- package/dist/subagent-hooks-api.js +1 -1
- package/node_modules/@openclaw/fs-safe/CHANGELOG.md +91 -0
- package/node_modules/@openclaw/fs-safe/README.md +1 -1
- package/node_modules/@openclaw/fs-safe/dist/advanced.d.ts +1 -0
- package/node_modules/@openclaw/fs-safe/dist/advanced.js +1 -0
- package/node_modules/@openclaw/fs-safe/dist/archive-durability.js +1 -1
- package/node_modules/@openclaw/fs-safe/dist/archive-entry.js +7 -3
- package/node_modules/@openclaw/fs-safe/dist/archive-merge.js +4 -4
- package/node_modules/@openclaw/fs-safe/dist/archive-parser.wasm +0 -0
- package/node_modules/@openclaw/fs-safe/dist/archive-read.js +5 -4
- package/node_modules/@openclaw/fs-safe/dist/archive-staging.d.ts +1 -1
- package/node_modules/@openclaw/fs-safe/dist/archive-staging.js +22 -38
- package/node_modules/@openclaw/fs-safe/dist/copy-path-admission.d.ts +17 -0
- package/node_modules/@openclaw/fs-safe/dist/copy-path-admission.js +117 -0
- package/node_modules/@openclaw/fs-safe/dist/copy-root-file-sync.d.ts +38 -0
- package/node_modules/@openclaw/fs-safe/dist/copy-root-file-sync.js +195 -0
- package/node_modules/@openclaw/fs-safe/dist/create.d.ts +1 -0
- package/node_modules/@openclaw/fs-safe/dist/create.js +4 -1
- package/node_modules/@openclaw/fs-safe/dist/entry-publication.js +3 -1
- package/node_modules/@openclaw/fs-safe/dist/errors.d.ts +2 -0
- package/node_modules/@openclaw/fs-safe/dist/errors.js +5 -0
- package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-root-acquire.d.ts +3 -0
- package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-root-acquire.js +57 -11
- package/node_modules/@openclaw/fs-safe/dist/guarded-mutation.js +5 -5
- package/node_modules/@openclaw/fs-safe/dist/guest-native-python.js +52 -5
- package/node_modules/@openclaw/fs-safe/dist/guest.js +1 -1
- package/node_modules/@openclaw/fs-safe/dist/index.d.ts +1 -1
- package/node_modules/@openclaw/fs-safe/dist/index.js +1 -1
- package/node_modules/@openclaw/fs-safe/dist/native-binding.d.ts +4 -0
- package/node_modules/@openclaw/fs-safe/dist/native-move-fallback.d.ts +3 -0
- package/node_modules/@openclaw/fs-safe/dist/native-move-fallback.js +54 -0
- package/node_modules/@openclaw/fs-safe/dist/native-noreplace.d.ts +8 -0
- package/node_modules/@openclaw/fs-safe/dist/native-noreplace.js +55 -0
- package/node_modules/@openclaw/fs-safe/dist/native-operations.d.ts +0 -1
- package/node_modules/@openclaw/fs-safe/dist/native-operations.js +22 -26
- package/node_modules/@openclaw/fs-safe/dist/native-pinned-write-windows.js +5 -1
- package/node_modules/@openclaw/fs-safe/dist/native-pinned-write.d.ts +1 -1
- package/node_modules/@openclaw/fs-safe/dist/native-pinned-write.js +12 -2
- package/node_modules/@openclaw/fs-safe/dist/native-rename-outcome.js +3 -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 +52 -6
- package/node_modules/@openclaw/fs-safe/dist/permission-exec.js +2 -1
- package/node_modules/@openclaw/fs-safe/dist/pinned-write-input.d.ts +2 -0
- package/node_modules/@openclaw/fs-safe/dist/pinned-write-input.js +17 -0
- package/node_modules/@openclaw/fs-safe/dist/pinned-write-types.d.ts +6 -1
- package/node_modules/@openclaw/fs-safe/dist/pinned-write.js +1 -1
- package/node_modules/@openclaw/fs-safe/dist/private-temp-workspace.js +2 -2
- package/node_modules/@openclaw/fs-safe/dist/publish-file-failure.d.ts +5 -0
- package/node_modules/@openclaw/fs-safe/dist/publish-file-failure.js +1 -0
- package/node_modules/@openclaw/fs-safe/dist/publish-file.d.ts +2 -0
- package/node_modules/@openclaw/fs-safe/dist/publish-file.js +35 -2
- package/node_modules/@openclaw/fs-safe/dist/replace-directory.js +6 -5
- package/node_modules/@openclaw/fs-safe/dist/replace-file-copy-fallback.js +1 -4
- package/node_modules/@openclaw/fs-safe/dist/replace-file-descriptor.js +6 -0
- package/node_modules/@openclaw/fs-safe/dist/root-create-input.d.ts +15 -1
- package/node_modules/@openclaw/fs-safe/dist/root-create-input.js +4 -0
- package/node_modules/@openclaw/fs-safe/dist/root-directory-entry.js +1 -1
- package/node_modules/@openclaw/fs-safe/dist/root-directory-list.d.ts +0 -1
- package/node_modules/@openclaw/fs-safe/dist/root-directory-list.js +6 -12
- package/node_modules/@openclaw/fs-safe/dist/root-errors.js +25 -4
- package/node_modules/@openclaw/fs-safe/dist/root-impl.js +18 -18
- package/node_modules/@openclaw/fs-safe/dist/root-move-noreplace.d.ts +4 -2
- package/node_modules/@openclaw/fs-safe/dist/root-move-noreplace.js +13 -17
- package/node_modules/@openclaw/fs-safe/dist/root-paths.js +1 -1
- package/node_modules/@openclaw/fs-safe/dist/root-walk.js +4 -4
- package/node_modules/@openclaw/fs-safe/dist/root-write-verification.d.ts +10 -1
- package/node_modules/@openclaw/fs-safe/dist/root-write-verification.js +20 -0
- package/node_modules/@openclaw/fs-safe/dist/secure-temp-dir.js +19 -7
- package/node_modules/@openclaw/fs-safe/dist/sibling-staged-file.js +18 -3
- package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-acquire.js +25 -3
- package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-admission.d.ts +2 -0
- package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-retained.d.ts +14 -0
- package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-retained.js +187 -0
- package/node_modules/@openclaw/fs-safe/dist/sidecar-lock.js +15 -1
- package/node_modules/@openclaw/fs-safe/dist/staged-file-settlement.js +4 -1
- package/node_modules/@openclaw/fs-safe/dist/temp-directory-diagnostics.d.ts +10 -0
- package/node_modules/@openclaw/fs-safe/dist/temp-directory-diagnostics.js +29 -0
- package/node_modules/@openclaw/fs-safe/dist/temp-target.js +1 -1
- package/node_modules/@openclaw/fs-safe/dist/temp-workspace-admission.js +6 -6
- package/node_modules/@openclaw/fs-safe/dist/temp-workspace-child-admission.d.ts +4 -4
- package/node_modules/@openclaw/fs-safe/dist/temp-workspace-child-admission.js +17 -16
- package/node_modules/@openclaw/fs-safe/dist/temp-workspace-descriptor.js +20 -28
- package/node_modules/@openclaw/fs-safe/dist/temp-workspace-owner.d.ts +1 -0
- package/node_modules/@openclaw/fs-safe/dist/temp-workspace-owner.js +27 -4
- package/node_modules/@openclaw/fs-safe/dist/walk.js +2 -13
- package/node_modules/@openclaw/fs-safe/dist/watch-native.d.ts +2 -2
- package/node_modules/@openclaw/fs-safe/dist/watch-native.js +3 -1
- package/node_modules/@openclaw/fs-safe/dist/watch-rescan.js +3 -9
- package/node_modules/@openclaw/fs-safe/dist/watch.js +2 -3
- package/node_modules/@openclaw/fs-safe/docs/advanced.md +1 -0
- package/node_modules/@openclaw/fs-safe/docs/archive.md +5 -1
- package/node_modules/@openclaw/fs-safe/docs/atomic.md +11 -3
- package/node_modules/@openclaw/fs-safe/docs/contributing.md +1 -1
- package/node_modules/@openclaw/fs-safe/docs/copy.md +109 -1
- package/node_modules/@openclaw/fs-safe/docs/durability.md +50 -5
- package/node_modules/@openclaw/fs-safe/docs/errors.md +37 -0
- package/node_modules/@openclaw/fs-safe/docs/guest.md +21 -4
- package/node_modules/@openclaw/fs-safe/docs/native-helper.md +5 -3
- package/node_modules/@openclaw/fs-safe/docs/native.md +39 -6
- package/node_modules/@openclaw/fs-safe/docs/path-scope.md +4 -0
- package/node_modules/@openclaw/fs-safe/docs/public-api.md +3 -1
- package/node_modules/@openclaw/fs-safe/docs/sidecar-lock.md +46 -8
- package/node_modules/@openclaw/fs-safe/docs/staged-file.md +10 -3
- package/node_modules/@openclaw/fs-safe/docs/temp.md +12 -0
- package/node_modules/@openclaw/fs-safe/docs/watch.md +6 -3
- package/node_modules/@openclaw/fs-safe/docs/writing.md +40 -11
- package/node_modules/@openclaw/fs-safe/package.json +16 -16
- 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-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-x64-msvc/fs-safe-native.node +0 -0
- package/node_modules/@openclaw/fs-safe-win32-x64-msvc/package.json +1 -1
- package/node_modules/follow-redirects/index.js +10 -1
- package/node_modules/follow-redirects/package.json +1 -1
- package/package.json +5 -5
- package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-root-arbitration.d.ts +0 -17
- package/node_modules/@openclaw/fs-safe/dist/file-lock-sync-root-arbitration.js +0 -66
- package/node_modules/@openclaw/fs-safe/dist/root-move-preflight.d.ts +0 -7
- package/node_modules/@openclaw/fs-safe/dist/root-move-preflight.js +0 -16
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import { FsSafeError } from "./errors.js";
|
|
3
|
+
export const NATIVE_NOREPLACE_UNSUPPORTED = "FS_SAFE_INTERNAL_RENAME_NOREPLACE_UNSUPPORTED";
|
|
4
|
+
const unsupported = new WeakMap();
|
|
5
|
+
const capabilityErrors = new WeakMap();
|
|
6
|
+
const MAX_DEVICES = 128;
|
|
7
|
+
function unavailable(operation, detail, cause) {
|
|
8
|
+
const error = new FsSafeError("helper-unavailable", `native no-replace ${operation} is unsupported on this filesystem (${detail})`, { cause, details: { capability: "rename-noreplace" } });
|
|
9
|
+
capabilityErrors.set(error, detail);
|
|
10
|
+
return error;
|
|
11
|
+
}
|
|
12
|
+
export function isNoReplaceUnavailable(error) {
|
|
13
|
+
return error instanceof FsSafeError && capabilityErrors.has(error);
|
|
14
|
+
}
|
|
15
|
+
export function noReplaceUnavailable(error, operation, syscallOnly = false) {
|
|
16
|
+
try {
|
|
17
|
+
const code = error?.code;
|
|
18
|
+
if (code !== NATIVE_NOREPLACE_UNSUPPORTED &&
|
|
19
|
+
!(syscallOnly && ["EINVAL", "ENOSYS", "ENOTSUP", "EOPNOTSUPP"].includes(code ?? "")))
|
|
20
|
+
return;
|
|
21
|
+
const capability = process.platform === "darwin" ? "renameatx_np RENAME_EXCL"
|
|
22
|
+
: process.platform === "win32" ? "native no-replace rename" : "renameat2 RENAME_NOREPLACE";
|
|
23
|
+
const detail = code === NATIVE_NOREPLACE_UNSUPPORTED
|
|
24
|
+
? error.message : `${capability}: ${code}`;
|
|
25
|
+
return unavailable(operation, detail, error);
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
// Diagnostic getters do not establish non-publication.
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export function rememberNoReplaceUnavailable(binding, parentFd, error) {
|
|
33
|
+
const detail = capabilityErrors.get(error);
|
|
34
|
+
if (!detail)
|
|
35
|
+
return;
|
|
36
|
+
const device = fs.fstatSync(parentFd, { bigint: true }).dev;
|
|
37
|
+
let devices = unsupported.get(binding);
|
|
38
|
+
if (!devices)
|
|
39
|
+
unsupported.set(binding, devices = new Map());
|
|
40
|
+
if (!devices.has(device) && devices.size >= MAX_DEVICES)
|
|
41
|
+
devices.delete(devices.keys().next().value);
|
|
42
|
+
devices.set(device, detail);
|
|
43
|
+
}
|
|
44
|
+
export function cachedNoReplaceUnavailable(binding, parentFd, operation = "publication") {
|
|
45
|
+
if (!unsupported.has(binding))
|
|
46
|
+
return;
|
|
47
|
+
return cachedNoReplaceDevice(binding, fs.fstatSync(parentFd, { bigint: true }).dev, operation);
|
|
48
|
+
}
|
|
49
|
+
export function cachedNoReplaceDevice(binding, device, operation) {
|
|
50
|
+
const devices = unsupported.get(binding);
|
|
51
|
+
if (!devices)
|
|
52
|
+
return;
|
|
53
|
+
const detail = devices.get(device);
|
|
54
|
+
return detail ? unavailable(operation, detail) : undefined;
|
|
55
|
+
}
|
|
@@ -5,7 +5,6 @@ export type NativeFileHandle = {
|
|
|
5
5
|
writeFile(data: string | Buffer, encoding?: BufferEncoding): Promise<void>;
|
|
6
6
|
};
|
|
7
7
|
export declare function nativeOpenFlags(flags: number): number;
|
|
8
|
-
export declare function writeNativeFd(fd: number, data: Buffer): void;
|
|
9
8
|
export declare function removeNativeCreatedFileIfStillPinned(params: {
|
|
10
9
|
parentPath: string;
|
|
11
10
|
parentFd: number;
|
|
@@ -10,31 +10,6 @@ export function nativeOpenFlags(flags) {
|
|
|
10
10
|
(closeOnExec ?? 0) |
|
|
11
11
|
(typeof fsSync.constants.O_NOFOLLOW === "number" ? fsSync.constants.O_NOFOLLOW : 0));
|
|
12
12
|
}
|
|
13
|
-
export function writeNativeFd(fd, data) {
|
|
14
|
-
let offset = 0;
|
|
15
|
-
while (offset < data.byteLength) {
|
|
16
|
-
const written = fsSync.writeSync(fd, data, offset, data.byteLength - offset);
|
|
17
|
-
if (written <= 0) {
|
|
18
|
-
throw Object.assign(new Error("native file write made no progress"), { code: "EIO" });
|
|
19
|
-
}
|
|
20
|
-
offset += written;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
function wrapNativeFd(fd, closeFd) {
|
|
24
|
-
let open = true;
|
|
25
|
-
return {
|
|
26
|
-
fd,
|
|
27
|
-
async close() {
|
|
28
|
-
if (open) {
|
|
29
|
-
open = false;
|
|
30
|
-
closeFd(fd);
|
|
31
|
-
}
|
|
32
|
-
},
|
|
33
|
-
async writeFile(data, encoding) {
|
|
34
|
-
writeNativeFd(fd, Buffer.isBuffer(data) ? data : Buffer.from(data, encoding ?? "utf8"));
|
|
35
|
-
},
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
13
|
export function removeNativeCreatedFileIfStillPinned(params) {
|
|
39
14
|
if (!params.created) {
|
|
40
15
|
return;
|
|
@@ -86,7 +61,28 @@ export async function createNativeExclusiveFile(targetPath, mode) {
|
|
|
86
61
|
fd = opened.fd;
|
|
87
62
|
fsSync.fchmodSync(fd, mode);
|
|
88
63
|
created = fsSync.fstatSync(fd, { bigint: true });
|
|
89
|
-
|
|
64
|
+
const ownedFd = fd;
|
|
65
|
+
let open = true;
|
|
66
|
+
return {
|
|
67
|
+
fd: ownedFd,
|
|
68
|
+
async close() {
|
|
69
|
+
if (open) {
|
|
70
|
+
open = false;
|
|
71
|
+
closeFd(ownedFd);
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
async writeFile(data, encoding) {
|
|
75
|
+
const buffer = Buffer.isBuffer(data) ? data : Buffer.from(data, encoding ?? "utf8");
|
|
76
|
+
let offset = 0;
|
|
77
|
+
while (offset < buffer.byteLength) {
|
|
78
|
+
const written = fsSync.writeSync(ownedFd, buffer, offset, buffer.byteLength - offset);
|
|
79
|
+
if (written <= 0) {
|
|
80
|
+
throw Object.assign(new Error("native file write made no progress"), { code: "EIO" });
|
|
81
|
+
}
|
|
82
|
+
offset += written;
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
};
|
|
90
86
|
}
|
|
91
87
|
catch (error) {
|
|
92
88
|
if (fd !== undefined) {
|
|
@@ -188,7 +188,11 @@ export async function runPinnedWriteWindows(binding, params, root, parentFd, par
|
|
|
188
188
|
if (params.sync !== false)
|
|
189
189
|
syncFileBestEffortSync(parentFd);
|
|
190
190
|
// Verification follows publication and final chmod, outside rollback handling.
|
|
191
|
-
|
|
191
|
+
if (params.overwrite === false && params.input.kind === "buffer" && params.input.stageBeforePublish === false) {
|
|
192
|
+
await params.verifyPublished?.(targetFd, verificationIdentity, parentGuard, { fd: parentFd, binding });
|
|
193
|
+
}
|
|
194
|
+
else
|
|
195
|
+
await params.verifyPublished?.(targetFd, verificationIdentity, parentGuard);
|
|
192
196
|
completed = true;
|
|
193
197
|
return { dev: targetIdentity.dev, ino: targetIdentity.ino };
|
|
194
198
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { FileIdentityStat } from "./file-identity.js";
|
|
2
2
|
import type { NativeBinding } from "./native.js";
|
|
3
3
|
import type { PinnedWriteParams } from "./pinned-write-types.js";
|
|
4
|
-
export declare function runPinnedWriteNative(binding: NativeBinding, params: PinnedWriteParams): Promise<FileIdentityStat>;
|
|
4
|
+
export declare function runPinnedWriteNative(binding: NativeBinding, params: PinnedWriteParams, fallback: (input: PinnedWriteParams["input"]) => Promise<FileIdentityStat>): Promise<FileIdentityStat>;
|
|
@@ -57,7 +57,9 @@ import { capturePolicyAwareNativeParent } from "./native-policy-parent.js";
|
|
|
57
57
|
import { openNativeParentAdmission, openNativeRootAdmission } from "./native-parent-admission.js";
|
|
58
58
|
import { assertNativeStaging, writeNativeStage } from "./native-staged-file.js";
|
|
59
59
|
import { captureNativeFdClose } from "./native-binding.js";
|
|
60
|
-
|
|
60
|
+
import { cachedNoReplaceUnavailable } from "./native-noreplace.js";
|
|
61
|
+
import { isFsSafeNativeRequired } from "./native-config.js";
|
|
62
|
+
export async function runPinnedWriteNative(binding, params, fallback) {
|
|
61
63
|
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
62
64
|
try {
|
|
63
65
|
const closeFd = captureNativeFdClose(binding);
|
|
@@ -126,9 +128,17 @@ export async function runPinnedWriteNative(binding, params) {
|
|
|
126
128
|
windowsOwnsDirectories = true;
|
|
127
129
|
return await runPinnedWriteWindows(binding, params, root, parentFd, verificationGuard);
|
|
128
130
|
}
|
|
131
|
+
if (params.overwrite === false && !(params.input.kind === "buffer" && params.input.stageBeforePublish === false)) {
|
|
132
|
+
const unavailable = cachedNoReplaceUnavailable(binding, parentFd);
|
|
133
|
+
if (unavailable) {
|
|
134
|
+
if (isFsSafeNativeRequired() || (params.input.kind === "file" && params.input.clone === "always"))
|
|
135
|
+
throw unavailable;
|
|
136
|
+
return await fallback(params.input);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
129
139
|
const ownedParent = parentFd;
|
|
130
140
|
parentFd = undefined;
|
|
131
|
-
return await writeNativeStage(binding, ownedParent, closeFd, directory, params, verificationGuard);
|
|
141
|
+
return await writeNativeStage(binding, ownedParent, closeFd, directory, params, verificationGuard, fallback);
|
|
132
142
|
}
|
|
133
143
|
catch (error) {
|
|
134
144
|
admissionFailure = { error };
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { NATIVE_NOREPLACE_UNSUPPORTED } from "./native-noreplace.js";
|
|
1
2
|
export const NATIVE_RENAME_SOURCE_IDENTITY_MISMATCH = "FS_SAFE_INTERNAL_RENAME_SOURCE_IDENTITY_MISMATCH";
|
|
2
3
|
export function classifyNativeRenameFailure(error) {
|
|
3
4
|
try {
|
|
4
|
-
|
|
5
|
+
const code = error?.code;
|
|
6
|
+
if (code === NATIVE_RENAME_SOURCE_IDENTITY_MISMATCH || code === NATIVE_NOREPLACE_UNSUPPORTED) {
|
|
5
7
|
return "uncommitted";
|
|
6
8
|
}
|
|
7
9
|
}
|
|
@@ -25,7 +25,7 @@ declare class NativeStagedFile implements StagedFile {
|
|
|
25
25
|
#private;
|
|
26
26
|
constructor(owner: NativeStageOwner);
|
|
27
27
|
static create(owner: NativeStageOwner, input: PinnedWriteInput, maxBytes?: number): Promise<NativeStagedFile>;
|
|
28
|
-
static write(binding: NativeStagingBinding, parentFd: number, closeParentFd: (fd: number) => void, directory: StagedFileReceipt["directory"], params: PinnedWriteParams, parentGuard: AnyAsyncDirectoryGuard): Promise<FileIdentityStat>;
|
|
28
|
+
static write(binding: NativeStagingBinding, parentFd: number, closeParentFd: (fd: number) => void, directory: StagedFileReceipt["directory"], params: PinnedWriteParams, parentGuard: AnyAsyncDirectoryGuard, fallback: (input: PinnedWriteInput) => Promise<FileIdentityStat>): Promise<FileIdentityStat>;
|
|
29
29
|
get receipt(): StagedFileReceipt;
|
|
30
30
|
assertCurrent(): Promise<void>;
|
|
31
31
|
publish(basename: string, options: {
|
|
@@ -59,12 +59,14 @@ import path from "node:path";
|
|
|
59
59
|
import { FsSafeError } from "./errors.js";
|
|
60
60
|
import { assertSynchronousCallbackResult, isMutationAuthorityError } from "./mutation-authority.js";
|
|
61
61
|
import { captureNativeFdClose } from "./native-binding.js";
|
|
62
|
-
import { writePinnedInput } from "./pinned-write-input.js";
|
|
62
|
+
import { replayPinnedInput, writePinnedInput } from "./pinned-write-input.js";
|
|
63
63
|
import { assertNativeCopyCompleted, createNativeCopyFile } from "./copy-file-input.js";
|
|
64
64
|
import { assertStagedDirectoryCurrent, openStagedDirectory } from "./staged-directory.js";
|
|
65
65
|
import { assertFinalSymlinkRejected } from "./root-symlink-policy.js";
|
|
66
66
|
import { classifyNativeRenameFailure } from "./native-rename-outcome.js";
|
|
67
67
|
import { createStagedFileReceipt, stagedFailure } from "./staged-file-settlement.js";
|
|
68
|
+
import { noReplaceUnavailable, rememberNoReplaceUnavailable } from "./native-noreplace.js";
|
|
69
|
+
import { isFsSafeNativeRequired } from "./native-config.js";
|
|
68
70
|
export function assertNativeStaging(binding) {
|
|
69
71
|
if ([
|
|
70
72
|
binding.closeOwnedFd,
|
|
@@ -93,6 +95,9 @@ class NativeStagedFile {
|
|
|
93
95
|
#state = { status: "open", publication: NOT_PUBLISHED };
|
|
94
96
|
#receipt;
|
|
95
97
|
#rejectFinalSymlink = false;
|
|
98
|
+
#unsupportedNoReplace;
|
|
99
|
+
#fallbackCleanup;
|
|
100
|
+
#fallbackCleanupError;
|
|
96
101
|
constructor(owner) {
|
|
97
102
|
const name = owner.name ?? `.fs-safe-${randomUUID()}.tmp`;
|
|
98
103
|
assertBasename(name, owner.portableNames !== false);
|
|
@@ -121,7 +126,7 @@ class NativeStagedFile {
|
|
|
121
126
|
await staged.#prepare(input, maxBytes);
|
|
122
127
|
return staged;
|
|
123
128
|
}
|
|
124
|
-
static async write(binding, parentFd, closeParentFd, directory, params, parentGuard) {
|
|
129
|
+
static async write(binding, parentFd, closeParentFd, directory, params, parentGuard, fallback) {
|
|
125
130
|
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
126
131
|
try {
|
|
127
132
|
const exclusive = params.overwrite === false && params.input.kind === "buffer" && params.input.stageBeforePublish === false;
|
|
@@ -143,12 +148,39 @@ class NativeStagedFile {
|
|
|
143
148
|
if (staged.#verifyMode)
|
|
144
149
|
staged.#assertCurrent();
|
|
145
150
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
151
|
+
let published;
|
|
152
|
+
try {
|
|
153
|
+
published = exclusive
|
|
154
|
+
? staged.#completePublication(params.basename, false, params.onPublished)
|
|
155
|
+
: await staged.publish(params.basename, { overwrite: params.overwrite !== false }, params.onPublished);
|
|
156
|
+
}
|
|
157
|
+
catch (error) {
|
|
158
|
+
if (!staged.#unsupportedNoReplace || isFsSafeNativeRequired() ||
|
|
159
|
+
(params.input.kind === "file" && params.input.clone === "always"))
|
|
160
|
+
throw error;
|
|
161
|
+
// Remove only our identity-known stage before re-admitting the JS write.
|
|
162
|
+
// Keep its descriptor alive to replay a one-shot stream in bounded chunks.
|
|
163
|
+
staged.#fallbackCleanup = "failed";
|
|
164
|
+
let removed;
|
|
165
|
+
try {
|
|
166
|
+
removed = binding.removeStagedFile(parentFd, staged.#owner.name, staged.#file());
|
|
167
|
+
staged.#fallbackCleanup = removed;
|
|
168
|
+
}
|
|
169
|
+
catch (cleanupError) {
|
|
170
|
+
staged.#fallbackCleanupError = { error: cleanupError };
|
|
171
|
+
throw error;
|
|
172
|
+
}
|
|
173
|
+
if (removed !== "removed" && removed !== "name-absent")
|
|
174
|
+
throw error;
|
|
175
|
+
rememberNoReplaceUnavailable(binding, parentFd, staged.#unsupportedNoReplace);
|
|
176
|
+
return await fallback(replayPinnedInput(staged.#file(), params.input));
|
|
177
|
+
}
|
|
149
178
|
const identity = published.staged.identity;
|
|
150
179
|
try {
|
|
151
|
-
|
|
180
|
+
if (exclusive)
|
|
181
|
+
await params.verifyPublished?.(staged.#file(), identity, parentGuard, { fd: parentFd, binding });
|
|
182
|
+
else
|
|
183
|
+
await params.verifyPublished?.(staged.#file(), identity, parentGuard);
|
|
152
184
|
}
|
|
153
185
|
catch (error) {
|
|
154
186
|
if (params.overwrite === false && params.input.kind !== "file" && params.input.stageBeforePublish === true) {
|
|
@@ -321,6 +353,15 @@ class NativeStagedFile {
|
|
|
321
353
|
catch (error) {
|
|
322
354
|
// Record before inspecting metadata, whose getters can reenter cleanup.
|
|
323
355
|
state.publication = Object.freeze({ status: "indeterminate", basename, overwrite });
|
|
356
|
+
// Linux VFS and rename(2): unsupported flags return EINVAL; ENOSYS
|
|
357
|
+
// means no syscall. A regular file renamed to a distinct sibling cannot
|
|
358
|
+
// hit the directory-into-itself EINVAL case. Nothing was published.
|
|
359
|
+
const unavailable = !overwrite ? noReplaceUnavailable(error, "publication", true) : undefined;
|
|
360
|
+
if (unavailable && this.#state === state && state.status === "open") {
|
|
361
|
+
state.publication = NOT_PUBLISHED;
|
|
362
|
+
this.#unsupportedNoReplace = unavailable;
|
|
363
|
+
throw unavailable;
|
|
364
|
+
}
|
|
324
365
|
// Only explicit pre-dispatch provenance can rule out a committed rename.
|
|
325
366
|
if (classifyNativeRenameFailure(error) === "uncommitted") {
|
|
326
367
|
state.publication = NOT_PUBLISHED;
|
|
@@ -377,6 +418,11 @@ class NativeStagedFile {
|
|
|
377
418
|
if (state.publication.status === "indeterminate") {
|
|
378
419
|
outcome = "preserved";
|
|
379
420
|
}
|
|
421
|
+
else if (this.#fallbackCleanup) {
|
|
422
|
+
outcome = this.#fallbackCleanup;
|
|
423
|
+
if (this.#fallbackCleanupError)
|
|
424
|
+
errors.push(this.#fallbackCleanupError.error);
|
|
425
|
+
}
|
|
380
426
|
else if (state.publication.status === "not-published" && state.fileFd !== undefined) {
|
|
381
427
|
try {
|
|
382
428
|
outcome = this.#owner.binding.removeStagedFile(this.#owner.parentFd, this.#owner.name, state.fileFd);
|
|
@@ -5,7 +5,8 @@ import { formatErrorDetail } from "./error-detail.js";
|
|
|
5
5
|
const execFileAsync = promisify(execFile);
|
|
6
6
|
export const DEFAULT_PERMISSION_EXEC_TIMEOUT_MS = 30_000;
|
|
7
7
|
export function formatPermissionErrorDetail(value) {
|
|
8
|
-
|
|
8
|
+
// Escaping cannot shrink input; 401 code units decide the 400-character excerpt.
|
|
9
|
+
const formatted = formatErrorDetail(value.slice(0, 401));
|
|
9
10
|
return formatted.length > 400 ? `${formatted.slice(0, 399)}…` : formatted;
|
|
10
11
|
}
|
|
11
12
|
const MAX_CAUGHT_FAILURE_PROTOTYPES = 4;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import type { FileHandle } from "node:fs/promises";
|
|
2
2
|
import type { PinnedWriteInput } from "./pinned-write-types.js";
|
|
3
|
+
/** Replay a consumed stream from an owned, readable stage descriptor. */
|
|
4
|
+
export declare function replayPinnedInput(fd: number, input: PinnedWriteInput): PinnedWriteInput;
|
|
3
5
|
export declare function writePinnedInput(target: FileHandle | number, input: PinnedWriteInput, maxBytes?: number, assertBeforeMutation?: () => void): Promise<void>;
|
|
@@ -1,8 +1,25 @@
|
|
|
1
|
+
import { readSync } from "node:fs";
|
|
1
2
|
import { types } from "node:util";
|
|
2
3
|
import { snapshotByteView } from "./byte-view.js";
|
|
3
4
|
import { writeCopyFileToFd } from "./copy-file-input.js";
|
|
4
5
|
import { FsSafeError } from "./errors.js";
|
|
5
6
|
import { writeAllToFile } from "./write-file-handle.js";
|
|
7
|
+
/** Replay a consumed stream from an owned, readable stage descriptor. */
|
|
8
|
+
export function replayPinnedInput(fd, input) {
|
|
9
|
+
if (input.kind !== "stream")
|
|
10
|
+
return input;
|
|
11
|
+
return { kind: "stream", stageBeforePublish: true, stream: (async function* () {
|
|
12
|
+
let position = 0;
|
|
13
|
+
const buffer = Buffer.alloc(64 * 1024);
|
|
14
|
+
for (;;) {
|
|
15
|
+
const bytes = readSync(fd, buffer, 0, buffer.length, position);
|
|
16
|
+
if (!bytes)
|
|
17
|
+
return;
|
|
18
|
+
position += bytes;
|
|
19
|
+
yield buffer.subarray(0, bytes);
|
|
20
|
+
}
|
|
21
|
+
})() };
|
|
22
|
+
}
|
|
6
23
|
const isUint8Array = types.isUint8Array;
|
|
7
24
|
function streamChunkBytes(chunk) {
|
|
8
25
|
if (Buffer.isBuffer(chunk))
|
|
@@ -2,6 +2,11 @@ import type { CopyFileInput } from "./copy-file-input.js";
|
|
|
2
2
|
import type { AnyAsyncDirectoryGuard } from "./directory-guard.js";
|
|
3
3
|
import type { FileIdentityStat } from "./file-identity.js";
|
|
4
4
|
import type { MutationDirectoryObservation } from "./pinned-mutation-observation.js";
|
|
5
|
+
import type { NativeBinding } from "./native-binding.js";
|
|
6
|
+
export type NativeWriteParent = Readonly<{
|
|
7
|
+
fd: number;
|
|
8
|
+
binding: NativeBinding;
|
|
9
|
+
}>;
|
|
5
10
|
export type PinnedWriteInput = {
|
|
6
11
|
kind: "buffer";
|
|
7
12
|
data: string | Buffer;
|
|
@@ -64,5 +69,5 @@ export type PinnedWriteParams = {
|
|
|
64
69
|
mutationAdmission?: PinnedWriteMutationAdmission;
|
|
65
70
|
onRenameIdentityMismatch?: "verify-content";
|
|
66
71
|
onPublished?: (identity: PublishedWriteIdentity) => void;
|
|
67
|
-
verifyPublished?: (fd: number, identity: PublishedWriteIdentity, parentGuard: AnyAsyncDirectoryGuard) => Promise<void>;
|
|
72
|
+
verifyPublished?: (fd: number, identity: PublishedWriteIdentity, parentGuard: AnyAsyncDirectoryGuard, nativeParent?: NativeWriteParent) => Promise<void>;
|
|
68
73
|
};
|
|
@@ -90,7 +90,7 @@ export async function runPinnedWriteHelper(params) {
|
|
|
90
90
|
}
|
|
91
91
|
const native = getNativeBinding();
|
|
92
92
|
if (native) {
|
|
93
|
-
return await runPinnedWriteNative(native, normalizedParams);
|
|
93
|
+
return await runPinnedWriteNative(native, normalizedParams, input => runPinnedWriteFallback({ ...normalizedParams, input }));
|
|
94
94
|
}
|
|
95
95
|
return await runPinnedWriteFallback(normalizedParams);
|
|
96
96
|
}
|
|
@@ -166,7 +166,7 @@ async function createTempWorkspace(options, scopedPrefix = false) {
|
|
|
166
166
|
else
|
|
167
167
|
admission.assertCurrent();
|
|
168
168
|
const stat = inspectDirectoryIdentitySync(dir);
|
|
169
|
-
const needsModeInitialization = validateInitialTempWorkspaceChild(stat, admission.ownerUid, dirMode);
|
|
169
|
+
const needsModeInitialization = validateInitialTempWorkspaceChild(stat, admission.ownerUid, dirMode, dir);
|
|
170
170
|
// Retain while the child still has its private creation mode so an
|
|
171
171
|
// explicit dirMode such as 0 cannot make identity descriptor acquisition fail.
|
|
172
172
|
retainedChild = TempWorkspaceRetainedChild.retain(dir, stat);
|
|
@@ -261,7 +261,7 @@ function createTempWorkspaceSync(options, scopedPrefix = false) {
|
|
|
261
261
|
else {
|
|
262
262
|
stat = inspectDirectoryIdentitySync(dir);
|
|
263
263
|
}
|
|
264
|
-
const needsModeInitialization = validateInitialTempWorkspaceChild(stat, admission.ownerUid, dirMode);
|
|
264
|
+
const needsModeInitialization = validateInitialTempWorkspaceChild(stat, admission.ownerUid, dirMode, dir);
|
|
265
265
|
retainedChild ??= TempWorkspaceRetainedChild.retain(dir, stat);
|
|
266
266
|
if (needsModeInitialization) {
|
|
267
267
|
retainedChild.initializeModeSync(dirMode, admission.ownerUid, admission.assertCurrent);
|
|
@@ -13,6 +13,9 @@ export type PublishFileExclusiveFailureDetails = {
|
|
|
13
13
|
targetIdentity?: FileIdentityStat;
|
|
14
14
|
cleanup: PublishFileExclusiveCleanup;
|
|
15
15
|
directorySync?: PublishFileExclusiveDirectorySyncFailure;
|
|
16
|
+
fallback?: "link-unlink";
|
|
17
|
+
publication?: "published";
|
|
18
|
+
sourceRemoval?: "not-attempted" | "still-linked" | "unverified" | "removed";
|
|
16
19
|
};
|
|
17
20
|
export type PublishFailureState = {
|
|
18
21
|
phase: PublishFileExclusiveFailurePhase;
|
|
@@ -21,6 +24,8 @@ export type PublishFailureState = {
|
|
|
21
24
|
targetCleanupIdentity?: FileIdentityStat;
|
|
22
25
|
preserveTarget: boolean;
|
|
23
26
|
directorySync?: PublishFileExclusiveDirectorySyncFailure;
|
|
27
|
+
fallback?: PublishFileExclusiveFailureDetails["fallback"];
|
|
28
|
+
sourceRemoval?: PublishFileExclusiveFailureDetails["sourceRemoval"];
|
|
24
29
|
};
|
|
25
30
|
export declare function rememberCreatedTarget(state: PublishFailureState, identity: FileIdentityStat, phase: PublishFileExclusiveFailurePhase): void;
|
|
26
31
|
export declare function publicationFailure(error: unknown, state: PublishFailureState, cleanup: PublishFileExclusiveCleanup): FsSafeError;
|
|
@@ -12,6 +12,7 @@ export function publicationFailure(error, state, cleanup) {
|
|
|
12
12
|
targetCreated: state.targetCreated,
|
|
13
13
|
...(state.targetIdentity ? { targetIdentity: state.targetIdentity } : {}),
|
|
14
14
|
...(state.directorySync ? { directorySync: state.directorySync } : {}),
|
|
15
|
+
...(state.fallback ? { fallback: state.fallback, publication: "published", sourceRemoval: state.sourceRemoval } : {}),
|
|
15
16
|
cleanup,
|
|
16
17
|
};
|
|
17
18
|
return new FsSafeError(error instanceof FsSafeError ? error.code : "helper-failed", `exclusive file publication failed during ${state.phase}: ${cause.message}`, { cause, details });
|
|
@@ -5,6 +5,8 @@ import { type PublishFileExclusiveSyncFailurePolicy } from "./publish-file-failu
|
|
|
5
5
|
export type PublishFileExclusiveStrategy = "link-or-copy" | "link-required" | "rename-noreplace";
|
|
6
6
|
export type PublishFileExclusiveResult = {
|
|
7
7
|
method: "hardlink" | "exclusive-copy" | "rename-noreplace";
|
|
8
|
+
/** Linux auto fallback; exclusive and identity-checked, but not crash-atomic. */
|
|
9
|
+
fallback?: "link-unlink";
|
|
8
10
|
identity: Stats;
|
|
9
11
|
directorySync: DirectorySyncOutcome;
|
|
10
12
|
};
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { nativeMoveNoReplace } from "./native-move-fallback.js";
|
|
2
|
+
import { getFsSafeNativeConfig } from "./native-config.js";
|
|
1
3
|
import { createHash } from "node:crypto";
|
|
2
4
|
import fsSync, {} from "node:fs";
|
|
3
5
|
import fs, {} from "node:fs/promises";
|
|
@@ -256,7 +258,7 @@ export async function publishFileExclusive(params) {
|
|
|
256
258
|
else
|
|
257
259
|
assertSourceCurrent();
|
|
258
260
|
assertPublishedTargetCurrent(targetPath, identity, "publication target changed during directory sync");
|
|
259
|
-
return { method, identity: fsSync.fstatSync(handle.fd), directorySync };
|
|
261
|
+
return { method, ...(failure.fallback ? { fallback: failure.fallback } : {}), identity: fsSync.fstatSync(handle.fd), directorySync };
|
|
260
262
|
};
|
|
261
263
|
await parent.assertCurrent();
|
|
262
264
|
assertSourceCurrent();
|
|
@@ -269,7 +271,38 @@ export async function publishFileExclusive(params) {
|
|
|
269
271
|
}
|
|
270
272
|
if (strategy === "rename-noreplace") {
|
|
271
273
|
const binding = requireNativeBinding();
|
|
272
|
-
|
|
274
|
+
try {
|
|
275
|
+
const fallback = nativeMoveNoReplace(binding, [
|
|
276
|
+
sourceNativeParent.handle.fd, sourceNativeParent.basename,
|
|
277
|
+
targetNativeParent.handle.fd, targetNativeParent.basename,
|
|
278
|
+
], sourceExactIdentity, getFsSafeNativeConfig().mode === "auto", "file publication");
|
|
279
|
+
if (fallback) {
|
|
280
|
+
failure.fallback = fallback;
|
|
281
|
+
failure.sourceRemoval = "removed";
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
catch (error) {
|
|
285
|
+
if (error instanceof FsSafeError) {
|
|
286
|
+
if (error.details?.publication === "published") {
|
|
287
|
+
failure.targetCreated = true;
|
|
288
|
+
failure.preserveTarget = true;
|
|
289
|
+
failure.phase = "rename-verify";
|
|
290
|
+
failure.fallback = "link-unlink";
|
|
291
|
+
failure.sourceRemoval = error.details.sourceRemoval;
|
|
292
|
+
// Changed/unverified pairs cannot establish which inode was published.
|
|
293
|
+
if (failure.sourceRemoval === "still-linked")
|
|
294
|
+
rememberCreatedTarget(failure, sourceExactIdentity, "rename-verify");
|
|
295
|
+
}
|
|
296
|
+
throw error;
|
|
297
|
+
}
|
|
298
|
+
const code = error?.code;
|
|
299
|
+
if (code === "path-mismatch" || code === "hardlink") {
|
|
300
|
+
throw new FsSafeError(code, "publication source changed before fallback", { cause: error });
|
|
301
|
+
}
|
|
302
|
+
if (code === "ELOOP")
|
|
303
|
+
throw new FsSafeError("symlink", "publication source became a symlink", { cause: error });
|
|
304
|
+
throw error;
|
|
305
|
+
}
|
|
273
306
|
rememberCreatedTarget(failure, sourceExactIdentity, "rename-verify");
|
|
274
307
|
// A failed post-rename fence must not delete the only remaining name.
|
|
275
308
|
failure.preserveTarget = true;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { noReplaceUnavailable } from "./native-noreplace.js";
|
|
1
2
|
import { randomUUID } from "node:crypto";
|
|
2
3
|
import fsSync from "node:fs";
|
|
3
4
|
import fs from "node:fs/promises";
|
|
@@ -19,7 +20,8 @@ function assertGuardsCurrent(guards) {
|
|
|
19
20
|
}
|
|
20
21
|
function replacementFailure(error, message, details, cause = error) {
|
|
21
22
|
if (error instanceof FsSafeError) {
|
|
22
|
-
|
|
23
|
+
const code = error.code;
|
|
24
|
+
return new FsSafeError(code, code === "helper-unavailable" ? `${message}: ${error.message}` : message, { cause, details });
|
|
23
25
|
}
|
|
24
26
|
const failure = new Error(message, { cause });
|
|
25
27
|
copyOperationalCode(failure, error);
|
|
@@ -46,14 +48,13 @@ function observeOptionalDirectory(pathname) {
|
|
|
46
48
|
return inspectDirectoryIdentitySync(pathname, undefined, initial);
|
|
47
49
|
}
|
|
48
50
|
function normalizeNativeRenameFailure(error) {
|
|
51
|
+
const unavailable = noReplaceUnavailable(error, "directory rename", true);
|
|
52
|
+
if (unavailable)
|
|
53
|
+
return unavailable;
|
|
49
54
|
const code = error?.code;
|
|
50
55
|
if (code === NATIVE_RENAME_SOURCE_IDENTITY_MISMATCH) {
|
|
51
56
|
return new FsSafeError("path-mismatch", "directory replacement source identity changed before native rename", { cause: error });
|
|
52
57
|
}
|
|
53
|
-
if (code === "EINVAL" || code === "ENOSYS" || code === "ENOTSUP" ||
|
|
54
|
-
code === "EOPNOTSUPP") {
|
|
55
|
-
return new FsSafeError("helper-unavailable", "native no-replace directory rename is unavailable on this filesystem", { cause: error });
|
|
56
|
-
}
|
|
57
58
|
return error;
|
|
58
59
|
}
|
|
59
60
|
function renameRetainedDirectory(params) {
|
|
@@ -139,15 +139,12 @@ function* replacePinnedWithRestore(io, file, replacement, maxRestoreBytes, repla
|
|
|
139
139
|
if (io.asynchronous)
|
|
140
140
|
yield chmod;
|
|
141
141
|
yield* file.sync();
|
|
142
|
-
throw restoreFailure(writeError, "restored");
|
|
143
142
|
}
|
|
144
143
|
catch (restoreError) {
|
|
145
144
|
mutation.rethrowRefusal();
|
|
146
|
-
if (restoreError instanceof FsSafeError && restoreError.details?.cleanup === "restored") {
|
|
147
|
-
throw restoreError;
|
|
148
|
-
}
|
|
149
145
|
throw restoreFailure(writeError, "restore-failed", restoreError);
|
|
150
146
|
}
|
|
147
|
+
throw restoreFailure(writeError, "restored");
|
|
151
148
|
}
|
|
152
149
|
}
|
|
153
150
|
export function* copyFallbackReplace(io, params) {
|
|
@@ -139,6 +139,12 @@ export function* writeTempFile(io, params) {
|
|
|
139
139
|
const writing = file.writeFile(params.content, true);
|
|
140
140
|
if (io.asynchronous)
|
|
141
141
|
yield writing;
|
|
142
|
+
if (io.asyncFs === fs && process.platform !== "win32" && !params.sync) {
|
|
143
|
+
// Matching non-durable writes have no I/O left after this identity fence.
|
|
144
|
+
const current = inspectAtomicIdentity(io, () => file.statExact(), identity, true);
|
|
145
|
+
if (Number(current.mode & 4095n) === (params.mode & 0o7777))
|
|
146
|
+
return { file, identity };
|
|
147
|
+
}
|
|
142
148
|
const chmod = file.chmod(params.mode);
|
|
143
149
|
if (io.asynchronous)
|
|
144
150
|
yield chmod;
|
|
@@ -1,14 +1,28 @@
|
|
|
1
|
-
import type { PinnedWriteInput } from "./pinned-write-types.js";
|
|
1
|
+
import type { NativeWriteParent, PinnedWriteInput, PublishedWriteIdentity } from "./pinned-write-types.js";
|
|
2
2
|
import type { RootCreateOptions, RootCreateStreamOptions, RootWriteOptions } from "./root-options.js";
|
|
3
|
+
import type { AnyAsyncDirectoryGuard } from "./directory-guard.js";
|
|
3
4
|
declare const exclusiveSidecarCreate: unique symbol;
|
|
4
5
|
export declare const sidecarExclusiveCreate: Readonly<{
|
|
5
6
|
[exclusiveSidecarCreate]: true;
|
|
6
7
|
}>;
|
|
8
|
+
export declare const retainSidecarCreated: unique symbol;
|
|
9
|
+
export type SidecarCreationRetention = Readonly<{
|
|
10
|
+
retain(fd: number, parent: AnyAsyncDirectoryGuard, nativeParent?: NativeWriteParent): void;
|
|
11
|
+
cleanup(fd: number, parent: NativeWriteParent, identity: PublishedWriteIdentity): void;
|
|
12
|
+
}>;
|
|
7
13
|
export type RootWriteParams = RootWriteOptions & RootCreateOptions & RootCreateStreamOptions & {
|
|
8
14
|
relativePath: string;
|
|
9
15
|
data: string | Buffer | AsyncIterable<Uint8Array>;
|
|
10
16
|
strictFileSync?: boolean;
|
|
11
17
|
[exclusiveSidecarCreate]?: true;
|
|
18
|
+
[retainSidecarCreated]?: SidecarCreationRetention;
|
|
19
|
+
};
|
|
20
|
+
export declare function sidecarRetainedCreate(retain: NonNullable<RootWriteParams[typeof retainSidecarCreated]>): {
|
|
21
|
+
[exclusiveSidecarCreate]: true;
|
|
22
|
+
[retainSidecarCreated]: Readonly<{
|
|
23
|
+
retain(fd: number, parent: AnyAsyncDirectoryGuard, nativeParent?: NativeWriteParent): void;
|
|
24
|
+
cleanup(fd: number, parent: NativeWriteParent, identity: PublishedWriteIdentity): void;
|
|
25
|
+
}>;
|
|
12
26
|
};
|
|
13
27
|
export declare function rethrowCreateInputError(error: unknown): never;
|
|
14
28
|
export declare function createInputOptions(data: RootWriteParams["data"], options: RootCreateOptions & RootCreateStreamOptions, defaultMaxBytes?: number): RootCreateOptions & RootCreateStreamOptions;
|
|
@@ -5,6 +5,10 @@ import { MutationAuthorityError } from "./mutation-authority.js";
|
|
|
5
5
|
// Keep this composition hook off the public Root options and package exports.
|
|
6
6
|
const exclusiveSidecarCreate = Symbol("exclusiveSidecarCreate");
|
|
7
7
|
export const sidecarExclusiveCreate = Object.freeze({ [exclusiveSidecarCreate]: true });
|
|
8
|
+
export const retainSidecarCreated = Symbol("retainSidecarCreated");
|
|
9
|
+
export function sidecarRetainedCreate(retain) {
|
|
10
|
+
return { ...sidecarExclusiveCreate, [retainSidecarCreated]: retain };
|
|
11
|
+
}
|
|
8
12
|
class CreateInputError extends FsSafeError {
|
|
9
13
|
rejection;
|
|
10
14
|
constructor(rejection) {
|
|
@@ -17,7 +17,7 @@ export async function lookupRootDirectoryEntry(root, guard, name) {
|
|
|
17
17
|
const observed = inspectStatObservationSync(bigint => bigint
|
|
18
18
|
? fs.lstatSync(pathname, { bigint: true }) : fs.lstatSync(pathname));
|
|
19
19
|
await assertRootDirectoryObservationGuard(root, guard);
|
|
20
|
-
return { entry:
|
|
20
|
+
return { entry: pathStatFromStats(observed.stat, name), identity: observed.identity };
|
|
21
21
|
}
|
|
22
22
|
catch (error) {
|
|
23
23
|
await assertRootDirectoryObservationGuard(root, guard);
|
|
@@ -16,6 +16,5 @@ export declare function assertRootDirectoryObservationGuard(root: RootContext, g
|
|
|
16
16
|
* both its identity and canonical check here.
|
|
17
17
|
*/
|
|
18
18
|
export declare function assertRootPathObservationReceiptCurrent(root: RootContext, receipt: RootPathObservationReceipt | RootPathParentObservationReceipt, finalTarget?: Stats | BigIntStats): void;
|
|
19
|
-
export declare function listDirectoryPath(root: RootContext, directory: string, withFileTypes: true, receipt?: RootPathObservationReceipt): Promise<DirEntry[]>;
|
|
20
19
|
export declare function listDirectoryPath(root: RootContext, directory: string, withFileTypes: boolean, receipt?: RootPathObservationReceipt): Promise<string[] | DirEntry[]>;
|
|
21
20
|
export declare function openRootDirectoryListing(root: RootContext, directory: string, options: RootDirectoryListingOptions, receipt?: RootPathObservationReceipt): Promise<RootDirectoryListing>;
|