@openclaw/feishu 2026.10.1-beta.1 → 2026.10.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/{channel-CX62T71S.mjs → channel-DoRSlOQd.mjs} +7 -7
- package/dist/.setup/{channel.runtime-COiaq-Rv.mjs → channel.runtime-jLSFNkJh.mjs} +6 -6
- package/dist/.setup/{chat-BdyvImsY.mjs → chat-mTBvMMvx.mjs} +2 -2
- package/dist/.setup/{client-BsBVWJzN.mjs → client-CcxmEkoy.mjs} +1 -1
- package/dist/.setup/{doctor-contract-B1B9ogdd.mjs → doctor-contract-DyOo8NvC.mjs} +15 -5
- package/dist/.setup/{monitor-7DvwUs4Y.mjs → monitor-DX3vAlY9.mjs} +3 -3
- package/dist/.setup/{monitor.account-7xVu7XWY.mjs → monitor.account-C_uDFPtG.mjs} +9 -9
- package/dist/.setup/{probe-B9o7iey6.mjs → probe-BjSykXB8.mjs} +2 -2
- package/dist/.setup/{reply-delivery-result-Bt-BWBEA.mjs → reply-delivery-result-laBNOmBu.mjs} +2 -2
- package/dist/.setup/{setup-api-DmzX9S01.mjs → setup-api-DTTsvzfC.mjs} +1 -1
- package/dist/.setup/{subagent-hooks-CUXg0pC-.mjs → subagent-hooks-C8Z_x3KJ.mjs} +1 -1
- package/dist/api.js +5 -5
- package/dist/channel-plugin-api.js +1 -1
- package/dist/doctor-contract-api.js +2 -2
- 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 +56 -0
- 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-entry.js +7 -3
- package/node_modules/@openclaw/fs-safe/dist/copy-root-file-sync.d.ts +35 -0
- package/node_modules/@openclaw/fs-safe/dist/copy-root-file-sync.js +218 -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/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 +3 -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-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 +48 -5
- 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.js +1 -1
- 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-native.d.ts +4 -0
- package/node_modules/@openclaw/fs-safe/dist/publish-file-native.js +35 -0
- package/node_modules/@openclaw/fs-safe/dist/publish-file.d.ts +2 -0
- package/node_modules/@openclaw/fs-safe/dist/publish-file.js +8 -2
- package/node_modules/@openclaw/fs-safe/dist/replace-directory.js +6 -5
- package/node_modules/@openclaw/fs-safe/dist/root-errors.js +25 -4
- package/node_modules/@openclaw/fs-safe/dist/root-impl.js +3 -3
- 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/sibling-staged-file.js +18 -3
- package/node_modules/@openclaw/fs-safe/dist/staged-file-settlement.js +4 -1
- 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/docs/advanced.md +1 -0
- package/node_modules/@openclaw/fs-safe/docs/archive.md +2 -1
- package/node_modules/@openclaw/fs-safe/docs/copy.md +61 -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/native-helper.md +5 -3
- package/node_modules/@openclaw/fs-safe/docs/native.md +39 -6
- package/node_modules/@openclaw/fs-safe/docs/public-api.md +3 -1
- package/node_modules/@openclaw/fs-safe/docs/staged-file.md +10 -3
- package/node_modules/@openclaw/fs-safe/docs/watch.md +3 -1
- package/node_modules/@openclaw/fs-safe/docs/writing.md +40 -11
- package/node_modules/@openclaw/fs-safe/package.json +11 -11
- 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/package.json +5 -5
|
@@ -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 });
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { BigIntStats } from "node:fs";
|
|
2
|
+
import type { NativeBinding } from "./native-binding.js";
|
|
3
|
+
import { type PublishFailureState } from "./publish-file-failure.js";
|
|
4
|
+
export declare function publishFileNoReplaceNative(binding: NativeBinding, paths: Parameters<NativeBinding["renameNoReplace"]>, expected: BigIntStats, failure: PublishFailureState): "link-unlink" | undefined;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { FsSafeError } from "./errors.js";
|
|
2
|
+
import { getFsSafeNativeConfig } from "./native-config.js";
|
|
3
|
+
import { nativeMoveNoReplace } from "./native-move-fallback.js";
|
|
4
|
+
import { rememberCreatedTarget } from "./publish-file-failure.js";
|
|
5
|
+
export function publishFileNoReplaceNative(binding, paths, expected, failure) {
|
|
6
|
+
try {
|
|
7
|
+
const fallback = nativeMoveNoReplace(binding, paths, expected, getFsSafeNativeConfig().mode === "auto", "file publication");
|
|
8
|
+
if (fallback) {
|
|
9
|
+
failure.fallback = fallback;
|
|
10
|
+
failure.sourceRemoval = "removed";
|
|
11
|
+
}
|
|
12
|
+
return fallback;
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
if (error instanceof FsSafeError && error.details?.publication === "published") {
|
|
16
|
+
failure.targetCreated = true;
|
|
17
|
+
failure.preserveTarget = true;
|
|
18
|
+
failure.phase = "rename-verify";
|
|
19
|
+
failure.fallback = "link-unlink";
|
|
20
|
+
failure.sourceRemoval = error.details.sourceRemoval;
|
|
21
|
+
// Changed/unverified pairs cannot establish which inode was published.
|
|
22
|
+
if (failure.sourceRemoval === "still-linked")
|
|
23
|
+
rememberCreatedTarget(failure, expected, "rename-verify");
|
|
24
|
+
}
|
|
25
|
+
if (error instanceof FsSafeError)
|
|
26
|
+
throw error;
|
|
27
|
+
const code = error?.code;
|
|
28
|
+
if (code === "path-mismatch" || code === "hardlink") {
|
|
29
|
+
throw new FsSafeError(code, "publication source changed before fallback", { cause: error });
|
|
30
|
+
}
|
|
31
|
+
if (code === "ELOOP")
|
|
32
|
+
throw new FsSafeError("symlink", "publication source became a symlink", { cause: error });
|
|
33
|
+
throw error;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -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,4 @@
|
|
|
1
|
+
import { publishFileNoReplaceNative } from "./publish-file-native.js";
|
|
1
2
|
import { createHash } from "node:crypto";
|
|
2
3
|
import fsSync, {} from "node:fs";
|
|
3
4
|
import fs, {} from "node:fs/promises";
|
|
@@ -256,7 +257,7 @@ export async function publishFileExclusive(params) {
|
|
|
256
257
|
else
|
|
257
258
|
assertSourceCurrent();
|
|
258
259
|
assertPublishedTargetCurrent(targetPath, identity, "publication target changed during directory sync");
|
|
259
|
-
return { method, identity: fsSync.fstatSync(handle.fd), directorySync };
|
|
260
|
+
return { method, ...(failure.fallback ? { fallback: failure.fallback } : {}), identity: fsSync.fstatSync(handle.fd), directorySync };
|
|
260
261
|
};
|
|
261
262
|
await parent.assertCurrent();
|
|
262
263
|
assertSourceCurrent();
|
|
@@ -269,7 +270,12 @@ export async function publishFileExclusive(params) {
|
|
|
269
270
|
}
|
|
270
271
|
if (strategy === "rename-noreplace") {
|
|
271
272
|
const binding = requireNativeBinding();
|
|
272
|
-
binding
|
|
273
|
+
publishFileNoReplaceNative(binding, [
|
|
274
|
+
sourceNativeParent.handle.fd,
|
|
275
|
+
sourceNativeParent.basename,
|
|
276
|
+
targetNativeParent.handle.fd,
|
|
277
|
+
targetNativeParent.basename,
|
|
278
|
+
], sourceExactIdentity, failure);
|
|
273
279
|
rememberCreatedTarget(failure, sourceExactIdentity, "rename-verify");
|
|
274
280
|
// A failed post-rename fence must not delete the only remaining name.
|
|
275
281
|
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) {
|
|
@@ -29,7 +29,7 @@ export function hardlinkedPathNotAllowedError() {
|
|
|
29
29
|
export function isAlreadyExistsError(error) {
|
|
30
30
|
return hasNodeErrorCode(error, "EEXIST") || /File exists|EEXIST/i.test(String(error));
|
|
31
31
|
}
|
|
32
|
-
function
|
|
32
|
+
function resourceExhaustion(error) {
|
|
33
33
|
const pending = [error];
|
|
34
34
|
let details;
|
|
35
35
|
let code;
|
|
@@ -45,7 +45,11 @@ function descriptorExhaustion(error) {
|
|
|
45
45
|
const diagnostic = current;
|
|
46
46
|
if (current instanceof FsSafeError && (!details || current.details?.cleanup))
|
|
47
47
|
details = current.details ?? details;
|
|
48
|
-
if (diagnostic.code === "EMFILE" || diagnostic.code === "ENFILE")
|
|
48
|
+
if (diagnostic.code === "EMFILE" || diagnostic.code === "ENFILE") {
|
|
49
|
+
if (!code || code === "ENOSPC")
|
|
50
|
+
code = diagnostic.code;
|
|
51
|
+
}
|
|
52
|
+
else if (diagnostic.code === "ENOSPC")
|
|
49
53
|
code ??= diagnostic.code;
|
|
50
54
|
if (diagnostic.name === "SuppressedError")
|
|
51
55
|
pending.push(diagnostic.suppressed, diagnostic.error);
|
|
@@ -55,15 +59,32 @@ function descriptorExhaustion(error) {
|
|
|
55
59
|
}
|
|
56
60
|
if (!code)
|
|
57
61
|
return;
|
|
62
|
+
// Disk-space diagnostics retain the published direct-write code and already-classified errors.
|
|
63
|
+
if (code === "ENOSPC" && error instanceof FsSafeError)
|
|
64
|
+
return;
|
|
58
65
|
const cleanup = details?.cleanup;
|
|
59
66
|
const publication = details?.publication;
|
|
60
67
|
const preserved = cleanup?.status === "preserved" && publication?.status === "indeterminate";
|
|
61
|
-
|
|
68
|
+
const message = code === "ENOSPC" ? PINNED_WRITE_ERRNO_MESSAGES.get(code) : "filesystem write failed: too many open files";
|
|
69
|
+
return new FsSafeError(code === "ENOSPC" ? "invalid-path" : "helper-failed", `${message} (${code})${preserved ? "; publication outcome is indeterminate; staged file preserved" : ""}`, { cause: error, details });
|
|
62
70
|
}
|
|
63
71
|
export function normalizePinnedWriteError(error) {
|
|
64
|
-
const exhausted =
|
|
72
|
+
const exhausted = resourceExhaustion(error);
|
|
65
73
|
if (exhausted)
|
|
66
74
|
return exhausted;
|
|
75
|
+
// Disposal retains cleanup evidence, but the failed publication remains primary.
|
|
76
|
+
let primary = error;
|
|
77
|
+
const seen = new Set();
|
|
78
|
+
try {
|
|
79
|
+
while (primary instanceof Error && primary.name === "SuppressedError" && !seen.has(primary)) {
|
|
80
|
+
seen.add(primary);
|
|
81
|
+
primary = primary.suppressed;
|
|
82
|
+
}
|
|
83
|
+
if (primary !== error && primary instanceof FsSafeError && primary.details?.phase === "publish") {
|
|
84
|
+
return new FsSafeError(primary.code, primary.message, { cause: error, details: primary.details });
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
catch { /* Unreadable diagnostics retain the original failure. */ }
|
|
67
88
|
if (error instanceof FsSafeError) {
|
|
68
89
|
return error;
|
|
69
90
|
}
|
|
@@ -1167,10 +1167,10 @@ async function movePathFallback(root, params) {
|
|
|
1167
1167
|
let sourceIdentity;
|
|
1168
1168
|
try {
|
|
1169
1169
|
if (params.overwrite && params.assertBeforeMutation) {
|
|
1170
|
-
sourceIdentity = inspectFileIdentitySync(() => admitMoveSourceStat(fsSync.lstatSync(source.resolved, { bigint: true })
|
|
1170
|
+
sourceIdentity = inspectFileIdentitySync(() => admitMoveSourceStat(fsSync.lstatSync(source.resolved, { bigint: true })));
|
|
1171
1171
|
}
|
|
1172
1172
|
else {
|
|
1173
|
-
admitMoveSourceStat(fsSync.lstatSync(source.resolved)
|
|
1173
|
+
admitMoveSourceStat(fsSync.lstatSync(source.resolved));
|
|
1174
1174
|
}
|
|
1175
1175
|
}
|
|
1176
1176
|
catch (error) {
|
|
@@ -1234,7 +1234,7 @@ async function movePathFallback(root, params) {
|
|
|
1234
1234
|
}
|
|
1235
1235
|
}
|
|
1236
1236
|
}
|
|
1237
|
-
inspectFileIdentitySync(() => admitMoveSourceStat(fsSync.lstatSync(source.resolved, { bigint: true })
|
|
1237
|
+
inspectFileIdentitySync(() => admitMoveSourceStat(fsSync.lstatSync(source.resolved, { bigint: true })), sourceIdentity);
|
|
1238
1238
|
}
|
|
1239
1239
|
await fs.rename(source.resolved, target.resolved);
|
|
1240
1240
|
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { type BigIntStats, type Stats } from "node:fs";
|
|
2
2
|
import type { RootMoveOptions } from "./root-options.js";
|
|
3
3
|
import { type RootContext } from "./root-context.js";
|
|
4
|
-
export declare function admitMoveSourceStat<T extends Stats | BigIntStats>(stat: T
|
|
5
|
-
export declare function movePathNative(root: RootContext, params: Pick<RootMoveOptions, "assertBeforeMutation" | "denyMutations" | "mutationSymlinks"
|
|
4
|
+
export declare function admitMoveSourceStat<T extends Stats | BigIntStats>(stat: T): T;
|
|
5
|
+
export declare function movePathNative(root: RootContext, params: Pick<RootMoveOptions, "assertBeforeMutation" | "denyMutations" | "mutationSymlinks"> & {
|
|
6
|
+
requireNative: boolean;
|
|
7
|
+
}, paths: {
|
|
6
8
|
sourcePath: string;
|
|
7
9
|
sourceParentPath: string;
|
|
8
10
|
targetPath: string;
|
|
@@ -15,6 +15,7 @@ import { PATH_ALIAS_POLICIES } from "./path-policy.js";
|
|
|
15
15
|
import { createSuppressedError } from "./suppressed-error.js";
|
|
16
16
|
import { inspectFileIdentitySync } from "./strict-file-identity.js";
|
|
17
17
|
import { getFsSafeTestHooks } from "./test-hooks.js";
|
|
18
|
+
import { nativeMoveNoReplace } from "./native-move-fallback.js";
|
|
18
19
|
function nativeParentRelativePath(rootReal, parentPath) {
|
|
19
20
|
const relative = path.relative(rootReal, parentPath);
|
|
20
21
|
if (relative === "" || relative === ".")
|
|
@@ -57,22 +58,13 @@ function normalizeMoveError(error) {
|
|
|
57
58
|
}
|
|
58
59
|
return error;
|
|
59
60
|
}
|
|
60
|
-
function
|
|
61
|
-
if (error?.code === "EINVAL") {
|
|
62
|
-
return new FsSafeError("helper-unavailable", "native no-replace move is unavailable on this filesystem", errorCauseOptions(error));
|
|
63
|
-
}
|
|
64
|
-
return normalizeMoveError(error);
|
|
65
|
-
}
|
|
66
|
-
export function admitMoveSourceStat(stat, overwrite = false) {
|
|
61
|
+
export function admitMoveSourceStat(stat) {
|
|
67
62
|
if (stat.isSymbolicLink()) {
|
|
68
63
|
throw new FsSafeError("symlink", "symlink not allowed");
|
|
69
64
|
}
|
|
70
65
|
if (stat.isFile() && stat.nlink > 1) {
|
|
71
66
|
throw hardlinkedPathNotAllowedError();
|
|
72
67
|
}
|
|
73
|
-
if (!overwrite && stat.isDirectory()) {
|
|
74
|
-
throw new FsSafeError("invalid-path", "directory moves require overwrite: true");
|
|
75
|
-
}
|
|
76
68
|
return stat;
|
|
77
69
|
}
|
|
78
70
|
export async function movePathNative(root, params, paths, overwrite = false) {
|
|
@@ -124,10 +116,9 @@ export async function movePathNative(root, params, paths, overwrite = false) {
|
|
|
124
116
|
await assertRootIdentityCurrent(root);
|
|
125
117
|
for (const admission of parentAdmissions)
|
|
126
118
|
assertSyncDirectoryGuard(admission.guard);
|
|
127
|
-
//
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
? inspectFileIdentitySync(() => admitMoveSourceStat(fsSync.lstatSync(admittedSourcePath, { bigint: true }), overwrite), paths.expectedSourceIdentity)
|
|
119
|
+
// Linux auto fallback needs an exact source even without an authority callback.
|
|
120
|
+
const sourceStat = overwrite || params.assertBeforeMutation || (process.platform === "linux" && !params.requireNative)
|
|
121
|
+
? inspectFileIdentitySync(() => admitMoveSourceStat(fsSync.lstatSync(admittedSourcePath, { bigint: true })), paths.expectedSourceIdentity)
|
|
131
122
|
: undefined;
|
|
132
123
|
if (!sourceStat)
|
|
133
124
|
admitMoveSourceStat(fsSync.lstatSync(admittedSourcePath));
|
|
@@ -172,20 +163,25 @@ export async function movePathNative(root, params, paths, overwrite = false) {
|
|
|
172
163
|
}
|
|
173
164
|
}
|
|
174
165
|
if (sourceStat !== undefined) {
|
|
175
|
-
inspectFileIdentitySync(() => admitMoveSourceStat(fsSync.lstatSync(admittedSourcePath, { bigint: true })
|
|
166
|
+
inspectFileIdentitySync(() => admitMoveSourceStat(fsSync.lstatSync(admittedSourcePath, { bigint: true })), sourceStat);
|
|
176
167
|
}
|
|
177
168
|
try {
|
|
178
169
|
assertFinalSymlinkRejected(admittedTargetPath, params.mutationSymlinks !== undefined);
|
|
179
170
|
if (overwrite)
|
|
180
171
|
binding.renameReplaceWithIdentity(sourceParent.fd, path.basename(paths.sourcePath), targetParent.fd, path.basename(paths.targetPath), sourceStat.dev, sourceStat.ino);
|
|
181
172
|
else
|
|
182
|
-
binding
|
|
173
|
+
nativeMoveNoReplace(binding, [
|
|
174
|
+
sourceParent.fd,
|
|
175
|
+
path.basename(paths.sourcePath),
|
|
176
|
+
targetParent.fd,
|
|
177
|
+
path.basename(paths.targetPath),
|
|
178
|
+
], sourceStat, !params.requireNative);
|
|
183
179
|
}
|
|
184
180
|
catch (error) {
|
|
185
181
|
if (isAlreadyExistsError(error) || (!overwrite && error?.code === "ENOTEMPTY")) {
|
|
186
182
|
throw new FsSafeError("already-exists", "destination exists", errorCauseOptions(error));
|
|
187
183
|
}
|
|
188
|
-
throw
|
|
184
|
+
throw normalizeMoveError(error);
|
|
189
185
|
}
|
|
190
186
|
try {
|
|
191
187
|
for (const admission of parentAdmissions)
|
|
@@ -8,6 +8,8 @@ import { syncDirectoryBestEffort } from "./directory-durability.js";
|
|
|
8
8
|
import { isWindowsReservedDeviceName } from "./device-path.js";
|
|
9
9
|
import { FsSafeError } from "./errors.js";
|
|
10
10
|
import { getNativeBinding } from "./native.js";
|
|
11
|
+
import { isFsSafeNativeRequired } from "./native-config.js";
|
|
12
|
+
import { cachedNoReplaceDevice, isNoReplaceUnavailable } from "./native-noreplace.js";
|
|
11
13
|
import { handoffPrivateProducerFile, } from "./private-producer-handoff.js";
|
|
12
14
|
import { resolveReadOpenFlags } from "./read-open-flags.js";
|
|
13
15
|
import { rootFromDirectoryGuard } from "./root-impl.js";
|
|
@@ -109,8 +111,18 @@ async function writeIsolatedProducer(params) {
|
|
|
109
111
|
const result = await Reflect.apply(write, writeReceiver, [producerPath]);
|
|
110
112
|
assertCurrent();
|
|
111
113
|
if (native) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
+
try {
|
|
115
|
+
const cached = cachedNoReplaceDevice(native, parentGuard.stat.dev, "producer handoff");
|
|
116
|
+
if (cached)
|
|
117
|
+
throw cached;
|
|
118
|
+
await targetRoot.move(path.relative(targetRoot.rootReal, producerPath), path.basename(tempPath), { assertBeforeMutation: assertCurrent });
|
|
119
|
+
return { cleanupWorkspace, result };
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
if (isFsSafeNativeRequired() || !isNoReplaceUnavailable(error))
|
|
123
|
+
throw error;
|
|
124
|
+
assertCurrent();
|
|
125
|
+
}
|
|
114
126
|
}
|
|
115
127
|
const handoff = await handoffPrivateProducerFile({
|
|
116
128
|
sourcePath: producerPath,
|
|
@@ -126,7 +138,10 @@ async function writeIsolatedProducer(params) {
|
|
|
126
138
|
await cleanupWorkspace();
|
|
127
139
|
}
|
|
128
140
|
catch (cleanupError) {
|
|
129
|
-
|
|
141
|
+
const combined = new AggregateError([error, cleanupError], "isolated producer operation and workspace cleanup failed");
|
|
142
|
+
if (isNoReplaceUnavailable(error))
|
|
143
|
+
throw new FsSafeError(error.code, error.message, { cause: combined });
|
|
144
|
+
throw combined;
|
|
130
145
|
}
|
|
131
146
|
throw error;
|
|
132
147
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { FsSafeError } from "./errors.js";
|
|
2
|
+
import { noReplaceUnavailable } from "./native-noreplace.js";
|
|
2
3
|
export function createStagedFileReceipt(directory, temporaryBasename, stat) {
|
|
3
4
|
return Object.freeze({
|
|
4
5
|
directory,
|
|
@@ -11,6 +12,7 @@ export function createStagedFileReceipt(directory, temporaryBasename, stat) {
|
|
|
11
12
|
});
|
|
12
13
|
}
|
|
13
14
|
export function stagedFailure(kind, error, details) {
|
|
15
|
+
error = noReplaceUnavailable(error, `${kind} publication`) ?? error;
|
|
14
16
|
let code = "helper-failed";
|
|
15
17
|
try {
|
|
16
18
|
code = error instanceof FsSafeError ? error.code
|
|
@@ -19,7 +21,8 @@ export function stagedFailure(kind, error, details) {
|
|
|
19
21
|
catch {
|
|
20
22
|
// Uninspectable error metadata must not interrupt terminal settlement.
|
|
21
23
|
}
|
|
22
|
-
return new FsSafeError(code,
|
|
24
|
+
return new FsSafeError(code, code === "helper-unavailable" && error instanceof FsSafeError
|
|
25
|
+
? error.message : `staged ${kind} ${details.phase} failed`, { cause: error, details });
|
|
23
26
|
}
|
|
24
27
|
/** Finish owned cleanup and every close before surfacing publication evidence. */
|
|
25
28
|
export async function settleStagedFile(params) {
|
|
@@ -9,6 +9,7 @@ export declare class TempWorkspaceCleanupCapability {
|
|
|
9
9
|
readonly parent: RetainedDirectory | undefined;
|
|
10
10
|
constructor(root: string, safety: TempWorkspaceCleanupSafety, admission: TempWorkspaceRootAdmission, dirMode: number);
|
|
11
11
|
get canRemoveOwnedTree(): boolean;
|
|
12
|
+
get canUseCompatibleCleanup(): boolean;
|
|
12
13
|
prepareChildCreation(): void;
|
|
13
14
|
admitChildDescriptor(canEnumerate: boolean): boolean;
|
|
14
15
|
assertCurrent(): void;
|
|
@@ -8,6 +8,8 @@ import { sameFileIdentityForCleanup } from "./file-identity.js";
|
|
|
8
8
|
import { getNativeBinding } from "./native.js";
|
|
9
9
|
import { openTempWorkspaceCleanupParent, TempWorkspaceRetainedChild, } from "./temp-workspace-descriptor.js";
|
|
10
10
|
import { getFsSafeTestHooks } from "./test-hooks.js";
|
|
11
|
+
import { isFsSafeNativeRequired } from "./native-config.js";
|
|
12
|
+
import { cachedNoReplaceUnavailable, noReplaceUnavailable, rememberNoReplaceUnavailable } from "./native-noreplace.js";
|
|
11
13
|
function isNativeCleanupBinding(binding) {
|
|
12
14
|
return typeof binding?.renameNoReplace === "function" &&
|
|
13
15
|
typeof binding.removeOwnedTree === "function" &&
|
|
@@ -94,6 +96,9 @@ export class TempWorkspaceCleanupCapability {
|
|
|
94
96
|
return (this.#phase === "ready" || this.#phase === "sealed") &&
|
|
95
97
|
this.#ownedTreeRemovalAvailable;
|
|
96
98
|
}
|
|
99
|
+
get canUseCompatibleCleanup() {
|
|
100
|
+
return this.#safety === "compatible" && !isFsSafeNativeRequired();
|
|
101
|
+
}
|
|
97
102
|
prepareChildCreation() {
|
|
98
103
|
const replay = this.#phase === "ready";
|
|
99
104
|
if (this.#phase !== "new" && !replay) {
|
|
@@ -269,11 +274,27 @@ export class TempWorkspaceCleanupOwner {
|
|
|
269
274
|
}
|
|
270
275
|
const name = `.fs-safe-workspace-cleanup-${randomUUID()}`;
|
|
271
276
|
const quarantinePath = path.join(parent.receipt.path, name);
|
|
272
|
-
|
|
277
|
+
let nativeRemoval = this.#capability.canRemoveOwnedTree && this.#directory !== undefined;
|
|
273
278
|
if (nativeRemoval) {
|
|
274
|
-
this.#capability.binding
|
|
279
|
+
const binding = this.#capability.binding;
|
|
280
|
+
try {
|
|
281
|
+
const cached = cachedNoReplaceUnavailable(binding, parent.fd, "workspace quarantine");
|
|
282
|
+
if (cached)
|
|
283
|
+
throw cached;
|
|
284
|
+
binding.renameNoReplace(parent.fd, path.basename(this.#dir), parent.fd, name);
|
|
285
|
+
}
|
|
286
|
+
catch (error) {
|
|
287
|
+
const unavailable = error instanceof FsSafeError && error.code === "helper-unavailable"
|
|
288
|
+
? error : noReplaceUnavailable(error, "workspace quarantine", true);
|
|
289
|
+
if (!unavailable)
|
|
290
|
+
throw error;
|
|
291
|
+
rememberNoReplaceUnavailable(binding, parent.fd, unavailable);
|
|
292
|
+
if (!this.#capability.canUseCompatibleCleanup)
|
|
293
|
+
throw unavailable;
|
|
294
|
+
nativeRemoval = false;
|
|
295
|
+
}
|
|
275
296
|
}
|
|
276
|
-
|
|
297
|
+
if (!nativeRemoval) {
|
|
277
298
|
// The admitted receipt is exact and descriptor-associated. Reuse it as
|
|
278
299
|
// the pre/post parent fence instead of layering a numeric guard over it.
|
|
279
300
|
this.#capability.assertCurrent();
|
|
@@ -288,7 +309,9 @@ export class TempWorkspaceCleanupOwner {
|
|
|
288
309
|
}
|
|
289
310
|
return { name, path: quarantinePath, nativeRemoval };
|
|
290
311
|
}
|
|
291
|
-
catch {
|
|
312
|
+
catch (error) {
|
|
313
|
+
if (error instanceof FsSafeError && error.code === "helper-unavailable")
|
|
314
|
+
throw error;
|
|
292
315
|
// A failed rename can still have committed on a remote filesystem.
|
|
293
316
|
return "indeterminate";
|
|
294
317
|
}
|
|
@@ -82,6 +82,7 @@ concurrent namespace changes.
|
|
|
82
82
|
| `appendRegularFile`, `appendRegularFileSync`, `readRegularFile`, `readRegularFileSync`, `statRegularFile`, `statRegularFileSync`, `resolveRegularFileAppendFlags`, `AppendRegularFileOptions`, `RegularFileStatResult` | [regular-file.md](regular-file.md) | Type-checked regular-file I/O. |
|
|
83
83
|
| `retainEntryForPublication`, `RetainedEntryPublication`, `RetainEntryForPublicationOptions`, `EntryPublicationReceipt`, `EntryPublicationResult`, `EntryPublicationIssue`, `PublicationIdentity`, `PublicationParent` | [One-way entry publication](entry-publication.md) | Native no-replace directory/regular-file/symlink export, including Windows NTFS junctions, under caller-exclusive namespace; explicit transition receipts, close-only disposal, no source CAS. |
|
|
84
84
|
| `retainFileInDirectory`, `RetainedFile`, related receipt/result types | [Retained Windows files](retained-file.md) | Existing-file native handle custody and explicit removal; local NTFS, producer authority required, no persistence guarantee. |
|
|
85
|
+
| `copyRootFileSync`, `CopyRootFileSyncOptions`, `CopiedRootFileSync` | [copy.md](copy.md#synchronous-guarded-file-copies) | Synchronous guarded exclusive file copy, optionally cloned and bound to an expected source identity, returning an owned destination descriptor and both identities. |
|
|
85
86
|
| `sameFileIdentity`, `FileIdentityStat` | – | Compare two stats for same-inode equality. |
|
|
86
87
|
| `readDirectoryIdentity`, `assertDirectoryIdentitySync`, `DirectoryIdentity` | [directory-identity.md](directory-identity.md) | Observe exact bigint directory identity and synchronously check a caller-selected path, optionally retaining its canonical path. |
|
|
87
88
|
| `pathExists`, `pathExistsSync` | – | Boolean existence check that does not throw on `ENOENT`. |
|
|
@@ -179,7 +179,8 @@ between native and JavaScript paths rather than reimplementing it in Rust.
|
|
|
179
179
|
|
|
180
180
|
ZIP extraction and bounded reads admit every physical central-directory record and its referenced local header before either decoder can normalize or collapse names. Raw names and valid Unicode Path names must pass traversal checks before stripping, filtering, or selecting a requested member; duplicate or colliding names reject with `entry-path`, even in unrelated or skipped members. Materially conflicting local/central or Unicode interpretations, malformed critical metadata, and ambiguous framing reject with `ArchiveFormatError`. Harmless internal separator and dot-component equivalence is allowed only after validation; every raw and Unicode interpretation must also agree on whether its name ends in `/` or `\`. Ordinary legacy filename decoding remains backend-selected. Native ZIP extraction groups nearby metadata reads into at most two 4 KiB read-ahead buffers per admission pass; larger records retain separately bounded reads. Buffered record views remain stable across eviction, and cached work periodically yields for deadline checks.
|
|
181
181
|
|
|
182
|
-
ZIP preflight and bounded reads
|
|
182
|
+
ZIP preflight and bounded reads use extraction's canonical path identity, including
|
|
183
|
+
removing directory trailing separators, and apply its case-insensitive NFC collision
|
|
183
184
|
policy to the complete archive, including entries that extraction would strip
|
|
184
185
|
or skip. Known UTF-8 and Unicode Path names are checked during physical admission;
|
|
185
186
|
legacy names retain backend-selected decoding and undergo the same collision
|
|
@@ -58,7 +58,7 @@ Apple [strongly discourages general directory cloning](https://github.com/apple-
|
|
|
58
58
|
| `"always"` | Require native cloning. Unsupported operations fail without a byte-copy fallback. |
|
|
59
59
|
| `"never"` | Copy regular file bytes using reads and writes. No native cloning or copy-offload calls. Works without a native binding. |
|
|
60
60
|
|
|
61
|
-
Automatic copying does not recover from permission errors, I/O errors, cancellation, or rejected source contents such as ReFS named streams. A failed clone must leave the destination absent before fallback can create it; otherwise copying fails rather than merging into a partial tree.
|
|
61
|
+
On Linux XFS and ZFS, `FICLONE` capability failures (including an ioctl denied by container seccomp or LSM policy with `EPERM`) select byte copying in `"auto"` mode; `"always"` reports `unsupported-platform`. Automatic copying does not recover from ordinary file-access permission errors, I/O errors, cancellation, or rejected source contents such as ReFS named streams. Native reflink workers settle and remove partial output before returning a clone failure. A failed clone must leave the destination absent before fallback can create it; otherwise copying fails rather than merging into a partial tree.
|
|
62
62
|
|
|
63
63
|
`concurrency` accepts integers from 1 through 32 and bounds active file copies. ReFS, XFS, and ZFS cloning default to 16 workers. Byte copying defaults to four concurrent files on Windows and one elsewhere. Btrfs uses its bulk operation. APFS uses a bulk clone followed by native directory-entry enumeration to restore directory timestamps; known regular files and symbolic links need no additional stat or open.
|
|
64
64
|
|
|
@@ -197,3 +197,63 @@ Run `node scripts/clone-xfs-proof.mjs MOUNT` on a real XFS volume to verify the
|
|
|
197
197
|
Run `node scripts/clone-zfs-proof.mjs MOUNT POOL` on a dedicated, otherwise idle Linux ZFS pool with compression and deduplication disabled. It verifies both `copyTree` and `Root.copyIn` through hashes and changes in the documented `bclonesaved` pool counter. It requires `zfs`, `zpool`, and `findmnt`, including permission to run `zpool sync`. Add `no-reflink` for a pool without block cloning to verify strict refusal and automatic byte fallback. The script creates and removes only its temporary directory; it does not create pools or change their properties.
|
|
198
198
|
|
|
199
199
|
Run `node benchmarks/clone.mjs SOURCE DESTINATION_PARENT` after `pnpm build` to compare one, four, and 16 workers on the same immutable source. Add `3 auto` or `3 never` to measure three samples of ordinary copying, including NTFS destinations. It records copying time separately from fixture preparation and full file-hash verification, and retains its uniquely named output directory for inspection. Prepare Btrfs sources with `createCloneSource` first.
|
|
200
|
+
|
|
201
|
+
## Synchronous guarded file copies
|
|
202
|
+
|
|
203
|
+
`copyRootFileSync` from `@openclaw/fs-safe/advanced` is for synchronous module
|
|
204
|
+
hooks and capture owners. Both roots and file paths are absolute; destination
|
|
205
|
+
parents must exist. The destination must be absent, and is created exclusively.
|
|
206
|
+
|
|
207
|
+
```ts
|
|
208
|
+
import { copyRootFileSync } from "@openclaw/fs-safe/advanced";
|
|
209
|
+
|
|
210
|
+
using copied = copyRootFileSync({
|
|
211
|
+
source: { rootPath: "/srv/plugins", absolutePath: "/srv/plugins/plugin.js" },
|
|
212
|
+
destination: { rootPath: "/srv/capture", absolutePath: "/srv/capture/plugin.js" },
|
|
213
|
+
clone: "auto",
|
|
214
|
+
maxBytes: 16 * 1024 * 1024,
|
|
215
|
+
mode: 0o600,
|
|
216
|
+
});
|
|
217
|
+
// Hash or read copied.fd: this is the owned destination, never a reopened path.
|
|
218
|
+
console.log(copied.bytes, copied.method, copied.identity, copied.sourceIdentity);
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
`CopyRootFileSyncOptions` selects the source and destination, `clone`, `maxBytes`,
|
|
222
|
+
`mode`, `preserveSourceMode`, `sourceHardlinks`, and optional `expectedSourceIdentity`.
|
|
223
|
+
`CopiedRootFileSync` owns a
|
|
224
|
+
readable/writable `fd`, with idempotent `close()` and `Symbol.dispose`, and returns
|
|
225
|
+
`path`, `bytes`, `method` (`"clone"`, `"copy-file-range"`, or `"copy"`), and exact
|
|
226
|
+
bigint destination `identity` and `sourceIdentity` (`dev`, `ino`). Both identities
|
|
227
|
+
are readonly and frozen. Closing releases the descriptor, not the file.
|
|
228
|
+
|
|
229
|
+
Callers that already pinned a source can pass `expectedSourceIdentity: { dev, ino }`
|
|
230
|
+
from `fs.fstatSync(pinnedSourceFd, { bigint: true })`. fs-safe still admits and
|
|
231
|
+
opens its own source descriptor, and compares its exact bigint identity before
|
|
232
|
+
creating any destination. A mismatch throws `FsSafeError("path-mismatch")`.
|
|
233
|
+
Keep the caller's descriptor open across the call; it remains caller-owned and
|
|
234
|
+
its cursor is unchanged. Do not derive the expectation from numeric stat fields,
|
|
235
|
+
which may have lost identity bits. Omitting the option preserves ordinary source
|
|
236
|
+
admission. Every successful copy method returns `sourceIdentity` for the source
|
|
237
|
+
actually copied, verified current again at the end of the operation. This binds
|
|
238
|
+
identity only; keep any existing source fingerprint/content and destination
|
|
239
|
+
receipt checks for concurrent edits and later replacements.
|
|
240
|
+
|
|
241
|
+
Clone policy matches `Root.copyIn`: the default is `"never"`; `"auto"` tries
|
|
242
|
+
native cloning, then bounded copy offload and byte copying on capability failure;
|
|
243
|
+
`"always"` requires cloning or throws `unsupported-platform`. APFS cloning
|
|
244
|
+
creates the guarded destination name from the admitted source descriptor. Linux
|
|
245
|
+
uses FICLONE and copy_file_range. Windows and native-disabled operation copy
|
|
246
|
+
bytes; they cannot satisfy `"always"`.
|
|
247
|
+
|
|
248
|
+
The source descriptor remains open through before/after source identity checks.
|
|
249
|
+
Symlink components are rejected; source hardlinks are rejected unless
|
|
250
|
+
`sourceHardlinks: "allow"` is selected. The byte limit is an EOF bound, not a
|
|
251
|
+
prefix length: overflow throws `too-large`. Omitted limits are unlimited. An
|
|
252
|
+
explicit mode wins over `preserveSourceMode`; otherwise new files use `0o600`
|
|
253
|
+
subject to the process umask, consistently with `copyIn`.
|
|
254
|
+
|
|
255
|
+
Failures attempt identity-checked removal of the owned destination and preserve
|
|
256
|
+
replacement entries. This helper creates directly at the destination name, so
|
|
257
|
+
other processes may observe partial bytes until it returns. It does not promise
|
|
258
|
+
crash durability or a coherent snapshot of concurrent in-place source edits.
|
|
259
|
+
Use a private capture directory and keep sources unchanged while capturing.
|
|
@@ -191,7 +191,37 @@ try {
|
|
|
191
191
|
|---|---|---|
|
|
192
192
|
| `link-required` | Create a same-filesystem hardlink or propagate the failure. | No; guarded JS `link` fallback remains. |
|
|
193
193
|
| `link-or-copy` | Try hardlink, then clone, Linux `copy_file_range`, then the JS byte loop for classified unsupported errors. | No; acceleration is optional. |
|
|
194
|
-
| `rename-noreplace` |
|
|
194
|
+
| `rename-noreplace` | Move the source without replacing an existing target; Linux `auto` can use identity-checked link/unlink when no-replace rename is unsupported. Success consumes `sourcePath`. | Yes. |
|
|
195
|
+
|
|
196
|
+
`rename-noreplace` normally uses atomic native rename. On Linux in native `auto`
|
|
197
|
+
mode, a definitively unsupported `RENAME_NOREPLACE` result (`EINVAL`, `ENOSYS`,
|
|
198
|
+
or unsupported-operation errno) permits the existing native file-move fallback.
|
|
199
|
+
It requires a regular source with one link, retains both parents, creates the
|
|
200
|
+
target with `linkat` without following symlinks, verifies both names against the
|
|
201
|
+
staged identity with exactly two links, then unlinks the source and verifies the
|
|
202
|
+
target has one link. Fallback collisions report `already-exists` without clobbering;
|
|
203
|
+
the atomic rename path retains its existing `EEXIST` error.
|
|
204
|
+
Success still returns `method: "rename-noreplace"`, with the additive
|
|
205
|
+
`fallback: "link-unlink"` field identifying this weaker mechanism. Atomic rename
|
|
206
|
+
and the other strategies omit `fallback`.
|
|
207
|
+
|
|
208
|
+
**Link/unlink is not crash-atomic.** A crash between those syscalls can leave both
|
|
209
|
+
names on the same complete inode. Callers must recognize that interrupted pair
|
|
210
|
+
as incomplete evidence or recover it under their own identity/ownership rules
|
|
211
|
+
before accepting a sealed artifact. The source parent is synchronized after
|
|
212
|
+
unlink, and the target parent is synchronized through the existing pinned
|
|
213
|
+
directory/`parentReceipt` path before success. These directory barriers do not
|
|
214
|
+
flush file contents: callers must finish and synchronize staged contents first.
|
|
215
|
+
Identity checks and syscalls remain separate, not source-name compare-and-swap;
|
|
216
|
+
detected substitutions refuse completion and preserve evidence.
|
|
217
|
+
|
|
218
|
+
Native `require` remains fail-closed with `helper-unavailable` and
|
|
219
|
+
`details.capability === "rename-noreplace"`. Missing helpers, native `off`, and
|
|
220
|
+
non-Linux platforms gain no fallback. If `linkat` returns `EPERM`, `EOPNOTSUPP`,
|
|
221
|
+
`EMLINK`, `EXDEV`, or `ENOSYS`, publication also fails closed, naming both
|
|
222
|
+
`rename-noreplace` and `details.fallbackCapability: "linkat"`. Permission or link
|
|
223
|
+
count limits need not mean the entire filesystem lacks hard-link support.
|
|
224
|
+
`link-required` and `link-or-copy` do not use `renameat2` and are unchanged.
|
|
195
225
|
|
|
196
226
|
`"link-required"` propagates an unsupported hardlink failure.
|
|
197
227
|
`"link-or-copy"` falls back only for `EPERM`, `EXDEV`, `ENOTSUP`,
|
|
@@ -339,6 +369,9 @@ type PublishFileExclusiveFailureDetails = {
|
|
|
339
369
|
targetIdentity?: { dev: number | bigint; ino: number | bigint };
|
|
340
370
|
cleanup: "removed" | "preserved" | "unknown";
|
|
341
371
|
directorySync?: { status: "failed"; code?: string };
|
|
372
|
+
fallback?: "link-unlink";
|
|
373
|
+
publication?: "published";
|
|
374
|
+
sourceRemoval?: "not-attempted" | "still-linked" | "unverified" | "removed";
|
|
342
375
|
};
|
|
343
376
|
```
|
|
344
377
|
|
|
@@ -352,6 +385,16 @@ this receipt instead of inferring ownership from path existence. The original
|
|
|
352
385
|
failure remains available as `cause`. Failures before target creation retain
|
|
353
386
|
their existing error shape and do not claim a cleanup result.
|
|
354
387
|
|
|
388
|
+
After a fallback link succeeds, failure always preserves the target, irrespective
|
|
389
|
+
of `onSyncFailure`. The receipt reports `fallback: "link-unlink"`,
|
|
390
|
+
`publication: "published"`, and the source-removal state. `still-linked` means
|
|
391
|
+
unlink failed and both names were reverified as the exact two-link pair;
|
|
392
|
+
`not-attempted` means pair verification failed before unlink; `unverified` means
|
|
393
|
+
unlink failed and the pair could no longer be verified; `removed` means unlink
|
|
394
|
+
completed but a later verification or sync failed. Publication describes the
|
|
395
|
+
completed link operation, not continuing authority over the target pathname.
|
|
396
|
+
Unverified targets do not receive a claimed `targetIdentity`.
|
|
397
|
+
|
|
355
398
|
Source and target identities are checked again after successful or unsupported
|
|
356
399
|
directory synchronization, while their descriptors remain owned. A late
|
|
357
400
|
verification failure retains its strategy's verification phase and is not a
|
|
@@ -389,13 +432,15 @@ can make a failed directory sync succeed: rollback deletion is also not proven
|
|
|
389
432
|
durable, and a preserved name may disappear after a crash. Always use the
|
|
390
433
|
typed receipt rather than inferring ownership from `exists()`.
|
|
391
434
|
|
|
392
|
-
`rename-noreplace` always preserves its target after a successful rename,
|
|
435
|
+
`rename-noreplace` always preserves its target after a successful rename or fallback link,
|
|
393
436
|
because removing it would discard the source's only remaining name; its typed
|
|
394
437
|
failure receipt makes that explicit regardless of `onSyncFailure`.
|
|
395
438
|
|
|
396
|
-
`"rename-noreplace"` requires the native helper and
|
|
397
|
-
source to the target without replacement
|
|
398
|
-
|
|
439
|
+
`"rename-noreplace"` requires the native helper and moves the
|
|
440
|
+
source to the target without replacement, with the Linux `auto` fallback limits
|
|
441
|
+
described above. A collision is reported as `EEXIST` for atomic rename or
|
|
442
|
+
`already-exists` for its Linux fallback, both files remain
|
|
443
|
+
unchanged, and a successful call returns
|
|
399
444
|
`method: "rename-noreplace"` after synchronizing the source and target parent
|
|
400
445
|
directories. Unlike the link/copy strategies, success consumes `sourcePath`.
|
|
401
446
|
|