@openclaw/feishu 2026.10.6 → 2026.10.8
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-DykAJJhn.mjs → channel-C6xKXhoV.mjs} +2 -2
- package/dist/.setup/{channel.runtime-CC15v8AP.mjs → channel.runtime-u62eAaRZ.mjs} +1 -1
- package/dist/.setup/{monitor-Cy9ofY1Q.mjs → monitor-BkQxhpUk.mjs} +1 -1
- package/dist/.setup/{monitor.account-UbN1RhlP.mjs → monitor.account-lTPltlCL.mjs} +19 -30
- package/dist/.setup/{setup-api-CRjDSHmn.mjs → setup-api-DfO9XC1M.mjs} +1 -1
- package/dist/.source-module-urls/6579f1b33dd01f8f0aaea28311ed6df1a635f9ad1e6fa86dcba53bca46407e55.json +1 -0
- package/dist/api.js +1 -1
- package/dist/channel-plugin-api.js +1 -1
- package/dist/setup-api.js +1 -1
- package/dist/setup-entry.js +1 -1
- package/node_modules/@openclaw/fs-safe/CHANGELOG.md +48 -0
- package/node_modules/@openclaw/fs-safe/README.md +14 -4
- package/node_modules/@openclaw/fs-safe/dist/archive-merge.js +28 -3
- package/node_modules/@openclaw/fs-safe/dist/archive-parser.wasm +0 -0
- package/node_modules/@openclaw/fs-safe/dist/archive-read.js +11 -5
- package/node_modules/@openclaw/fs-safe/dist/archive-zip-loader.js +4 -2
- package/node_modules/@openclaw/fs-safe/dist/archive.js +2 -2
- package/node_modules/@openclaw/fs-safe/dist/clone-metadata.js +1 -1
- package/node_modules/@openclaw/fs-safe/dist/copy-file-input.d.ts +2 -0
- package/node_modules/@openclaw/fs-safe/dist/copy-file-input.js +4 -3
- package/node_modules/@openclaw/fs-safe/dist/copy-link.d.ts +26 -0
- package/node_modules/@openclaw/fs-safe/dist/copy-link.js +169 -0
- package/node_modules/@openclaw/fs-safe/dist/copy-metadata.d.ts +9 -0
- package/node_modules/@openclaw/fs-safe/dist/copy-metadata.js +39 -0
- package/node_modules/@openclaw/fs-safe/dist/copy-root-file-sync.js +1 -1
- package/node_modules/@openclaw/fs-safe/dist/copy-tree-portable.js +3 -6
- package/node_modules/@openclaw/fs-safe/dist/copy.js +3 -3
- package/node_modules/@openclaw/fs-safe/dist/darwin-acl.d.ts +12 -0
- package/node_modules/@openclaw/fs-safe/dist/darwin-acl.js +29 -0
- package/node_modules/@openclaw/fs-safe/dist/directory-mode-node.d.ts +3 -0
- package/node_modules/@openclaw/fs-safe/dist/directory-mode-node.js +27 -2
- package/node_modules/@openclaw/fs-safe/dist/entry-publication.js +1 -1
- package/node_modules/@openclaw/fs-safe/dist/file-handle-transfer.js +4 -2
- package/node_modules/@openclaw/fs-safe/dist/file-hash.js +4 -3
- package/node_modules/@openclaw/fs-safe/dist/file-lock.d.ts +1 -0
- package/node_modules/@openclaw/fs-safe/dist/file-lock.js +1 -0
- package/node_modules/@openclaw/fs-safe/dist/file-write-lease.d.ts +9 -0
- package/node_modules/@openclaw/fs-safe/dist/file-write-lease.js +42 -0
- package/node_modules/@openclaw/fs-safe/dist/guest-native-python.js +3 -0
- package/node_modules/@openclaw/fs-safe/dist/hardlink-fallback.d.ts +1 -0
- package/node_modules/@openclaw/fs-safe/dist/hardlink-fallback.js +5 -0
- package/node_modules/@openclaw/fs-safe/dist/json-durable-queue-ownership.js +16 -3
- package/node_modules/@openclaw/fs-safe/dist/native-binding.d.ts +57 -18
- package/node_modules/@openclaw/fs-safe/dist/native-directory-observation.js +1 -1
- package/node_modules/@openclaw/fs-safe/dist/native-move-fallback.d.ts +1 -1
- package/node_modules/@openclaw/fs-safe/dist/native-move-fallback.js +2 -0
- package/node_modules/@openclaw/fs-safe/dist/native-operations.js +1 -1
- package/node_modules/@openclaw/fs-safe/dist/native-parent-admission.d.ts +1 -1
- package/node_modules/@openclaw/fs-safe/dist/native-parent-admission.js +2 -0
- package/node_modules/@openclaw/fs-safe/dist/native-pinned-write-windows.d.ts +1 -1
- package/node_modules/@openclaw/fs-safe/dist/native-pinned-write-windows.js +19 -1
- package/node_modules/@openclaw/fs-safe/dist/native-pinned-write.d.ts +4 -1
- package/node_modules/@openclaw/fs-safe/dist/native-pinned-write.js +18 -0
- package/node_modules/@openclaw/fs-safe/dist/native-policy-parent.d.ts +1 -1
- package/node_modules/@openclaw/fs-safe/dist/native-policy-parent.js +3 -0
- 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 +3 -0
- package/node_modules/@openclaw/fs-safe/dist/native.d.ts +5 -3
- package/node_modules/@openclaw/fs-safe/dist/native.js +25 -6
- package/node_modules/@openclaw/fs-safe/dist/opened-realpath.js +9 -1
- package/node_modules/@openclaw/fs-safe/dist/overwrite-file-handle.js +4 -1
- package/node_modules/@openclaw/fs-safe/dist/permissions-public.d.ts +1 -0
- package/node_modules/@openclaw/fs-safe/dist/permissions-public.js +1 -0
- package/node_modules/@openclaw/fs-safe/dist/permissions-windows.js +36 -47
- package/node_modules/@openclaw/fs-safe/dist/pinned-write-input.js +2 -0
- package/node_modules/@openclaw/fs-safe/dist/pinned-write-staged.js +3 -0
- package/node_modules/@openclaw/fs-safe/dist/pinned-write-types.d.ts +2 -1
- package/node_modules/@openclaw/fs-safe/dist/pinned-write.js +5 -3
- package/node_modules/@openclaw/fs-safe/dist/pipe.d.ts +9 -0
- package/node_modules/@openclaw/fs-safe/dist/pipe.js +26 -0
- package/node_modules/@openclaw/fs-safe/dist/private-producer-handoff.js +2 -5
- package/node_modules/@openclaw/fs-safe/dist/publish-copy-stage.js +92 -10
- package/node_modules/@openclaw/fs-safe/dist/publish-file.d.ts +1 -1
- package/node_modules/@openclaw/fs-safe/dist/publish-file.js +12 -11
- package/node_modules/@openclaw/fs-safe/dist/root-copy.d.ts +18 -0
- package/node_modules/@openclaw/fs-safe/dist/root-copy.js +128 -0
- package/node_modules/@openclaw/fs-safe/dist/root-create-native.js +12 -4
- package/node_modules/@openclaw/fs-safe/dist/root-impl.js +6 -92
- package/node_modules/@openclaw/fs-safe/dist/root-move-noreplace.js +1 -1
- package/node_modules/@openclaw/fs-safe/dist/root-options.d.ts +2 -0
- package/node_modules/@openclaw/fs-safe/dist/root-remove-native.js +8 -1
- package/node_modules/@openclaw/fs-safe/dist/sibling-staged-file.js +1 -1
- package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-retained.js +1 -1
- package/node_modules/@openclaw/fs-safe/dist/sidecar-lock-target.js +8 -1
- package/node_modules/@openclaw/fs-safe/dist/test-hooks.d.ts +1 -0
- package/node_modules/@openclaw/fs-safe/dist/test-hooks.js +1 -0
- package/node_modules/@openclaw/fs-safe/dist/watch-native.js +2 -2
- package/node_modules/@openclaw/fs-safe/dist/windows-security-bridge.cs +11 -5
- package/node_modules/@openclaw/fs-safe/dist/windows-security-command.js +9 -1
- package/node_modules/@openclaw/fs-safe/dist/windows-test-hooks.d.ts +16 -0
- package/node_modules/@openclaw/fs-safe/dist/windows-test-hooks.js +51 -0
- package/node_modules/@openclaw/fs-safe/docs/archive.md +16 -0
- package/node_modules/@openclaw/fs-safe/docs/contributing.md +35 -5
- package/node_modules/@openclaw/fs-safe/docs/copy.md +22 -0
- package/node_modules/@openclaw/fs-safe/docs/durability.md +4 -2
- package/node_modules/@openclaw/fs-safe/docs/errors.md +8 -0
- package/node_modules/@openclaw/fs-safe/docs/guest.md +2 -0
- package/node_modules/@openclaw/fs-safe/docs/install.md +13 -5
- package/node_modules/@openclaw/fs-safe/docs/migrating-to-0.5.md +5 -5
- package/node_modules/@openclaw/fs-safe/docs/native-helper.md +15 -5
- package/node_modules/@openclaw/fs-safe/docs/native.md +51 -2
- package/node_modules/@openclaw/fs-safe/docs/pipe.md +81 -0
- package/node_modules/@openclaw/fs-safe/docs/platform-capabilities.md +63 -0
- package/node_modules/@openclaw/fs-safe/docs/quickstart.md +23 -3
- package/node_modules/@openclaw/fs-safe/docs/reading.md +7 -1
- package/node_modules/@openclaw/fs-safe/docs/secret-file.md +5 -5
- package/node_modules/@openclaw/fs-safe/docs/sidecar-lock.md +31 -13
- package/node_modules/@openclaw/fs-safe/docs/store.md +11 -0
- package/node_modules/@openclaw/fs-safe/docs/types.md +45 -80
- package/node_modules/@openclaw/fs-safe/docs/writing.md +121 -14
- package/node_modules/@openclaw/fs-safe/package.json +18 -10
- package/node_modules/@openclaw/fs-safe-darwin-arm64/fs-safe-native.node +0 -0
- package/node_modules/@openclaw/fs-safe-darwin-arm64/package.json +1 -1
- package/node_modules/@openclaw/fs-safe-darwin-x64/fs-safe-native.node +0 -0
- package/node_modules/@openclaw/fs-safe-darwin-x64/package.json +1 -1
- package/node_modules/@openclaw/fs-safe-freebsd-arm64/fs-safe-native.node +0 -0
- package/node_modules/@openclaw/fs-safe-freebsd-arm64/package.json +29 -0
- package/node_modules/@openclaw/fs-safe-freebsd-x64/fs-safe-native.node +0 -0
- package/node_modules/@openclaw/fs-safe-freebsd-x64/package.json +29 -0
- package/node_modules/@openclaw/fs-safe-linux-arm64-gnu/fs-safe-native.node +0 -0
- package/node_modules/@openclaw/fs-safe-linux-arm64-gnu/package.json +1 -1
- package/node_modules/@openclaw/fs-safe-linux-arm64-musl/fs-safe-native.node +0 -0
- package/node_modules/@openclaw/fs-safe-linux-arm64-musl/package.json +1 -1
- package/node_modules/@openclaw/fs-safe-linux-x64-gnu/fs-safe-native.node +0 -0
- package/node_modules/@openclaw/fs-safe-linux-x64-gnu/package.json +1 -1
- package/node_modules/@openclaw/fs-safe-linux-x64-musl/fs-safe-native.node +0 -0
- package/node_modules/@openclaw/fs-safe-linux-x64-musl/package.json +1 -1
- package/node_modules/@openclaw/fs-safe-win32-arm64-msvc/fs-safe-native.node +0 -0
- package/node_modules/@openclaw/fs-safe-win32-arm64-msvc/package.json +29 -0
- 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
|
@@ -40,30 +40,25 @@ const normalize = (value) => normalizeLowercaseStringOrEmpty(value);
|
|
|
40
40
|
const defaultWindowsUserInfo = () => os.userInfo();
|
|
41
41
|
const defaultPermissionExec = executePermissionCommand;
|
|
42
42
|
function inspectWindowsPermissionsNative(targetPath, unverified) {
|
|
43
|
-
const native = getNativeBinding();
|
|
43
|
+
const native = getNativeBinding("readOwnerAndDacl");
|
|
44
44
|
if (!native)
|
|
45
45
|
return undefined;
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
if (facts.fallbackRequired)
|
|
49
|
-
return undefined;
|
|
50
|
-
return {
|
|
51
|
-
...unverified,
|
|
52
|
-
source: "windows-acl",
|
|
53
|
-
worldWritable: facts.worldWritable,
|
|
54
|
-
groupWritable: facts.groupWritable,
|
|
55
|
-
worldReadable: facts.worldReadable,
|
|
56
|
-
groupReadable: facts.groupReadable,
|
|
57
|
-
ownerSid: facts.ownerSid,
|
|
58
|
-
ownerTrusted: facts.ownerClass !== "foreign",
|
|
59
|
-
aclSummary: `native owner=${facts.ownerClass} world=` +
|
|
60
|
-
`${facts.worldReadable ? "r" : "-"}${facts.worldWritable ? "w" : "-"} ` +
|
|
61
|
-
`group=${facts.groupReadable ? "r" : "-"}${facts.groupWritable ? "w" : "-"}`,
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
catch {
|
|
46
|
+
const facts = native.readOwnerAndDacl(targetPath);
|
|
47
|
+
if (facts.fallbackRequired)
|
|
65
48
|
return undefined;
|
|
66
|
-
|
|
49
|
+
return {
|
|
50
|
+
...unverified,
|
|
51
|
+
source: "windows-acl",
|
|
52
|
+
worldWritable: facts.worldWritable,
|
|
53
|
+
groupWritable: facts.groupWritable,
|
|
54
|
+
worldReadable: facts.worldReadable,
|
|
55
|
+
groupReadable: facts.groupReadable,
|
|
56
|
+
ownerSid: facts.ownerSid,
|
|
57
|
+
ownerTrusted: facts.ownerClass !== "foreign",
|
|
58
|
+
aclSummary: `native owner=${facts.ownerClass} world=` +
|
|
59
|
+
`${facts.worldReadable ? "r" : "-"}${facts.worldWritable ? "w" : "-"} ` +
|
|
60
|
+
`group=${facts.groupReadable ? "r" : "-"}${facts.groupWritable ? "w" : "-"}`,
|
|
61
|
+
};
|
|
67
62
|
}
|
|
68
63
|
export async function inspectWindowsPermissions(targetPath, unverified, opts) {
|
|
69
64
|
if (hasWindowsPathAlias(targetPath, "filesystem", "win32")) {
|
|
@@ -263,32 +258,26 @@ export async function inspectWindowsAcl(targetPath, opts) {
|
|
|
263
258
|
}
|
|
264
259
|
let owner;
|
|
265
260
|
if (process.platform === "win32" && opts?.env === undefined && opts?.exec === undefined) {
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
};
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
catch {
|
|
290
|
-
// Preserve this inspector's structured fallback and command diagnostics
|
|
291
|
-
// when the optional helper or native descriptor query is unavailable.
|
|
261
|
+
const native = getNativeBinding("readOwnerAndDacl");
|
|
262
|
+
const stat = native && await safeStat(targetPath);
|
|
263
|
+
// Keep the named-query behavior for leaf links; the native reader follows them.
|
|
264
|
+
const facts = stat?.ok && !stat.isSymlink ? native?.readOwnerAndDacl(targetPath) : undefined;
|
|
265
|
+
if (facts && !facts.fallbackRequired && facts.isLocal && facts.aceListComplete && facts.unsupportedAceTypes.length === 0 &&
|
|
266
|
+
facts.aces.every(ace => ace.flags.inherited && ace.mask !== 0)) {
|
|
267
|
+
// .NET normalizes explicit ACEs, but retains nonzero inherited ACEs in
|
|
268
|
+
// their original order without merging them. Other forms keep its query.
|
|
269
|
+
// Adapt descriptor facts only: the public summary owns its SID and rights
|
|
270
|
+
// classification, which differs from the native secure-read policy.
|
|
271
|
+
owner = {
|
|
272
|
+
daclPresent: facts.daclPresent,
|
|
273
|
+
currentUserSid: facts.currentUserSid,
|
|
274
|
+
aces: facts.aces.map(ace => ({
|
|
275
|
+
sid: ace.sid,
|
|
276
|
+
mask: ace.mask,
|
|
277
|
+
deny: ace.aceType === "deny",
|
|
278
|
+
inheritOnly: ace.flags.inheritOnly,
|
|
279
|
+
})),
|
|
280
|
+
};
|
|
292
281
|
}
|
|
293
282
|
}
|
|
294
283
|
owner ??= await inspectWindowsOwner({ targetPath, env: opts?.env, exec: opts?.exec ?? defaultPermissionExec });
|
|
@@ -29,6 +29,8 @@ function streamChunkBytes(chunk) {
|
|
|
29
29
|
return snapshotByteView(chunk);
|
|
30
30
|
}
|
|
31
31
|
export async function writePinnedInput(target, input, maxBytes, assertBeforeMutation) {
|
|
32
|
+
if (input.kind === "link")
|
|
33
|
+
throw new FsSafeError("helper-failed", "link copying requires the link publication path");
|
|
32
34
|
if (input.kind === "file") {
|
|
33
35
|
await writeCopyFileToFd(typeof target === "number" ? target : target.fd, input, maxBytes, assertBeforeMutation);
|
|
34
36
|
return;
|
|
@@ -18,6 +18,7 @@ import { cleanupPinnedFilePath } from "./file-cleanup.js";
|
|
|
18
18
|
import { assertFinalSymlinkRejected } from "./root-symlink-policy.js";
|
|
19
19
|
import { createStagedFileReceipt, settleStagedFile } from "./staged-file-settlement.js";
|
|
20
20
|
import { getFsSafeTestHooks } from "./test-hooks.js";
|
|
21
|
+
import { restoreCopyMetadata } from "./copy-metadata.js";
|
|
21
22
|
export async function runPinnedStagedWrite(params, parentPath, parentGuard) {
|
|
22
23
|
const verifyPosixMode = process.platform !== "win32" &&
|
|
23
24
|
(params.verifyPosixMode === true || params.private === true);
|
|
@@ -66,6 +67,8 @@ export async function runPinnedStagedWrite(params, parentPath, parentGuard) {
|
|
|
66
67
|
}
|
|
67
68
|
const expectedTempStat = tempStat;
|
|
68
69
|
await handle.chmod(params.mode);
|
|
70
|
+
if (params.input.kind === "file")
|
|
71
|
+
restoreCopyMetadata(handle.fd, params.input.metadata);
|
|
69
72
|
if (verifyPosixMode) {
|
|
70
73
|
assertPinnedWriteMode(handle.fd, params.mode, params.private);
|
|
71
74
|
assertBeforeMutation = pinnedWriteModeAssertion(handle.fd, params.mode, params.assertBeforeMutation, params.private);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { CopyFileInput } from "./copy-file-input.js";
|
|
2
|
+
import type { CopyLinkInput } from "./copy-link.js";
|
|
2
3
|
import type { AnyAsyncDirectoryGuard } from "./directory-guard.js";
|
|
3
4
|
import type { FileIdentityStat } from "./file-identity.js";
|
|
4
5
|
import type { MutationDirectoryObservation } from "./pinned-mutation-observation.js";
|
|
@@ -16,7 +17,7 @@ export type PinnedWriteInput = {
|
|
|
16
17
|
kind: "stream";
|
|
17
18
|
stream: AsyncIterable<Uint8Array | string>;
|
|
18
19
|
stageBeforePublish?: boolean;
|
|
19
|
-
} | CopyFileInput;
|
|
20
|
+
} | CopyFileInput | CopyLinkInput;
|
|
20
21
|
export type RenameIdentityPolicy = "strict" | "verify-content-with-lock";
|
|
21
22
|
export type PublishedWriteIdentity = Readonly<{
|
|
22
23
|
dev: bigint;
|
|
@@ -12,8 +12,7 @@ import { syncDirectoryBestEffort } from "./directory-durability.js";
|
|
|
12
12
|
import { sha256Hex } from "./file-identity.js";
|
|
13
13
|
import { withAsyncDirectoryGuards } from "./guarded-mutation.js";
|
|
14
14
|
import { mkdirPathComponentsWithGuards } from "./guarded-mkdir.js";
|
|
15
|
-
import { runPinnedWriteNative } from "./native-pinned-write.js";
|
|
16
|
-
import { getNativeBinding } from "./native.js";
|
|
15
|
+
import { getPinnedWriteNativeBinding, runPinnedWriteNative } from "./native-pinned-write.js";
|
|
17
16
|
import { validatePinnedRelativePath } from "./pinned-operation.js";
|
|
18
17
|
import { cleanupPinnedFilePath } from "./file-cleanup.js";
|
|
19
18
|
import { withSidecarLock } from "./sidecar-lock.js";
|
|
@@ -23,6 +22,7 @@ import { assertPinnedWriteMode, preparePinnedWriteMode } from "./pinned-write-mo
|
|
|
23
22
|
import { runPinnedStagedWrite } from "./pinned-write-staged.js";
|
|
24
23
|
import { assertFinalSymlinkRejected } from "./root-symlink-policy.js";
|
|
25
24
|
import { assertNoWindowsPathAlias } from "./windows-path-alias.js";
|
|
25
|
+
import { copyLinkAtParent } from "./copy-link.js";
|
|
26
26
|
function assertSafeBasename(basename) {
|
|
27
27
|
if (!basename ||
|
|
28
28
|
basename === "." ||
|
|
@@ -88,7 +88,7 @@ export async function runPinnedWriteHelper(params) {
|
|
|
88
88
|
if (normalizedParams.onRenameIdentityMismatch === "verify-content") {
|
|
89
89
|
return await runPinnedWriteFallback(normalizedParams);
|
|
90
90
|
}
|
|
91
|
-
const native =
|
|
91
|
+
const native = getPinnedWriteNativeBinding(normalizedParams);
|
|
92
92
|
if (native) {
|
|
93
93
|
return await runPinnedWriteNative(native, normalizedParams, input => runPinnedWriteFallback({ ...normalizedParams, input }));
|
|
94
94
|
}
|
|
@@ -225,6 +225,8 @@ async function runPinnedWriteFallback(params) {
|
|
|
225
225
|
}));
|
|
226
226
|
await assertAsyncDirectoryGuard(parentGuard);
|
|
227
227
|
}
|
|
228
|
+
if (params.input.kind === "link")
|
|
229
|
+
return await copyLinkAtParent(params, params.input, parentGuard);
|
|
228
230
|
if (params.overwrite === false && params.input.kind !== "file" && !params.input.stageBeforePublish) {
|
|
229
231
|
const assertBeforeMutation = () => {
|
|
230
232
|
assertFinalSymlinkRejected(targetPath, params.rejectFinalSymlink);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type OwnedFileDescriptorSync } from "./create-owned-file.js";
|
|
2
|
+
export type OwnedPipeSync = {
|
|
3
|
+
readonly reader: OwnedFileDescriptorSync;
|
|
4
|
+
readonly writer: OwnedFileDescriptorSync;
|
|
5
|
+
/** True when close-on-exec was set atomically at creation. */
|
|
6
|
+
readonly atomicCloseOnExec: boolean;
|
|
7
|
+
};
|
|
8
|
+
/** Creates a POSIX anonymous pipe with two native-owned, close-on-exec ends. */
|
|
9
|
+
export declare function createPipe(): OwnedPipeSync;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ownFileDescriptorSync } from "./create-owned-file.js";
|
|
2
|
+
import { FsSafeError } from "./errors.js";
|
|
3
|
+
import { captureNativeFdClose } from "./native-binding.js";
|
|
4
|
+
import { requireNativeBinding } from "./native.js";
|
|
5
|
+
/** Creates a POSIX anonymous pipe with two native-owned, close-on-exec ends. */
|
|
6
|
+
export function createPipe() {
|
|
7
|
+
if (!["linux", "darwin", "freebsd"].includes(process.platform)) {
|
|
8
|
+
throw new FsSafeError("unsupported-platform", "anonymous pipes require Linux, Darwin, or FreeBSD");
|
|
9
|
+
}
|
|
10
|
+
const native = requireNativeBinding();
|
|
11
|
+
if (!native.createPipe) {
|
|
12
|
+
throw new FsSafeError("helper-unavailable", "native anonymous pipes are unavailable");
|
|
13
|
+
}
|
|
14
|
+
const close = captureNativeFdClose(native);
|
|
15
|
+
try {
|
|
16
|
+
const { reader, writer, atomicCloseOnExec } = native.createPipe();
|
|
17
|
+
return Object.freeze({
|
|
18
|
+
reader: ownFileDescriptorSync(reader, close),
|
|
19
|
+
writer: ownFileDescriptorSync(writer, close),
|
|
20
|
+
atomicCloseOnExec,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
catch (cause) {
|
|
24
|
+
throw new FsSafeError("helper-failed", "anonymous pipe creation failed", { cause });
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -2,6 +2,7 @@ import fsSync, {} from "node:fs";
|
|
|
2
2
|
import fs, {} from "node:fs/promises";
|
|
3
3
|
import { FsSafeError } from "./errors.js";
|
|
4
4
|
import { sameFileIdentityForCleanup } from "./file-identity.js";
|
|
5
|
+
import { isHardlinkFallbackError } from "./hardlink-fallback.js";
|
|
5
6
|
import { assertSynchronousCallbackResult } from "./mutation-authority.js";
|
|
6
7
|
import { resolveReadOpenFlags } from "./read-open-flags.js";
|
|
7
8
|
import { errorCauseOptions } from "./root-errors.js";
|
|
@@ -39,11 +40,7 @@ export function normalizeLinkError(error) {
|
|
|
39
40
|
if (code === "EEXIST") {
|
|
40
41
|
return new FsSafeError("already-exists", "isolated producer sibling already exists", errorCauseOptions(error));
|
|
41
42
|
}
|
|
42
|
-
if (
|
|
43
|
-
code === "ENOSYS" ||
|
|
44
|
-
code === "ENOTSUP" ||
|
|
45
|
-
code === "EOPNOTSUPP" ||
|
|
46
|
-
code === "EPERM") {
|
|
43
|
+
if (isHardlinkFallbackError(error)) {
|
|
47
44
|
return new FsSafeError("helper-unavailable", "atomic isolated producer handoff is unavailable", errorCauseOptions(error));
|
|
48
45
|
}
|
|
49
46
|
return error;
|
|
@@ -2,7 +2,10 @@ import fs, {} from "node:fs";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { assertSyncDirectoryGuard } from "./directory-guard.js";
|
|
4
4
|
import { FsSafeError } from "./errors.js";
|
|
5
|
+
import { assertExclusiveCreateLeaf } from "./exclusive-create.js";
|
|
5
6
|
import { sameFileIdentityForCleanup } from "./file-identity.js";
|
|
7
|
+
import { hasErrorCode } from "./file-cleanup.js";
|
|
8
|
+
import { isHardlinkFallbackError } from "./hardlink-fallback.js";
|
|
6
9
|
// Node has no portable no-replace rename. Publish the completed stage by link,
|
|
7
10
|
// then remove its verified temporary name without yielding.
|
|
8
11
|
export function publishCopyStage(params) {
|
|
@@ -27,7 +30,16 @@ export function publishCopyStage(params) {
|
|
|
27
30
|
throw new FsSafeError("already-exists", "destination already exists");
|
|
28
31
|
}
|
|
29
32
|
params.onPublicationAttempt?.();
|
|
30
|
-
|
|
33
|
+
let renamed = false;
|
|
34
|
+
try {
|
|
35
|
+
fs.linkSync(temporaryPath, targetPath);
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
if (!isHardlinkFallbackError(error))
|
|
39
|
+
throw error;
|
|
40
|
+
publishThroughPlaceholder(params, assertCurrent);
|
|
41
|
+
renamed = true;
|
|
42
|
+
}
|
|
31
43
|
let observerRejected = false;
|
|
32
44
|
let observerError;
|
|
33
45
|
try {
|
|
@@ -38,16 +50,29 @@ export function publishCopyStage(params) {
|
|
|
38
50
|
observerError = error;
|
|
39
51
|
}
|
|
40
52
|
try {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
53
|
+
if (renamed) {
|
|
54
|
+
assertSyncDirectoryGuard(params.parentGuard);
|
|
55
|
+
if (fs.lstatSync(temporaryPath, { throwIfNoEntry: false })) {
|
|
56
|
+
throw new FsSafeError("path-mismatch", "renamed copy stage still exists");
|
|
57
|
+
}
|
|
58
|
+
const target = fs.lstatSync(targetPath, { bigint: true });
|
|
59
|
+
if (!target.isFile() || target.isSymbolicLink() || target.nlink !== 1n ||
|
|
60
|
+
!sameFileIdentityForCleanup(target, identity)) {
|
|
61
|
+
throw new FsSafeError("path-mismatch", "renamed copy target changed after publication");
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
const parent = fs.lstatSync(path.dirname(temporaryPath), { bigint: true });
|
|
66
|
+
const current = fs.lstatSync(temporaryPath, { bigint: true });
|
|
67
|
+
if (parent.isSymbolicLink() || !parent.isDirectory() ||
|
|
68
|
+
!sameFileIdentityForCleanup(parent, params.parentGuard.stat) ||
|
|
69
|
+
current.isSymbolicLink() || !current.isFile() ||
|
|
70
|
+
!sameFileIdentityForCleanup(current, identity)) {
|
|
71
|
+
throw new FsSafeError("path-mismatch", "published copy temporary name changed before cleanup");
|
|
72
|
+
}
|
|
73
|
+
// This removes the stage's name, never the published destination or source.
|
|
74
|
+
fs.unlinkSync(temporaryPath);
|
|
48
75
|
}
|
|
49
|
-
// This removes the stage's name, never the published destination or source.
|
|
50
|
-
fs.unlinkSync(temporaryPath);
|
|
51
76
|
}
|
|
52
77
|
catch (error) {
|
|
53
78
|
throw new FsSafeError("helper-failed", "published copy temporary cleanup failed", {
|
|
@@ -58,3 +83,60 @@ export function publishCopyStage(params) {
|
|
|
58
83
|
if (observerRejected)
|
|
59
84
|
throw observerError;
|
|
60
85
|
}
|
|
86
|
+
function isEmptyPlaceholder(current, identity) {
|
|
87
|
+
return current.isFile() && !current.isSymbolicLink() && current.nlink === 1n &&
|
|
88
|
+
current.size === 0n && sameFileIdentityForCleanup(current, identity);
|
|
89
|
+
}
|
|
90
|
+
function publishThroughPlaceholder(params, assertCurrent) {
|
|
91
|
+
const { targetPath, temporaryPath } = params;
|
|
92
|
+
// An empty placeholder can be observed before the completed stage atomically replaces it.
|
|
93
|
+
// The stage proved directory write access; a real permission denial still fails O_EXCL.
|
|
94
|
+
assertCurrent();
|
|
95
|
+
let fd;
|
|
96
|
+
try {
|
|
97
|
+
assertExclusiveCreateLeaf(targetPath);
|
|
98
|
+
fd = fs.openSync(targetPath, fs.constants.O_WRONLY | fs.constants.O_CREAT |
|
|
99
|
+
fs.constants.O_EXCL | (fs.constants.O_NOFOLLOW ?? 0), 0o600);
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
if (hasErrorCode(error, "EEXIST")) {
|
|
103
|
+
throw new FsSafeError("already-exists", "destination already exists", { cause: error });
|
|
104
|
+
}
|
|
105
|
+
throw error;
|
|
106
|
+
}
|
|
107
|
+
let placeholder;
|
|
108
|
+
try {
|
|
109
|
+
try {
|
|
110
|
+
placeholder = fs.fstatSync(fd, { bigint: true });
|
|
111
|
+
}
|
|
112
|
+
finally {
|
|
113
|
+
fs.closeSync(fd);
|
|
114
|
+
}
|
|
115
|
+
assertCurrent();
|
|
116
|
+
const current = fs.lstatSync(targetPath, { bigint: true, throwIfNoEntry: false });
|
|
117
|
+
if (!current || !isEmptyPlaceholder(current, placeholder)) {
|
|
118
|
+
throw new FsSafeError("path-mismatch", "exclusive copy placeholder changed before publication");
|
|
119
|
+
}
|
|
120
|
+
fs.renameSync(temporaryPath, targetPath);
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
try {
|
|
124
|
+
assertSyncDirectoryGuard(params.parentGuard);
|
|
125
|
+
const current = fs.lstatSync(targetPath, { bigint: true, throwIfNoEntry: false });
|
|
126
|
+
if (current) {
|
|
127
|
+
if (!placeholder)
|
|
128
|
+
throw new FsSafeError("path-mismatch", "copy placeholder identity unavailable for cleanup");
|
|
129
|
+
if (isEmptyPlaceholder(current, placeholder))
|
|
130
|
+
fs.unlinkSync(targetPath);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
catch (cleanupError) {
|
|
134
|
+
throw new FsSafeError("helper-failed", "unpublished copy placeholder cleanup failed", {
|
|
135
|
+
cause: new AggregateError([error, cleanupError], "publication and cleanup failed"),
|
|
136
|
+
details: { publication: "not-published", path: targetPath, cleanup: "failed",
|
|
137
|
+
...(placeholder ? { dev: placeholder.dev, ino: placeholder.ino } : {}) },
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
throw error;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
@@ -2,6 +2,7 @@ import { type BigIntStats, type Stats } from "node:fs";
|
|
|
2
2
|
import { type DirectoryReceipt, type DirectorySyncOutcome } from "./directory-durability.js";
|
|
3
3
|
import { type FileIdentityStat } from "./file-identity.js";
|
|
4
4
|
import { type PublishFileExclusiveSyncFailurePolicy } from "./publish-file-failure.js";
|
|
5
|
+
export { isHardlinkFallbackError } from "./hardlink-fallback.js";
|
|
5
6
|
export type PublishFileExclusiveStrategy = "link-or-copy" | "link-required" | "rename-noreplace";
|
|
6
7
|
export type PublishFileExclusiveResult = {
|
|
7
8
|
method: "hardlink" | "exclusive-copy" | "rename-noreplace";
|
|
@@ -10,7 +11,6 @@ export type PublishFileExclusiveResult = {
|
|
|
10
11
|
identity: Stats;
|
|
11
12
|
directorySync: DirectorySyncOutcome;
|
|
12
13
|
};
|
|
13
|
-
export declare function isHardlinkFallbackError(error: unknown): boolean;
|
|
14
14
|
export declare function publishFileExclusive(params: {
|
|
15
15
|
sourcePath: string;
|
|
16
16
|
targetPath: string;
|
|
@@ -11,7 +11,7 @@ import { ownDirectoryReceipt } from "./directory-receipt.js";
|
|
|
11
11
|
import { hashFileHandle } from "./file-hash.js";
|
|
12
12
|
import { sameFileIdentity, sameFileIdentityForCleanup, } from "./file-identity.js";
|
|
13
13
|
import { syncFileBestEffortSync } from "./file-sync.js";
|
|
14
|
-
import { getNativeBinding, requireNativeBinding } from "./native.js";
|
|
14
|
+
import { getNativeBinding, requireNativeBinding, selectNativeBinding } from "./native.js";
|
|
15
15
|
import { captureNativeFdClose } from "./native-binding.js";
|
|
16
16
|
import { resolveReadOpenFlags } from "./read-open-flags.js";
|
|
17
17
|
import { directorySyncFailure, publicationFailure, rememberCreatedTarget, } from "./publish-file-failure.js";
|
|
@@ -19,11 +19,9 @@ import { admitStandalonePublicationPath, assertNoWindowsPathAlias } from "./wind
|
|
|
19
19
|
import { getFsSafeTestHooks } from "./test-hooks.js";
|
|
20
20
|
import { hasErrorCode } from "./file-cleanup.js";
|
|
21
21
|
import { writeAllToFile } from "./write-file-handle.js";
|
|
22
|
-
|
|
22
|
+
import { isHardlinkFallbackError } from "./hardlink-fallback.js";
|
|
23
|
+
export { isHardlinkFallbackError } from "./hardlink-fallback.js";
|
|
23
24
|
const NATIVE_COPY_FALLBACK_CODES = new Set(["EINVAL", "ENOSYS", "ENOTSUP", "EOPNOTSUPP", "EPERM", "EXDEV"]);
|
|
24
|
-
export function isHardlinkFallbackError(error) {
|
|
25
|
-
return HARDLINK_FALLBACK_CODES.has(error?.code ?? "");
|
|
26
|
-
}
|
|
27
25
|
function directoryOpenFlags() {
|
|
28
26
|
return (fsSync.constants.O_RDONLY |
|
|
29
27
|
(typeof fsSync.constants.O_DIRECTORY === "number" ? fsSync.constants.O_DIRECTORY : 0));
|
|
@@ -78,13 +76,16 @@ async function copyPinnedSource(params) {
|
|
|
78
76
|
if (params.native && params.targetNativeParent) {
|
|
79
77
|
const closeFd = captureNativeFdClose(params.native);
|
|
80
78
|
for (const method of ["clone", "copy-file-range"]) {
|
|
79
|
+
const native = selectNativeBinding(params.native, method === "clone" ? "cloneFileExclusive" : "copyFileRangeExclusive");
|
|
80
|
+
if (!native)
|
|
81
|
+
continue;
|
|
81
82
|
let nativeFd;
|
|
82
83
|
try {
|
|
83
84
|
if (method === "clone") {
|
|
84
|
-
nativeFd =
|
|
85
|
+
nativeFd = native.cloneFileExclusive(params.source.fd, params.targetNativeParent.handle.fd, params.targetNativeParent.basename);
|
|
85
86
|
}
|
|
86
87
|
else {
|
|
87
|
-
const copied = await
|
|
88
|
+
const copied = await native.copyFileRangeExclusive(params.source.fd, params.targetNativeParent.handle.fd, params.targetNativeParent.basename);
|
|
88
89
|
if (copied.errorCode) {
|
|
89
90
|
throw Object.assign(new Error(copied.errorMessage ?? "native copy failed"), {
|
|
90
91
|
code: copied.errorCode,
|
|
@@ -263,14 +264,14 @@ export async function publishFileExclusive(params) {
|
|
|
263
264
|
await parent.assertCurrent();
|
|
264
265
|
assertSourceCurrent();
|
|
265
266
|
const native = strategy === "rename-noreplace"
|
|
266
|
-
? requireNativeBinding()
|
|
267
|
-
: getNativeBinding();
|
|
267
|
+
? requireNativeBinding("renameNoReplace")
|
|
268
|
+
: getNativeBinding("linkBeneath");
|
|
268
269
|
if (native) {
|
|
269
270
|
sourceNativeParent = await openNativeParent(sourcePath);
|
|
270
271
|
targetNativeParent = await openNativeParent(targetPath);
|
|
271
272
|
}
|
|
272
273
|
if (strategy === "rename-noreplace") {
|
|
273
|
-
const binding = requireNativeBinding();
|
|
274
|
+
const binding = requireNativeBinding("renameNoReplace");
|
|
274
275
|
try {
|
|
275
276
|
const fallback = nativeMoveNoReplace(binding, [
|
|
276
277
|
sourceNativeParent.handle.fd, sourceNativeParent.basename,
|
|
@@ -313,7 +314,7 @@ export async function publishFileExclusive(params) {
|
|
|
313
314
|
return await finishPublication("rename-noreplace", source, sourceExactIdentity);
|
|
314
315
|
}
|
|
315
316
|
try {
|
|
316
|
-
if (native) {
|
|
317
|
+
if (native?.linkBeneath) {
|
|
317
318
|
native.linkBeneath(sourceNativeParent.handle.fd, sourceNativeParent.basename, targetNativeParent.handle.fd, targetNativeParent.basename);
|
|
318
319
|
}
|
|
319
320
|
else {
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type BigIntStats } from "node:fs";
|
|
2
|
+
import type { OpenResult } from "./root-impl.js";
|
|
3
|
+
import type { RootContext } from "./root-context.js";
|
|
4
|
+
import type { RootCopyOptions, RootCopySource, HardlinkPolicy } from "./root-options.js";
|
|
5
|
+
import { onCopyPublication, onCopySourceAdmission, type CopyPublicationOptions } from "./copy-publication.js";
|
|
6
|
+
type RootCopyParams = RootCopyOptions & {
|
|
7
|
+
source: RootCopySource;
|
|
8
|
+
relativePath: string;
|
|
9
|
+
verifyPublished?: CopyPublicationOptions[typeof onCopyPublication];
|
|
10
|
+
admitSource?: CopyPublicationOptions[typeof onCopySourceAdmission];
|
|
11
|
+
};
|
|
12
|
+
export declare function copyFileInRoot(root: RootContext, params: RootCopyParams, openVerifiedLocalFile: (path: string, options: {
|
|
13
|
+
hardlinks?: HardlinkPolicy;
|
|
14
|
+
}) => Promise<{
|
|
15
|
+
opened: OpenResult;
|
|
16
|
+
identity: BigIntStats;
|
|
17
|
+
}>): Promise<void>;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import fsSync, {} from "node:fs";
|
|
2
|
+
import { assertCopySourceCurrent, resolveFileCopyCloneMode } from "./copy-file-input.js";
|
|
3
|
+
import { resolveCopyCloneMode } from "./copy-policy.js";
|
|
4
|
+
import { captureCopyMetadata } from "./copy-metadata.js";
|
|
5
|
+
import { admitCopyLink, assertCopyLinkAvailable } from "./copy-link.js";
|
|
6
|
+
import { assertAbsolutePathInput } from "./absolute-path.js";
|
|
7
|
+
import { assertNoNulPathInput } from "./path.js";
|
|
8
|
+
import { assertNoWindowsPathAlias } from "./windows-path-alias.js";
|
|
9
|
+
import { inspectFileIdentity } from "./strict-file-identity.js";
|
|
10
|
+
import { MutationAuthorityError } from "./mutation-authority.js";
|
|
11
|
+
import { serializePathWrite } from "./write-queue.js";
|
|
12
|
+
import { rootWriteQueueKey } from "./root-create-native.js";
|
|
13
|
+
import { resolvePinnedWriteTargetInRoot } from "./root-write-admission.js";
|
|
14
|
+
import { createCopyPublicationObserver, onCopyPublication, onCopySourceAdmission } from "./copy-publication.js";
|
|
15
|
+
import { isAlreadyExistsError, normalizePinnedWriteError } from "./root-errors.js";
|
|
16
|
+
import { runPinnedWriteHelper } from "./pinned-write.js";
|
|
17
|
+
import { FsSafeError } from "./errors.js";
|
|
18
|
+
export async function copyFileInRoot(root, params, openVerifiedLocalFile) {
|
|
19
|
+
params.signal?.throwIfAborted();
|
|
20
|
+
resolveCopyCloneMode(params.clone, "never");
|
|
21
|
+
if (params.sourceSymlinks !== undefined && params.sourceSymlinks !== "reject" && params.sourceSymlinks !== "copy-link") {
|
|
22
|
+
throw new FsSafeError("invalid-path", "sourceSymlinks must be reject or copy-link");
|
|
23
|
+
}
|
|
24
|
+
if (params.sourceSymlinks === "copy-link") {
|
|
25
|
+
if (typeof params.source !== "string") {
|
|
26
|
+
throw new FsSafeError("invalid-path", "sourceSymlinks: copy-link requires an absolute-path string source; open/stat capabilities cannot observe links without following them");
|
|
27
|
+
}
|
|
28
|
+
const link = await admitCopyLink(assertAbsolutePathInput(params.source), params.preserveMetadata === true, params.signal)
|
|
29
|
+
.catch(error => { throw normalizePinnedWriteError(error); });
|
|
30
|
+
if (link) {
|
|
31
|
+
if (params.overwrite === true)
|
|
32
|
+
throw new FsSafeError("invalid-path", "copy-link cannot overwrite an existing destination; omit overwrite or use false");
|
|
33
|
+
assertCopyLinkAvailable();
|
|
34
|
+
const mode = params.mode ?? (params.preserveSourceMode ? Number(link.identity.mode & 4095n) : undefined);
|
|
35
|
+
await copyInputInRoot(root, { ...params, overwrite: false }, link, mode);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
const clone = resolveFileCopyCloneMode(params.clone);
|
|
40
|
+
let source;
|
|
41
|
+
let sourceIdentity;
|
|
42
|
+
if (typeof params.source === "string") {
|
|
43
|
+
assertNoNulPathInput(params.source, "source path contains a NUL byte");
|
|
44
|
+
assertNoWindowsPathAlias(params.source, "filesystem", "source path uses a Windows filesystem namespace alias");
|
|
45
|
+
({ opened: source, identity: sourceIdentity } = await openVerifiedLocalFile(params.source, {
|
|
46
|
+
hardlinks: params.sourceHardlinks,
|
|
47
|
+
}));
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
source = await params.source.root.open(params.source.relativePath, params.sourceHardlinks === undefined ? undefined : { hardlinks: params.sourceHardlinks });
|
|
51
|
+
try {
|
|
52
|
+
sourceIdentity = await inspectFileIdentity(() => fsSync.fstatSync(source.handle.fd, { bigint: true }));
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
await source.handle.close().catch(() => undefined);
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
try {
|
|
60
|
+
if (params.maxBytes !== undefined && source.stat.size > params.maxBytes) {
|
|
61
|
+
throw new FsSafeError("too-large", `file exceeds limit of ${params.maxBytes} bytes (got ${source.stat.size})`);
|
|
62
|
+
}
|
|
63
|
+
let metadata;
|
|
64
|
+
try {
|
|
65
|
+
metadata = params.preserveMetadata ? captureCopyMetadata(source.handle.fd, sourceIdentity) : undefined;
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
throw normalizePinnedWriteError(error);
|
|
69
|
+
}
|
|
70
|
+
const sourceAdmission = params.admitSource?.(sourceIdentity, source.realPath);
|
|
71
|
+
const verifySource = async () => {
|
|
72
|
+
params.signal?.throwIfAborted();
|
|
73
|
+
try {
|
|
74
|
+
sourceAdmission?.verify();
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
throw new MutationAuthorityError(error);
|
|
78
|
+
}
|
|
79
|
+
if (typeof params.source !== "string")
|
|
80
|
+
await params.source.root.stat(".");
|
|
81
|
+
await assertCopySourceCurrent(source, sourceIdentity);
|
|
82
|
+
};
|
|
83
|
+
const mode = sourceAdmission?.mode ?? params.mode ?? (params.preserveSourceMode ? Number(sourceIdentity.mode & 4095n) : undefined);
|
|
84
|
+
await copyInputInRoot(root, params, {
|
|
85
|
+
kind: "file", handle: source.handle, size: source.stat.size, clone,
|
|
86
|
+
signal: params.signal, metadata, verifySource,
|
|
87
|
+
}, mode, () => assertCopySourceCurrent(source, sourceIdentity));
|
|
88
|
+
}
|
|
89
|
+
finally {
|
|
90
|
+
await source.handle.close().catch(() => { });
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
async function copyInputInRoot(root, params, input, mode, verifyAdmission = input.verifySource) {
|
|
94
|
+
if (mode !== undefined && (!Number.isInteger(mode) || mode < 0 || mode > 0o7777)) {
|
|
95
|
+
throw new FsSafeError("invalid-path", "invalid copy mode");
|
|
96
|
+
}
|
|
97
|
+
await serializePathWrite(rootWriteQueueKey(root, params.relativePath), async () => {
|
|
98
|
+
const pinned = await resolvePinnedWriteTargetInRoot(root, params.relativePath, mode, params.denyMutations, params.overwrite !== false, params.mutationSymlinks);
|
|
99
|
+
await serializePathWrite(pinned.targetPath, async () => {
|
|
100
|
+
await verifyAdmission();
|
|
101
|
+
const observer = createCopyPublicationObserver(pinned.targetPath, params.onDestinationPublished);
|
|
102
|
+
try {
|
|
103
|
+
await runPinnedWriteHelper({
|
|
104
|
+
rootPath: pinned.rootReal, relativeParentPath: pinned.relativeParentPath, basename: pinned.basename,
|
|
105
|
+
mkdir: params.mkdir !== false, mode: pinned.mode, overwrite: params.overwrite !== false,
|
|
106
|
+
rejectFinalSymlink: params.mutationSymlinks !== undefined, maxBytes: params.maxBytes,
|
|
107
|
+
sync: params.durable !== false,
|
|
108
|
+
assertBeforeMutation: params.signal || params.assertBeforeMutation ? () => {
|
|
109
|
+
if (params.signal?.aborted)
|
|
110
|
+
throw new MutationAuthorityError(params.signal.reason);
|
|
111
|
+
params.assertBeforeMutation?.();
|
|
112
|
+
} : undefined,
|
|
113
|
+
verifyPublished: params.verifyPublished, onPublished: observer.onPublished, input,
|
|
114
|
+
rootIdentity: root.rootIdentity, mutationAdmission: pinned.mutationAdmission,
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
catch (error) {
|
|
118
|
+
observer.rethrowObserverFailure(error);
|
|
119
|
+
if (params.signal?.aborted && error === params.signal.reason)
|
|
120
|
+
throw error;
|
|
121
|
+
if (isAlreadyExistsError(error))
|
|
122
|
+
throw new FsSafeError("already-exists", "copy destination already exists", { cause: error });
|
|
123
|
+
throw normalizePinnedWriteError(error);
|
|
124
|
+
}
|
|
125
|
+
await input.verifySource();
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
}
|
|
@@ -63,10 +63,11 @@ import { getNativeBinding } from "./native.js";
|
|
|
63
63
|
import { captureNativeFdClose } from "./native-binding.js";
|
|
64
64
|
import { openNativeRootAdmission } from "./native-parent-admission.js";
|
|
65
65
|
import { capturePolicyAwareNativeParent } from "./native-policy-parent.js";
|
|
66
|
-
import { isNotFoundPathError, isPathInside } from "./path.js";
|
|
66
|
+
import { hasNodeErrorCode, isNotFoundPathError, isPathInside } from "./path.js";
|
|
67
67
|
import { preparePinnedWriteMutationAdmission } from "./pinned-mutation-admission.js";
|
|
68
68
|
import { resolvePathViaExistingAncestor } from "./root-path-existing.js";
|
|
69
69
|
import { admitPathInsideRoot } from "./root-boundary.js";
|
|
70
|
+
import { directoryComponentNotDirectoryError } from "./root-errors.js";
|
|
70
71
|
import { assertRootIdentityCurrentSync } from "./root-context.js";
|
|
71
72
|
import { inspectFileIdentitySync } from "./strict-file-identity.js";
|
|
72
73
|
import { getFsSafeTestHooks } from "./test-hooks.js";
|
|
@@ -81,7 +82,7 @@ function unavailable() {
|
|
|
81
82
|
throw new FsSafeError("helper-unavailable", "native confined creation is unavailable");
|
|
82
83
|
}
|
|
83
84
|
async function withNativeDirectory(params, operation, discard) {
|
|
84
|
-
const binding = getNativeBinding();
|
|
85
|
+
const binding = getNativeBinding("openBeneath", "mkdirChildBeneath");
|
|
85
86
|
if (!binding?.openBeneath || !binding.mkdirChildBeneath || (params.private && process.platform === "win32"))
|
|
86
87
|
return unavailable();
|
|
87
88
|
const directoryTarget = params.directory === params.target;
|
|
@@ -232,10 +233,17 @@ export async function tryMkdirRootNative(params) {
|
|
|
232
233
|
// and uses handle-relative NtCreateFile with its protected security descriptor.
|
|
233
234
|
if (params.private && process.platform === "win32")
|
|
234
235
|
return false;
|
|
235
|
-
|
|
236
|
+
try {
|
|
237
|
+
return await withNativeDirectory(params, async (_binding, _fd, assertCurrent) => { assertCurrent(); return true; });
|
|
238
|
+
}
|
|
239
|
+
catch (error) {
|
|
240
|
+
if (hasNodeErrorCode(error, "ENOTDIR"))
|
|
241
|
+
throw directoryComponentNotDirectoryError(error);
|
|
242
|
+
throw error;
|
|
243
|
+
}
|
|
236
244
|
}
|
|
237
245
|
export async function tryOpenCreateRootNative(params) {
|
|
238
|
-
const binding = getNativeBinding();
|
|
246
|
+
const binding = getNativeBinding("openBeneath", "mkdirChildBeneath", "removeStagedFile", "openCreateBeneath");
|
|
239
247
|
if (!binding?.removeStagedFile || !binding.openCreateBeneath)
|
|
240
248
|
return unavailable();
|
|
241
249
|
const access = (params.existingFlags & fs.constants.O_RDWR) ? 0o600 : 0o200;
|