@lousy-agents/agent-shell 5.21.6 → 5.21.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1394 -514
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { createRequire as __rspack_createRequire } from "node:module";
|
|
3
3
|
const __rspack_createRequire_require = __rspack_createRequire(import.meta.url);
|
|
4
4
|
var __webpack_modules__ = ({
|
|
5
|
-
|
|
5
|
+
446(__unused_rspack_module, __unused_rspack___webpack_exports__, __webpack_require__) {
|
|
6
6
|
|
|
7
7
|
;// CONCATENATED MODULE: external "node:child_process"
|
|
8
8
|
const external_node_child_process_namespaceObject = __rspack_createRequire_require("node:child_process");
|
|
@@ -113,7 +113,7 @@ function byte_budget_normalizeMaxBytes(value, options = {}) {
|
|
|
113
113
|
if (selected === undefined || selected === Number.POSITIVE_INFINITY)
|
|
114
114
|
return selected;
|
|
115
115
|
if (!Number.isSafeInteger(selected) || selected < 0) {
|
|
116
|
-
throw new RangeError(
|
|
116
|
+
throw new RangeError("maxBytes must be a non-negative safe integer or Infinity");
|
|
117
117
|
}
|
|
118
118
|
return selected;
|
|
119
119
|
}
|
|
@@ -132,7 +132,7 @@ function isStatValueProvablyDifferent(left, right, platform) {
|
|
|
132
132
|
}
|
|
133
133
|
return platform !== "win32" || (!isZero(left) && !isZero(right));
|
|
134
134
|
}
|
|
135
|
-
function
|
|
135
|
+
function file_identity_sha256Hex(data, encoding) {
|
|
136
136
|
const buffer = typeof data === "string" ? Buffer.from(data, encoding ?? "utf8") : data;
|
|
137
137
|
return (0,external_node_crypto_namespaceObject.createHash)("sha256").update(buffer).digest("hex");
|
|
138
138
|
}
|
|
@@ -143,7 +143,7 @@ function file_identity_sameFileIdentity(left, right, platform = process.platform
|
|
|
143
143
|
return (!isStatValueProvablyDifferent(left.dev, right.dev, platform) &&
|
|
144
144
|
!isStatValueProvablyDifferent(left.ino, right.ino, platform));
|
|
145
145
|
}
|
|
146
|
-
function
|
|
146
|
+
function file_identity_sameFileIdentityForCleanup(left, right, platform = process.platform) {
|
|
147
147
|
// A zero Windows device or inode is unknown, not proof that a pathname still
|
|
148
148
|
// names the object we created. Cleanup must fail closed rather than delete a
|
|
149
149
|
// replacement that happens to share the known half of the identity.
|
|
@@ -214,7 +214,7 @@ function identityCheck(expected, platform) {
|
|
|
214
214
|
}
|
|
215
215
|
// Retry only unknown Windows identities, retaining every known component so a
|
|
216
216
|
// later observation cannot erase a definite mismatch. Never reopen the file.
|
|
217
|
-
async function
|
|
217
|
+
async function strict_file_identity_inspectFileIdentity(inspect, expected, platform = process.platform) {
|
|
218
218
|
const check = identityCheck(expected, platform);
|
|
219
219
|
for (let attempt = 0; attempt < 2; attempt++) {
|
|
220
220
|
const stat = await inspect();
|
|
@@ -223,7 +223,7 @@ async function inspectFileIdentity(inspect, expected, platform = process.platfor
|
|
|
223
223
|
}
|
|
224
224
|
throw identityMismatch();
|
|
225
225
|
}
|
|
226
|
-
function
|
|
226
|
+
function strict_file_identity_inspectFileIdentitySync(inspect, expected, platform = process.platform) {
|
|
227
227
|
const check = identityCheck(expected, platform);
|
|
228
228
|
for (let attempt = 0; attempt < 2; attempt++) {
|
|
229
229
|
const stat = inspect();
|
|
@@ -254,11 +254,11 @@ function normalizeWindowsPathForComparison(input) {
|
|
|
254
254
|
// whitespace is part of the path and must not be trimmed away.
|
|
255
255
|
return normalized.replaceAll("/", "\\").toLowerCase();
|
|
256
256
|
}
|
|
257
|
-
function
|
|
257
|
+
function path_isNodeError(value) {
|
|
258
258
|
return Boolean(value && typeof value === "object" && "code" in value);
|
|
259
259
|
}
|
|
260
260
|
function hasNodeErrorCode(value, code) {
|
|
261
|
-
return
|
|
261
|
+
return path_isNodeError(value) && value.code === code;
|
|
262
262
|
}
|
|
263
263
|
function path_assertNoNulPathInput(filePath, message = "path contains a NUL byte") {
|
|
264
264
|
if (filePath.includes("\0")) {
|
|
@@ -266,10 +266,10 @@ function path_assertNoNulPathInput(filePath, message = "path contains a NUL byte
|
|
|
266
266
|
}
|
|
267
267
|
}
|
|
268
268
|
function path_isNotFoundPathError(value) {
|
|
269
|
-
return
|
|
269
|
+
return path_isNodeError(value) && typeof value.code === "string" && NOT_FOUND_CODES.has(value.code);
|
|
270
270
|
}
|
|
271
271
|
function isSymlinkOpenError(value) {
|
|
272
|
-
return
|
|
272
|
+
return path_isNodeError(value) && typeof value.code === "string" && SYMLINK_OPEN_CODES.has(value.code);
|
|
273
273
|
}
|
|
274
274
|
function path_isPathInside(root, target) {
|
|
275
275
|
if (process.platform === "win32") {
|
|
@@ -426,7 +426,7 @@ function normalizeRemovePathError(error) {
|
|
|
426
426
|
if (error instanceof errors_FsSafeError) {
|
|
427
427
|
return error;
|
|
428
428
|
}
|
|
429
|
-
if (!
|
|
429
|
+
if (!path_isNodeError(error) || typeof error.code !== "string") {
|
|
430
430
|
return normalizePinnedPathError(error);
|
|
431
431
|
}
|
|
432
432
|
const cause = error instanceof Error ? error : undefined;
|
|
@@ -438,6 +438,15 @@ function normalizeRemovePathError(error) {
|
|
|
438
438
|
}
|
|
439
439
|
return new errors_FsSafeError("not-removable", "path could not be removed", { cause });
|
|
440
440
|
}
|
|
441
|
+
function throwFsSafeReadError(error, label) {
|
|
442
|
+
if (error instanceof FsSafeError) {
|
|
443
|
+
throw error;
|
|
444
|
+
}
|
|
445
|
+
if (isNodeError(error)) {
|
|
446
|
+
throw new FsSafeError("read-failed", `${label} target could not be read`, { cause: error });
|
|
447
|
+
}
|
|
448
|
+
throw error;
|
|
449
|
+
}
|
|
441
450
|
|
|
442
451
|
;// CONCATENATED MODULE: ../../node_modules/@openclaw/fs-safe/dist/directory-guard.js
|
|
443
452
|
|
|
@@ -447,20 +456,21 @@ function normalizeRemovePathError(error) {
|
|
|
447
456
|
|
|
448
457
|
|
|
449
458
|
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
const stat = await promises_namespaceObject.lstat(dir);
|
|
459
|
+
async function directory_guard_createAsyncDirectoryGuard(dir, options) {
|
|
460
|
+
const stat = options?.bigint ? await inspectDirectoryIdentity(dir) : external_node_fs_namespaceObject.lstatSync(dir);
|
|
453
461
|
if (stat.isSymbolicLink() || !stat.isDirectory()) {
|
|
454
462
|
throw root_errors_directoryComponentNotDirectoryError();
|
|
455
463
|
}
|
|
456
|
-
return { dir, realPath:
|
|
464
|
+
return { dir, realPath: external_node_fs_namespaceObject.realpathSync.native(dir), stat };
|
|
457
465
|
}
|
|
458
|
-
async function
|
|
459
|
-
const stat =
|
|
466
|
+
async function directory_guard_assertAsyncDirectoryGuard(guard) {
|
|
467
|
+
const stat = typeof guard.stat.dev === "bigint" && typeof guard.stat.ino === "bigint"
|
|
468
|
+
? await inspectDirectoryIdentity(guard.dir, { dev: guard.stat.dev, ino: guard.stat.ino })
|
|
469
|
+
: external_node_fs_namespaceObject.lstatSync(guard.dir);
|
|
460
470
|
if (stat.isSymbolicLink() || !stat.isDirectory()) {
|
|
461
471
|
throw root_errors_directoryComponentNotDirectoryError();
|
|
462
472
|
}
|
|
463
|
-
if (!file_identity_sameFileIdentity(stat, guard.stat) ||
|
|
473
|
+
if (!file_identity_sameFileIdentity(stat, guard.stat) || external_node_fs_namespaceObject.realpathSync.native(guard.dir) !== guard.realPath) {
|
|
464
474
|
throw new errors_FsSafeError("path-mismatch", "directory changed during operation");
|
|
465
475
|
}
|
|
466
476
|
}
|
|
@@ -480,12 +490,12 @@ function directory_guard_assertSyncDirectoryGuard(guard) {
|
|
|
480
490
|
throw new FsSafeError("path-mismatch", "directory changed during operation");
|
|
481
491
|
}
|
|
482
492
|
}
|
|
483
|
-
async function directory_guard_createNearestExistingDirectoryGuard(rootReal, targetPath) {
|
|
493
|
+
async function directory_guard_createNearestExistingDirectoryGuard(rootReal, targetPath, options = { bigint: false }) {
|
|
484
494
|
let current = external_node_path_namespaceObject.resolve(targetPath);
|
|
485
495
|
const root = external_node_path_namespaceObject.resolve(rootReal);
|
|
486
496
|
while (current !== root) {
|
|
487
497
|
try {
|
|
488
|
-
return await directory_guard_createAsyncDirectoryGuard(current);
|
|
498
|
+
return await directory_guard_createAsyncDirectoryGuard(current, options);
|
|
489
499
|
}
|
|
490
500
|
catch (error) {
|
|
491
501
|
if (!path_isNotFoundPathError(error)) {
|
|
@@ -494,7 +504,7 @@ async function directory_guard_createNearestExistingDirectoryGuard(rootReal, tar
|
|
|
494
504
|
current = external_node_path_namespaceObject.dirname(current);
|
|
495
505
|
}
|
|
496
506
|
}
|
|
497
|
-
return await directory_guard_createAsyncDirectoryGuard(root);
|
|
507
|
+
return await directory_guard_createAsyncDirectoryGuard(root, options);
|
|
498
508
|
}
|
|
499
509
|
function directory_guard_createNearestExistingSyncDirectoryGuard(rootReal, targetPath) {
|
|
500
510
|
let current = path.resolve(targetPath);
|
|
@@ -514,8 +524,8 @@ function directory_guard_createNearestExistingSyncDirectoryGuard(rootReal, targe
|
|
|
514
524
|
}
|
|
515
525
|
// Recovery receipts must retain every identity bit, including on Windows.
|
|
516
526
|
async function inspectDirectoryIdentity(dir, expected) {
|
|
517
|
-
return await
|
|
518
|
-
const stat =
|
|
527
|
+
return await strict_file_identity_inspectFileIdentity(async () => {
|
|
528
|
+
const stat = external_node_fs_namespaceObject.lstatSync(dir, { bigint: true });
|
|
519
529
|
if (stat.isSymbolicLink() || !stat.isDirectory())
|
|
520
530
|
throw root_errors_directoryComponentNotDirectoryError();
|
|
521
531
|
return stat;
|
|
@@ -568,11 +578,11 @@ function assertDirectory(identity, pathname, label) {
|
|
|
568
578
|
}
|
|
569
579
|
async function createDirectoryReceipt(directoryPath, label) {
|
|
570
580
|
const resolvedPath = external_node_path_namespaceObject.resolve(directoryPath);
|
|
571
|
-
const identity =
|
|
581
|
+
const identity = external_node_fs_namespaceObject.lstatSync(resolvedPath);
|
|
572
582
|
assertDirectory(identity, resolvedPath, label);
|
|
573
583
|
return {
|
|
574
584
|
path: resolvedPath,
|
|
575
|
-
realPath:
|
|
585
|
+
realPath: external_node_fs_namespaceObject.realpathSync.native(resolvedPath),
|
|
576
586
|
identity,
|
|
577
587
|
};
|
|
578
588
|
}
|
|
@@ -587,10 +597,10 @@ function createDirectoryReceiptSync(directoryPath, label) {
|
|
|
587
597
|
};
|
|
588
598
|
}
|
|
589
599
|
async function assertDirectoryReceiptCurrent(receipt, label) {
|
|
590
|
-
const currentIdentity =
|
|
600
|
+
const currentIdentity = external_node_fs_namespaceObject.lstatSync(receipt.path);
|
|
591
601
|
assertDirectory(currentIdentity, receipt.path, label);
|
|
592
602
|
if (!file_identity_sameFileIdentity(receipt.identity, currentIdentity) ||
|
|
593
|
-
(
|
|
603
|
+
(external_node_fs_namespaceObject.realpathSync.native(receipt.path)) !== receipt.realPath) {
|
|
594
604
|
throw new errors_FsSafeError("path-mismatch", `${label} changed during durable directory operation: ${receipt.path}`);
|
|
595
605
|
}
|
|
596
606
|
}
|
|
@@ -603,7 +613,7 @@ function assertDirectoryReceiptCurrentSync(receipt, label) {
|
|
|
603
613
|
}
|
|
604
614
|
}
|
|
605
615
|
async function assertOpenDirectoryCurrent(handle, receipt, label) {
|
|
606
|
-
const openedIdentity =
|
|
616
|
+
const openedIdentity = external_node_fs_namespaceObject.fstatSync(handle.fd);
|
|
607
617
|
assertDirectory(openedIdentity, receipt.path, label);
|
|
608
618
|
if (!file_identity_sameFileIdentity(receipt.identity, openedIdentity)) {
|
|
609
619
|
throw new errors_FsSafeError("path-mismatch", `${label} handle changed during directory sync: ${receipt.path}`);
|
|
@@ -830,13 +840,14 @@ async function ensureDurableDirectory(options) {
|
|
|
830
840
|
|
|
831
841
|
|
|
832
842
|
|
|
843
|
+
|
|
833
844
|
function isSameOrChildPath(candidate, parent) {
|
|
834
845
|
const parentPrefix = parent.endsWith(external_node_path_namespaceObject.sep) ? parent : `${parent}${external_node_path_namespaceObject.sep}`;
|
|
835
846
|
return candidate === parent || candidate.startsWith(parentPrefix);
|
|
836
847
|
}
|
|
837
848
|
async function realpathOrThrowNotFile(target) {
|
|
838
849
|
try {
|
|
839
|
-
return external_node_path_namespaceObject.resolve(
|
|
850
|
+
return external_node_path_namespaceObject.resolve(external_node_fs_namespaceObject.realpathSync.native(target));
|
|
840
851
|
}
|
|
841
852
|
catch (error) {
|
|
842
853
|
if (path_isNotFoundPathError(error)) {
|
|
@@ -855,7 +866,7 @@ async function realpathOrThrowNotFile(target) {
|
|
|
855
866
|
*/
|
|
856
867
|
async function mkdirPathComponentsWithGuards(params) {
|
|
857
868
|
const root = external_node_path_namespaceObject.resolve(params.rootReal);
|
|
858
|
-
const rootCanonical = external_node_path_namespaceObject.resolve(
|
|
869
|
+
const rootCanonical = external_node_path_namespaceObject.resolve(external_node_fs_namespaceObject.realpathSync.native(root));
|
|
859
870
|
const target = external_node_path_namespaceObject.resolve(params.targetPath);
|
|
860
871
|
const relative = external_node_path_namespaceObject.relative(root, target);
|
|
861
872
|
if (isPathRelativeEscape(relative)) {
|
|
@@ -865,18 +876,18 @@ async function mkdirPathComponentsWithGuards(params) {
|
|
|
865
876
|
for (const part of relative.split(external_node_path_namespaceObject.sep).filter(Boolean)) {
|
|
866
877
|
const next = external_node_path_namespaceObject.join(current, part);
|
|
867
878
|
const parentGuard = await directory_guard_createAsyncDirectoryGuard(current);
|
|
868
|
-
await
|
|
879
|
+
await directory_guard_assertAsyncDirectoryGuard(parentGuard);
|
|
869
880
|
await params.beforeComponent?.(next);
|
|
870
881
|
try {
|
|
871
|
-
await promises_namespaceObject.mkdir(next);
|
|
882
|
+
await promises_namespaceObject.mkdir(next, { mode: params.mode });
|
|
872
883
|
}
|
|
873
884
|
catch (error) {
|
|
874
885
|
if (!error || typeof error !== "object" || !("code" in error) || error.code !== "EEXIST") {
|
|
875
886
|
throw error;
|
|
876
887
|
}
|
|
877
888
|
}
|
|
878
|
-
const stat =
|
|
879
|
-
if (!stat.isSymbolicLink() && !stat.isDirectory()) {
|
|
889
|
+
const stat = external_node_fs_namespaceObject.lstatSync(next);
|
|
890
|
+
if ((params.rejectSymlinks && stat.isSymbolicLink()) || (!stat.isSymbolicLink() && !stat.isDirectory())) {
|
|
880
891
|
throw root_errors_directoryComponentNotDirectoryError();
|
|
881
892
|
}
|
|
882
893
|
// Node's recursive mkdir follows symlinks in missing components. Build one
|
|
@@ -895,17 +906,17 @@ async function mkdirPathComponentsWithGuards(params) {
|
|
|
895
906
|
// every subsequent segment. Callers that need the final directory
|
|
896
907
|
// (e.g. to guard it themselves after this function returns) must use
|
|
897
908
|
// the returned resolved path, not their own lexical parent path.
|
|
898
|
-
const targetStat =
|
|
909
|
+
const targetStat = external_node_fs_namespaceObject.statSync(nextReal);
|
|
899
910
|
if (!targetStat.isDirectory()) {
|
|
900
911
|
throw root_errors_directoryComponentNotDirectoryError();
|
|
901
912
|
}
|
|
902
913
|
await directory_guard_createAsyncDirectoryGuard(nextReal);
|
|
903
|
-
await
|
|
914
|
+
await directory_guard_assertAsyncDirectoryGuard(parentGuard);
|
|
904
915
|
current = nextReal;
|
|
905
916
|
continue;
|
|
906
917
|
}
|
|
907
918
|
await directory_guard_createAsyncDirectoryGuard(next);
|
|
908
|
-
await
|
|
919
|
+
await directory_guard_assertAsyncDirectoryGuard(parentGuard);
|
|
909
920
|
current = next;
|
|
910
921
|
}
|
|
911
922
|
return current;
|
|
@@ -918,13 +929,13 @@ async function mkdirPathComponentsWithGuards(params) {
|
|
|
918
929
|
|
|
919
930
|
async function withAsyncDirectoryGuards(guards, mutate, options = {}) {
|
|
920
931
|
for (const guard of guards) {
|
|
921
|
-
await
|
|
932
|
+
await directory_guard_assertAsyncDirectoryGuard(guard);
|
|
922
933
|
}
|
|
923
934
|
const result = await mutate();
|
|
924
935
|
if (options.verifyAfter !== false) {
|
|
925
936
|
try {
|
|
926
937
|
for (const guard of guards) {
|
|
927
|
-
await
|
|
938
|
+
await directory_guard_assertAsyncDirectoryGuard(guard);
|
|
928
939
|
}
|
|
929
940
|
}
|
|
930
941
|
catch (error) {
|
|
@@ -962,9 +973,13 @@ async function guardedRename(params) {
|
|
|
962
973
|
? await createNearestExistingDirectoryGuard(params.targetRoot, path.dirname(params.to))
|
|
963
974
|
: await createAsyncDirectoryGuard(path.dirname(params.to));
|
|
964
975
|
await withAsyncDirectoryGuards([sourceGuard, targetGuard], async () => {
|
|
976
|
+
if (params.onSourceInspected) {
|
|
977
|
+
params.onSourceInspected(fsSync.lstatSync(params.from, { bigint: true }));
|
|
978
|
+
}
|
|
965
979
|
// Authority must survive all awaited guards; do not yield before rename dispatch.
|
|
966
980
|
params.assertBeforeRename?.();
|
|
967
981
|
await fs.rename(params.from, params.to);
|
|
982
|
+
params.onRenamed?.();
|
|
968
983
|
}, { verifyAfter: params.verifyAfter });
|
|
969
984
|
}
|
|
970
985
|
function guardedRenameSync(params) {
|
|
@@ -995,13 +1010,12 @@ function guardedRmSync(params) {
|
|
|
995
1010
|
|
|
996
1011
|
|
|
997
1012
|
|
|
998
|
-
|
|
999
1013
|
function isFilesystemRoot(candidate) {
|
|
1000
1014
|
return external_node_path_namespaceObject.parse(candidate).root === candidate;
|
|
1001
1015
|
}
|
|
1002
|
-
async function
|
|
1016
|
+
async function root_path_existing_pathExists(targetPath) {
|
|
1003
1017
|
try {
|
|
1004
|
-
|
|
1018
|
+
external_node_fs_namespaceObject.lstatSync(targetPath);
|
|
1005
1019
|
return true;
|
|
1006
1020
|
}
|
|
1007
1021
|
catch (error) {
|
|
@@ -1015,7 +1029,7 @@ async function resolvePathViaExistingAncestor(targetPath) {
|
|
|
1015
1029
|
const normalized = external_node_path_namespaceObject.resolve(targetPath);
|
|
1016
1030
|
let cursor = normalized;
|
|
1017
1031
|
const missingSuffix = [];
|
|
1018
|
-
while (!isFilesystemRoot(cursor) && !(await
|
|
1032
|
+
while (!isFilesystemRoot(cursor) && !(await root_path_existing_pathExists(cursor))) {
|
|
1019
1033
|
missingSuffix.unshift(external_node_path_namespaceObject.basename(cursor));
|
|
1020
1034
|
const parent = external_node_path_namespaceObject.dirname(cursor);
|
|
1021
1035
|
if (parent === cursor) {
|
|
@@ -1023,11 +1037,11 @@ async function resolvePathViaExistingAncestor(targetPath) {
|
|
|
1023
1037
|
}
|
|
1024
1038
|
cursor = parent;
|
|
1025
1039
|
}
|
|
1026
|
-
if (!(await
|
|
1040
|
+
if (!(await root_path_existing_pathExists(cursor))) {
|
|
1027
1041
|
return normalized;
|
|
1028
1042
|
}
|
|
1029
1043
|
try {
|
|
1030
|
-
const resolvedAncestor = external_node_path_namespaceObject.resolve(
|
|
1044
|
+
const resolvedAncestor = external_node_path_namespaceObject.resolve(external_node_fs_namespaceObject.realpathSync.native(cursor));
|
|
1031
1045
|
return missingSuffix.length === 0
|
|
1032
1046
|
? resolvedAncestor
|
|
1033
1047
|
: external_node_path_namespaceObject.resolve(resolvedAncestor, ...missingSuffix);
|
|
@@ -1137,10 +1151,15 @@ function mergeDenyMutationPolicies(defaultPolicy, callPolicy) {
|
|
|
1137
1151
|
|
|
1138
1152
|
|
|
1139
1153
|
|
|
1154
|
+
|
|
1140
1155
|
function recordFileOpenFailure(error, filePath) {
|
|
1141
1156
|
recordFileObservationFailure(error, `open:${filePath}`);
|
|
1142
1157
|
throw error;
|
|
1143
1158
|
}
|
|
1159
|
+
function recordExclusiveCreateFailure(error, filePath) {
|
|
1160
|
+
recordFileObservationFailure(error, `exclusive-create:${filePath}`);
|
|
1161
|
+
throw error;
|
|
1162
|
+
}
|
|
1144
1163
|
function openedPathResolutionError(error = new errors_FsSafeError("path-mismatch", "unable to resolve opened file path")) {
|
|
1145
1164
|
recordFileObservationFailure(error, "resolution");
|
|
1146
1165
|
return error;
|
|
@@ -1150,8 +1169,8 @@ async function recordPreOpenFileChange(error, handle, filePath, before, opened)
|
|
|
1150
1169
|
![0n, 1n].includes(before.nlink) || ![0n, 1n].includes(opened.nlink))
|
|
1151
1170
|
return;
|
|
1152
1171
|
try {
|
|
1153
|
-
await
|
|
1154
|
-
const current = await
|
|
1172
|
+
await strict_file_identity_inspectFileIdentity(async () => before);
|
|
1173
|
+
const current = await strict_file_identity_inspectFileIdentity(() => external_node_fs_namespaceObject.fstatSync(handle.fd, { bigint: true }), opened);
|
|
1155
1174
|
if (current.isFile() && [0n, 1n].includes(current.nlink) &&
|
|
1156
1175
|
(before.dev !== current.dev || before.ino !== current.ino)) {
|
|
1157
1176
|
// A stale pathname sample is not proof that its former inode was unlinked.
|
|
@@ -1167,7 +1186,7 @@ async function recordOpenedFileFailure(error, handle, filePath, identity) {
|
|
|
1167
1186
|
!identity.isFile() || identity.nlink > 1n)
|
|
1168
1187
|
return;
|
|
1169
1188
|
try {
|
|
1170
|
-
const current = await
|
|
1189
|
+
const current = await strict_file_identity_inspectFileIdentity(() => external_node_fs_namespaceObject.fstatSync(handle.fd, { bigint: true }), identity);
|
|
1171
1190
|
if (current.isFile() && current.nlink === 0n)
|
|
1172
1191
|
recordFileObservationFailure(error, `unlinked:${filePath}`);
|
|
1173
1192
|
}
|
|
@@ -1182,24 +1201,23 @@ async function recordOpenedFileFailure(error, handle, filePath, identity) {
|
|
|
1182
1201
|
|
|
1183
1202
|
|
|
1184
1203
|
|
|
1204
|
+
|
|
1185
1205
|
async function resolveOpenedFileRealPathForHandle(handle, ioPath) {
|
|
1186
|
-
const handleStat =
|
|
1187
|
-
return await resolveOpenedFileRealPathForFd(handle.fd, handleStat, ioPath);
|
|
1206
|
+
const handleStat = external_node_fs_namespaceObject.fstatSync(handle.fd);
|
|
1207
|
+
return (await resolveOpenedFileRealPathForFd(handle.fd, handleStat, ioPath)).realPath;
|
|
1188
1208
|
}
|
|
1189
1209
|
async function resolveOpenedFileRealPathForFd(fd, handleStat, ioPath) {
|
|
1190
1210
|
const statOptions = typeof handleStat.dev === "bigint" || typeof handleStat.ino === "bigint"
|
|
1191
1211
|
? { bigint: true } : undefined;
|
|
1192
1212
|
const fdCandidates = process.platform === "linux"
|
|
1193
1213
|
? [`/proc/self/fd/${fd}`, `/dev/fd/${fd}`]
|
|
1194
|
-
:
|
|
1195
|
-
? []
|
|
1196
|
-
: [`/dev/fd/${fd}`];
|
|
1214
|
+
: [];
|
|
1197
1215
|
for (const fdPath of fdCandidates) {
|
|
1198
1216
|
try {
|
|
1199
|
-
const fdRealPath =
|
|
1200
|
-
const fdRealStat = statOptions ?
|
|
1217
|
+
const fdRealPath = external_node_fs_namespaceObject.realpathSync.native(fdPath);
|
|
1218
|
+
const fdRealStat = statOptions ? external_node_fs_namespaceObject.statSync(fdRealPath, statOptions) : external_node_fs_namespaceObject.statSync(fdRealPath);
|
|
1201
1219
|
if (file_identity_sameFileIdentity(handleStat, fdRealStat)) {
|
|
1202
|
-
return fdRealPath;
|
|
1220
|
+
return { realPath: fdRealPath, stat: fdRealStat };
|
|
1203
1221
|
}
|
|
1204
1222
|
}
|
|
1205
1223
|
catch {
|
|
@@ -1207,10 +1225,10 @@ async function resolveOpenedFileRealPathForFd(fd, handleStat, ioPath) {
|
|
|
1207
1225
|
}
|
|
1208
1226
|
}
|
|
1209
1227
|
try {
|
|
1210
|
-
const ioRealPath =
|
|
1211
|
-
const ioRealStat = statOptions ?
|
|
1228
|
+
const ioRealPath = external_node_fs_namespaceObject.realpathSync.native(ioPath);
|
|
1229
|
+
const ioRealStat = statOptions ? external_node_fs_namespaceObject.statSync(ioRealPath, statOptions) : external_node_fs_namespaceObject.statSync(ioRealPath);
|
|
1212
1230
|
if (file_identity_sameFileIdentity(handleStat, ioRealStat)) {
|
|
1213
|
-
return ioRealPath;
|
|
1231
|
+
return { realPath: ioRealPath, stat: ioRealStat };
|
|
1214
1232
|
}
|
|
1215
1233
|
}
|
|
1216
1234
|
catch (err) {
|
|
@@ -1233,7 +1251,7 @@ async function resolveOpenedFileRealPathForFd(fd, handleStat, ioPath) {
|
|
|
1233
1251
|
async function resolveOpenedFileRealPathFromParent(handleStat, ioPath, statOptions) {
|
|
1234
1252
|
let parentReal;
|
|
1235
1253
|
try {
|
|
1236
|
-
parentReal =
|
|
1254
|
+
parentReal = external_node_fs_namespaceObject.realpathSync.native(external_node_path_namespaceObject.dirname(ioPath));
|
|
1237
1255
|
}
|
|
1238
1256
|
catch (err) {
|
|
1239
1257
|
if (path_isNotFoundPathError(err)) {
|
|
@@ -1254,9 +1272,12 @@ async function resolveOpenedFileRealPathFromParent(handleStat, ioPath, statOptio
|
|
|
1254
1272
|
for (const entry of entries.toSorted()) {
|
|
1255
1273
|
const candidatePath = external_node_path_namespaceObject.join(parentReal, entry);
|
|
1256
1274
|
try {
|
|
1257
|
-
const candidateStat = statOptions ?
|
|
1275
|
+
const candidateStat = statOptions ? external_node_fs_namespaceObject.lstatSync(candidatePath, statOptions) : external_node_fs_namespaceObject.lstatSync(candidatePath);
|
|
1258
1276
|
if (candidateStat.isFile() && file_identity_sameFileIdentity(handleStat, candidateStat)) {
|
|
1259
|
-
|
|
1277
|
+
const realPath = external_node_fs_namespaceObject.realpathSync.native(candidatePath);
|
|
1278
|
+
const stat = statOptions ? external_node_fs_namespaceObject.statSync(realPath, statOptions) : external_node_fs_namespaceObject.statSync(realPath);
|
|
1279
|
+
if (file_identity_sameFileIdentity(handleStat, stat))
|
|
1280
|
+
return { realPath, stat };
|
|
1260
1281
|
}
|
|
1261
1282
|
}
|
|
1262
1283
|
catch (err) {
|
|
@@ -1268,6 +1289,27 @@ async function resolveOpenedFileRealPathFromParent(handleStat, ioPath, statOptio
|
|
|
1268
1289
|
return null;
|
|
1269
1290
|
}
|
|
1270
1291
|
|
|
1292
|
+
;// CONCATENATED MODULE: ../../node_modules/@openclaw/fs-safe/dist/file-sync.js
|
|
1293
|
+
|
|
1294
|
+
async function syncFileBestEffort(handle) {
|
|
1295
|
+
try {
|
|
1296
|
+
await handle.sync();
|
|
1297
|
+
}
|
|
1298
|
+
catch (error) {
|
|
1299
|
+
if (error?.code !== "EPERM")
|
|
1300
|
+
throw error;
|
|
1301
|
+
}
|
|
1302
|
+
}
|
|
1303
|
+
function syncFileBestEffortSync(fd, fsModule = external_node_fs_namespaceObject) {
|
|
1304
|
+
try {
|
|
1305
|
+
fsModule.fsyncSync(fd);
|
|
1306
|
+
}
|
|
1307
|
+
catch (error) {
|
|
1308
|
+
if (error?.code !== "EPERM")
|
|
1309
|
+
throw error;
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
|
|
1271
1313
|
;// CONCATENATED MODULE: external "node:module"
|
|
1272
1314
|
const external_node_module_namespaceObject = __rspack_createRequire_require("node:module");
|
|
1273
1315
|
;// CONCATENATED MODULE: ../../node_modules/@openclaw/fs-safe/dist/native-config.js
|
|
@@ -1527,7 +1569,7 @@ function getNativeBinding() {
|
|
|
1527
1569
|
}
|
|
1528
1570
|
return undefined;
|
|
1529
1571
|
}
|
|
1530
|
-
function
|
|
1572
|
+
function native_requireNativeBinding() {
|
|
1531
1573
|
const native = getNativeBinding();
|
|
1532
1574
|
if (!native) {
|
|
1533
1575
|
throw new FsSafeError("helper-unavailable", "native fs-safe helper is unavailable", {
|
|
@@ -1614,15 +1656,14 @@ function removeNativeCreatedFileIfStillPinned(params) {
|
|
|
1614
1656
|
return;
|
|
1615
1657
|
}
|
|
1616
1658
|
try {
|
|
1617
|
-
const parentPathStat = external_node_fs_namespaceObject.lstatSync(params.parentPath);
|
|
1618
|
-
const parentFdStat =
|
|
1659
|
+
const parentPathStat = external_node_fs_namespaceObject.lstatSync(params.parentPath, { bigint: true });
|
|
1660
|
+
const parentFdStat = external_node_fs_namespaceObject.fstatSync(params.parentFd, { bigint: true });
|
|
1619
1661
|
const targetPath = external_node_path_namespaceObject.join(params.parentPath, params.basename);
|
|
1620
|
-
const target = external_node_fs_namespaceObject.lstatSync(targetPath);
|
|
1621
|
-
if (!parentPathStat.isSymbolicLink() &&
|
|
1622
|
-
parentPathStat
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
sameFileIdentityForCleanup(target, params.created)) {
|
|
1662
|
+
const target = external_node_fs_namespaceObject.lstatSync(targetPath, { bigint: true });
|
|
1663
|
+
if (!parentPathStat.isSymbolicLink() && parentPathStat.isDirectory() &&
|
|
1664
|
+
file_identity_sameFileIdentityForCleanup(parentPathStat, parentFdStat) &&
|
|
1665
|
+
!target.isSymbolicLink() && target.isFile() &&
|
|
1666
|
+
file_identity_sameFileIdentityForCleanup(target, params.created)) {
|
|
1626
1667
|
external_node_fs_namespaceObject.rmSync(targetPath);
|
|
1627
1668
|
}
|
|
1628
1669
|
}
|
|
@@ -1659,7 +1700,7 @@ async function createNativeExclusiveFile(targetPath, mode) {
|
|
|
1659
1700
|
}
|
|
1660
1701
|
fd = opened.fd;
|
|
1661
1702
|
external_node_fs_namespaceObject.fchmodSync(fd, mode);
|
|
1662
|
-
created = external_node_fs_namespaceObject.fstatSync(fd);
|
|
1703
|
+
created = external_node_fs_namespaceObject.fstatSync(fd, { bigint: true });
|
|
1663
1704
|
return wrapNativeFd(fd, opened.containment);
|
|
1664
1705
|
}
|
|
1665
1706
|
catch (error) {
|
|
@@ -1671,7 +1712,6 @@ async function createNativeExclusiveFile(targetPath, mode) {
|
|
|
1671
1712
|
// Preserve the original error.
|
|
1672
1713
|
}
|
|
1673
1714
|
removeNativeCreatedFileIfStillPinned({
|
|
1674
|
-
binding,
|
|
1675
1715
|
parentPath,
|
|
1676
1716
|
parentFd: parent.fd,
|
|
1677
1717
|
basename,
|
|
@@ -1684,22 +1724,14 @@ async function createNativeExclusiveFile(targetPath, mode) {
|
|
|
1684
1724
|
await parent.close().catch(() => undefined);
|
|
1685
1725
|
}
|
|
1686
1726
|
}
|
|
1687
|
-
function syncNativeFileBestEffort(fd) {
|
|
1688
|
-
try {
|
|
1689
|
-
external_node_fs_namespaceObject.fsyncSync(fd);
|
|
1690
|
-
}
|
|
1691
|
-
catch (error) {
|
|
1692
|
-
if (error.code !== "EPERM") {
|
|
1693
|
-
throw error;
|
|
1694
|
-
}
|
|
1695
|
-
}
|
|
1696
|
-
}
|
|
1697
1727
|
|
|
1698
1728
|
;// CONCATENATED MODULE: ../../node_modules/@openclaw/fs-safe/dist/native-pinned-write-windows.js
|
|
1699
1729
|
|
|
1700
1730
|
|
|
1701
1731
|
|
|
1702
1732
|
|
|
1733
|
+
|
|
1734
|
+
|
|
1703
1735
|
function sameNativeIdentity(left, right) {
|
|
1704
1736
|
return left.dev === right.dev && left.ino === right.ino;
|
|
1705
1737
|
}
|
|
@@ -1724,14 +1756,15 @@ async function runPinnedWriteWindows(binding, params, root, parentFd, parentGuar
|
|
|
1724
1756
|
try {
|
|
1725
1757
|
tempName = `.fs-safe-${(0,external_node_crypto_namespaceObject.randomUUID)()}.tmp`;
|
|
1726
1758
|
tempFd = binding.openBeneath(parentFd, tempName, nativeOpenFlags(external_node_fs_namespaceObject.constants.O_WRONLY | external_node_fs_namespaceObject.constants.O_CREAT | external_node_fs_namespaceObject.constants.O_EXCL)).fd;
|
|
1727
|
-
|
|
1728
|
-
|
|
1759
|
+
const verificationIdentity = strict_file_identity_inspectFileIdentitySync(() => external_node_fs_namespaceObject.fstatSync(tempFd, { bigint: true }));
|
|
1760
|
+
tempIdentity = verificationIdentity;
|
|
1729
1761
|
// Creation is requested at 0600 in the binding, but a restrictive umask
|
|
1730
1762
|
// can remove owner access. Keep the unpublished inode private and
|
|
1731
1763
|
// reopenable until the published name has been identity-fenced.
|
|
1732
1764
|
external_node_fs_namespaceObject.fchmodSync(tempFd, 0o600);
|
|
1733
1765
|
await writeNativeInput(tempFd, params.input, params.maxBytes);
|
|
1734
|
-
|
|
1766
|
+
if (params.sync !== false)
|
|
1767
|
+
syncFileBestEffortSync(tempFd);
|
|
1735
1768
|
if (params.overwrite === false) {
|
|
1736
1769
|
binding.renameNoReplace(parentFd, tempName, parentFd, params.basename);
|
|
1737
1770
|
}
|
|
@@ -1740,8 +1773,9 @@ async function runPinnedWriteWindows(binding, params, root, parentFd, parentGuar
|
|
|
1740
1773
|
}
|
|
1741
1774
|
renamed = true;
|
|
1742
1775
|
targetFd = binding.openBeneath(parentFd, params.basename, nativeOpenFlags(external_node_fs_namespaceObject.constants.O_RDONLY)).fd;
|
|
1776
|
+
const targetStat = strict_file_identity_inspectFileIdentitySync(() => external_node_fs_namespaceObject.fstatSync(targetFd, { bigint: true }), verificationIdentity);
|
|
1743
1777
|
const targetIdentity = binding.fstatIdentity(targetFd);
|
|
1744
|
-
if (!
|
|
1778
|
+
if (!targetStat.isFile()) {
|
|
1745
1779
|
throw new errors_FsSafeError("path-mismatch", "native write target changed after rename");
|
|
1746
1780
|
}
|
|
1747
1781
|
// Native exclusive creation starts at 0600. Apply the requested mode only
|
|
@@ -1749,13 +1783,13 @@ async function runPinnedWriteWindows(binding, params, root, parentFd, parentGuar
|
|
|
1749
1783
|
// verifiable and so broader modes are never exposed before that fence.
|
|
1750
1784
|
try {
|
|
1751
1785
|
external_node_fs_namespaceObject.fchmodSync(targetFd, params.mode);
|
|
1752
|
-
|
|
1786
|
+
if (params.sync !== false)
|
|
1787
|
+
syncFileBestEffortSync(targetFd);
|
|
1753
1788
|
}
|
|
1754
1789
|
catch (error) {
|
|
1755
1790
|
closeWriteFd(targetFd);
|
|
1756
1791
|
targetFd = undefined;
|
|
1757
1792
|
removeNativeCreatedFileIfStillPinned({
|
|
1758
|
-
binding,
|
|
1759
1793
|
parentPath,
|
|
1760
1794
|
parentFd,
|
|
1761
1795
|
basename: params.basename,
|
|
@@ -1763,7 +1797,8 @@ async function runPinnedWriteWindows(binding, params, root, parentFd, parentGuar
|
|
|
1763
1797
|
});
|
|
1764
1798
|
throw error;
|
|
1765
1799
|
}
|
|
1766
|
-
|
|
1800
|
+
if (params.sync !== false)
|
|
1801
|
+
syncFileBestEffortSync(parentFd);
|
|
1767
1802
|
// Verification follows publication and final chmod, outside rollback handling.
|
|
1768
1803
|
await params.verifyPublished?.(targetFd, verificationIdentity, parentGuard);
|
|
1769
1804
|
completed = true;
|
|
@@ -1774,7 +1809,6 @@ async function runPinnedWriteWindows(binding, params, root, parentFd, parentGuar
|
|
|
1774
1809
|
const tempCloseError = closeWriteFd(tempFd);
|
|
1775
1810
|
if (!renamed) {
|
|
1776
1811
|
removeNativeCreatedFileIfStillPinned({
|
|
1777
|
-
binding,
|
|
1778
1812
|
parentPath,
|
|
1779
1813
|
parentFd,
|
|
1780
1814
|
basename: tempName,
|
|
@@ -1819,7 +1853,7 @@ function assertStagedDirectoryCurrent(receipt) {
|
|
|
1819
1853
|
throw new errors_FsSafeError("path-mismatch", "staging directory pathname changed");
|
|
1820
1854
|
}
|
|
1821
1855
|
}
|
|
1822
|
-
function
|
|
1856
|
+
function staged_directory_openStagedDirectory(directory) {
|
|
1823
1857
|
// Copy supplied facts before any asynchronous work; receipts are not authority.
|
|
1824
1858
|
const pathname = path.resolve(typeof directory === "string" ? directory : directory.path);
|
|
1825
1859
|
const expected = typeof directory === "string" ? undefined : {
|
|
@@ -1909,6 +1943,8 @@ var __disposeResources = (undefined && undefined.__disposeResources) || (functio
|
|
|
1909
1943
|
|
|
1910
1944
|
|
|
1911
1945
|
|
|
1946
|
+
|
|
1947
|
+
|
|
1912
1948
|
function assertNativeStaging(binding) {
|
|
1913
1949
|
if ([
|
|
1914
1950
|
binding.createStagedFile,
|
|
@@ -1944,23 +1980,25 @@ class NativeStagedFile {
|
|
|
1944
1980
|
#directory;
|
|
1945
1981
|
#portableNames;
|
|
1946
1982
|
#publishedMode;
|
|
1983
|
+
#sync;
|
|
1947
1984
|
#name = `.fs-safe-${(0,external_node_crypto_namespaceObject.randomUUID)()}.tmp`;
|
|
1948
1985
|
#state = { status: "open", publication: NOT_PUBLISHED };
|
|
1949
1986
|
#receipt;
|
|
1950
|
-
constructor(binding, parentFd, directory, portableNames, publishedMode) {
|
|
1987
|
+
constructor(binding, parentFd, directory, portableNames, publishedMode, sync) {
|
|
1951
1988
|
this.#binding = binding;
|
|
1952
1989
|
this.#parentFd = parentFd;
|
|
1953
1990
|
this.#directory = directory;
|
|
1954
1991
|
this.#portableNames = portableNames;
|
|
1955
1992
|
this.#publishedMode = publishedMode;
|
|
1993
|
+
this.#sync = sync;
|
|
1956
1994
|
}
|
|
1957
1995
|
// Takes ownership of parentFd, including all construction and preparation failures.
|
|
1958
1996
|
static async create(binding, parentFd, directory, input, mode, maxBytes,
|
|
1959
1997
|
// Public staging uses portable names; existing POSIX writes accept literal names.
|
|
1960
|
-
portableNames = true) {
|
|
1998
|
+
portableNames = true, sync = true) {
|
|
1961
1999
|
let staged;
|
|
1962
2000
|
try {
|
|
1963
|
-
staged = new NativeStagedFile(binding, parentFd, directory, portableNames, mode);
|
|
2001
|
+
staged = new NativeStagedFile(binding, parentFd, directory, portableNames, mode, sync);
|
|
1964
2002
|
}
|
|
1965
2003
|
catch (error) {
|
|
1966
2004
|
try {
|
|
@@ -1979,7 +2017,7 @@ class NativeStagedFile {
|
|
|
1979
2017
|
try {
|
|
1980
2018
|
// This owner never escapes. Only the internal verifier borrows its fd;
|
|
1981
2019
|
// public descriptor methods remain await-free and cannot race disposal.
|
|
1982
|
-
const staged = __addDisposableResource(env_1, await NativeStagedFile.create(binding, parentFd, directory, params.input, params.mode, params.maxBytes, false), true);
|
|
2020
|
+
const staged = __addDisposableResource(env_1, await NativeStagedFile.create(binding, parentFd, directory, params.input, params.mode, params.maxBytes, false, params.sync), true);
|
|
1983
2021
|
const published = await staged.publish(params.basename, { overwrite: params.overwrite !== false });
|
|
1984
2022
|
const identity = published.staged.identity;
|
|
1985
2023
|
await params.verifyPublished?.(staged.#file(), identity, parentGuard);
|
|
@@ -2016,10 +2054,12 @@ class NativeStagedFile {
|
|
|
2016
2054
|
}
|
|
2017
2055
|
#assertNamed(name) {
|
|
2018
2056
|
const fd = this.#file();
|
|
2019
|
-
|
|
2020
|
-
external_node_fs_namespaceObject.fstatSync(fd, { bigint: true })
|
|
2057
|
+
const stat = this.#binding.stagedFileMatches(this.#parentFd, name, fd)
|
|
2058
|
+
? external_node_fs_namespaceObject.fstatSync(fd, { bigint: true }) : undefined;
|
|
2059
|
+
if (!stat || stat.nlink !== 1n) {
|
|
2021
2060
|
throw new errors_FsSafeError("path-mismatch", "staged entry no longer names the exclusive created file");
|
|
2022
2061
|
}
|
|
2062
|
+
return Number(stat.mode & 4095n);
|
|
2023
2063
|
}
|
|
2024
2064
|
#assertCurrent() {
|
|
2025
2065
|
if (this.#open().publication.status !== "not-published") {
|
|
@@ -2042,7 +2082,8 @@ class NativeStagedFile {
|
|
|
2042
2082
|
const fd = state.fileFd;
|
|
2043
2083
|
external_node_fs_namespaceObject.fchmodSync(fd, 0o600);
|
|
2044
2084
|
await writeNativeInput(fd, input, maxBytes);
|
|
2045
|
-
|
|
2085
|
+
if (this.#sync)
|
|
2086
|
+
syncFileBestEffortSync(fd);
|
|
2046
2087
|
const stat = external_node_fs_namespaceObject.fstatSync(fd, { bigint: true });
|
|
2047
2088
|
this.#receipt = Object.freeze({
|
|
2048
2089
|
directory: this.#directory,
|
|
@@ -2109,14 +2150,21 @@ class NativeStagedFile {
|
|
|
2109
2150
|
overwrite,
|
|
2110
2151
|
});
|
|
2111
2152
|
state.publication = receipt;
|
|
2112
|
-
this.#assertNamed(basename);
|
|
2153
|
+
const stagedMode = this.#assertNamed(basename);
|
|
2113
2154
|
assertStagedDirectoryCurrent(this.#directory);
|
|
2114
2155
|
// Keep contents private until the published name passes its identity
|
|
2115
2156
|
// fence. Mode changes use the owned fd, including for final mode 000.
|
|
2116
2157
|
const fd = this.#file();
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2158
|
+
if (this.#publishedMode !== 0o600 || stagedMode !== 0o600)
|
|
2159
|
+
external_node_fs_namespaceObject.fchmodSync(fd, this.#publishedMode);
|
|
2160
|
+
// With sync enabled, content was synced before rename. A lost chmod leaves staged 0600,
|
|
2161
|
+
// no wider than modes retaining owner rw. Restrictive modes and observed
|
|
2162
|
+
// widening of the stage still need the permission correction made durable.
|
|
2163
|
+
if (this.#sync && ((this.#publishedMode & 0o600) !== 0o600 || (stagedMode & ~this.#publishedMode) !== 0)) {
|
|
2164
|
+
syncFileBestEffortSync(fd);
|
|
2165
|
+
}
|
|
2166
|
+
if (this.#sync)
|
|
2167
|
+
syncFileBestEffortSync(this.#parentFd);
|
|
2120
2168
|
this.#assertNamed(basename);
|
|
2121
2169
|
assertStagedDirectoryCurrent(this.#directory);
|
|
2122
2170
|
return receipt;
|
|
@@ -2189,6 +2237,17 @@ class NativeStagedFile {
|
|
|
2189
2237
|
}
|
|
2190
2238
|
const createNativeStage = NativeStagedFile.create;
|
|
2191
2239
|
const writeNativeStage = NativeStagedFile.write;
|
|
2240
|
+
async function stageFileInDirectory(options) {
|
|
2241
|
+
if (process.platform !== "linux" && process.platform !== "darwin") {
|
|
2242
|
+
throw new FsSafeError("unsupported-platform", "retained-directory staging requires Linux or macOS");
|
|
2243
|
+
}
|
|
2244
|
+
const binding = requireNativeBinding();
|
|
2245
|
+
assertNativeStaging(binding);
|
|
2246
|
+
const input = { kind: "buffer", data: Buffer.from(options.content) };
|
|
2247
|
+
const mode = options.mode ?? 0o600;
|
|
2248
|
+
const parent = openStagedDirectory(options.directory);
|
|
2249
|
+
return await createNativeStage(binding, parent.fd, parent.receipt, input, mode);
|
|
2250
|
+
}
|
|
2192
2251
|
|
|
2193
2252
|
;// CONCATENATED MODULE: ../../node_modules/@openclaw/fs-safe/dist/native-pinned-write.js
|
|
2194
2253
|
var native_pinned_write_addDisposableResource = (undefined && undefined.__addDisposableResource) || function (env, value, async) {
|
|
@@ -2250,6 +2309,8 @@ var native_pinned_write_disposeResources = (undefined && undefined.__disposeReso
|
|
|
2250
2309
|
|
|
2251
2310
|
|
|
2252
2311
|
|
|
2312
|
+
|
|
2313
|
+
|
|
2253
2314
|
async function runPinnedWriteNative(binding, params) {
|
|
2254
2315
|
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
2255
2316
|
try {
|
|
@@ -2272,8 +2333,14 @@ async function runPinnedWriteNative(binding, params) {
|
|
|
2272
2333
|
},
|
|
2273
2334
|
}, false);
|
|
2274
2335
|
try {
|
|
2336
|
+
const exactRoot = typeof params.rootIdentity?.dev === "bigint" && typeof params.rootIdentity.ino === "bigint"
|
|
2337
|
+
? { dev: params.rootIdentity.dev, ino: params.rootIdentity.ino } : undefined;
|
|
2275
2338
|
let rootMatches;
|
|
2276
|
-
if (
|
|
2339
|
+
if (exactRoot) {
|
|
2340
|
+
strict_file_identity_inspectFileIdentitySync(() => external_node_fs_namespaceObject.fstatSync(root.fd, { bigint: true }), exactRoot);
|
|
2341
|
+
rootMatches = true;
|
|
2342
|
+
}
|
|
2343
|
+
else if (windows) {
|
|
2277
2344
|
const identity = binding.fstatIdentity(root.fd);
|
|
2278
2345
|
rootMatches = !params.rootIdentity || sameNativeIdentity(params.rootIdentity, identity);
|
|
2279
2346
|
}
|
|
@@ -2288,24 +2355,26 @@ async function runPinnedWriteNative(binding, params) {
|
|
|
2288
2355
|
binding.mkdirBeneath(root.fd, params.relativeParentPath, 0o777);
|
|
2289
2356
|
}
|
|
2290
2357
|
parentFd = binding.openBeneath(root.fd, params.relativeParentPath, directoryFlags).fd;
|
|
2291
|
-
const parentPath =
|
|
2358
|
+
const parentPath = external_node_fs_namespaceObject.realpathSync.native(params.relativeParentPath
|
|
2292
2359
|
? external_node_path_namespaceObject.join(params.rootPath, ...params.relativeParentPath.split("/"))
|
|
2293
2360
|
: params.rootPath);
|
|
2294
2361
|
const directory = windows ? undefined : describeStagedDirectory(parentFd, parentPath);
|
|
2295
|
-
const parentPathStat =
|
|
2296
|
-
|
|
2362
|
+
const parentPathStat = exactRoot
|
|
2363
|
+
? await inspectDirectoryIdentity(parentPath, strict_file_identity_inspectFileIdentitySync(() => external_node_fs_namespaceObject.fstatSync(parentFd, { bigint: true })))
|
|
2364
|
+
: external_node_fs_namespaceObject.lstatSync(parentPath);
|
|
2365
|
+
if (windows && !exactRoot) {
|
|
2297
2366
|
const parentIdentity = binding.fstatIdentity(parentFd);
|
|
2298
2367
|
if (parentPathStat.isSymbolicLink() || !sameNativeIdentity(parentPathStat, parentIdentity)) {
|
|
2299
2368
|
throw new errors_FsSafeError("path-mismatch", "native write parent changed during resolution");
|
|
2300
2369
|
}
|
|
2301
2370
|
}
|
|
2302
|
-
else if (parentPathStat.isSymbolicLink() || !exactIdentityMatches(parentPathStat, directory.identity)) {
|
|
2371
|
+
else if (!windows && (parentPathStat.isSymbolicLink() || !exactIdentityMatches(parentPathStat, directory.identity))) {
|
|
2303
2372
|
throw new errors_FsSafeError("path-mismatch", "native write parent changed during resolution");
|
|
2304
2373
|
}
|
|
2305
2374
|
const verificationGuard = { dir: parentPath, realPath: parentPath, stat: parentPathStat };
|
|
2306
2375
|
if (params.overwrite === false) {
|
|
2307
2376
|
try {
|
|
2308
|
-
|
|
2377
|
+
external_node_fs_namespaceObject.lstatSync(external_node_path_namespaceObject.join(parentPath, params.basename));
|
|
2309
2378
|
throw Object.assign(new Error("destination already exists"), { code: "EEXIST" });
|
|
2310
2379
|
}
|
|
2311
2380
|
catch (error) {
|
|
@@ -2395,6 +2464,384 @@ function read_open_flags_resolveReadOpenFlags(options) {
|
|
|
2395
2464
|
return constants.O_RDONLY | noFollow | nonBlocking;
|
|
2396
2465
|
}
|
|
2397
2466
|
|
|
2467
|
+
;// CONCATENATED MODULE: ../../node_modules/@openclaw/fs-safe/dist/replace-file-temp-owner.js
|
|
2468
|
+
|
|
2469
|
+
|
|
2470
|
+
|
|
2471
|
+
|
|
2472
|
+
|
|
2473
|
+
|
|
2474
|
+
|
|
2475
|
+
|
|
2476
|
+
const PUBLISHED_READ_FLAGS = read_open_flags_resolveReadOpenFlags();
|
|
2477
|
+
function assertOwnedFile(stat, pathname, pathnameEntry) {
|
|
2478
|
+
if (stat.isSymbolicLink()) {
|
|
2479
|
+
throw new FsSafeError("symlink", `Atomic replace owned file became a symlink: ${pathname}`);
|
|
2480
|
+
}
|
|
2481
|
+
if (!stat.isFile()) {
|
|
2482
|
+
throw new FsSafeError("not-file", `Atomic replace owned file must remain regular: ${pathname}`);
|
|
2483
|
+
}
|
|
2484
|
+
if (stat.nlink > 1n || (pathnameEntry && stat.nlink !== 1n)) {
|
|
2485
|
+
throw new FsSafeError("hardlink", `Atomic replace owned file must retain one link: ${pathname}`);
|
|
2486
|
+
}
|
|
2487
|
+
}
|
|
2488
|
+
function missingOwnedFile(pathname, cause) {
|
|
2489
|
+
return new FsSafeError("path-mismatch", `Atomic replace owned file disappeared: ${pathname}`, {
|
|
2490
|
+
cause,
|
|
2491
|
+
});
|
|
2492
|
+
}
|
|
2493
|
+
function cleanupFailure(originalError, cleanupError) {
|
|
2494
|
+
if (originalError !== undefined) {
|
|
2495
|
+
return new Error(`Atomic file replace failed (${String(originalError)}); cleanup also failed (${String(cleanupError)})`, { cause: originalError });
|
|
2496
|
+
}
|
|
2497
|
+
return cleanupError instanceof Error ? cleanupError : new Error(String(cleanupError));
|
|
2498
|
+
}
|
|
2499
|
+
async function cleanupOwnedPath(params) {
|
|
2500
|
+
if (!params.identity)
|
|
2501
|
+
return true;
|
|
2502
|
+
try {
|
|
2503
|
+
const current = params.fsModule === promises_namespaceObject
|
|
2504
|
+
? external_node_fs_namespaceObject.lstatSync(params.pathname, { bigint: true })
|
|
2505
|
+
: await params.fsModule.lstat(params.pathname, { bigint: true });
|
|
2506
|
+
if (current.isSymbolicLink() ||
|
|
2507
|
+
!current.isFile() ||
|
|
2508
|
+
current.nlink !== 1n ||
|
|
2509
|
+
!file_identity_sameFileIdentityForCleanup(current, params.identity)) {
|
|
2510
|
+
return true;
|
|
2511
|
+
}
|
|
2512
|
+
await params.fsModule.unlink(params.pathname);
|
|
2513
|
+
return true;
|
|
2514
|
+
}
|
|
2515
|
+
catch (cleanupError) {
|
|
2516
|
+
if (cleanupError.code === "ENOENT")
|
|
2517
|
+
return true;
|
|
2518
|
+
if (params.throwOnCleanupError) {
|
|
2519
|
+
throw cleanupFailure(params.originalError, cleanupError);
|
|
2520
|
+
}
|
|
2521
|
+
return false;
|
|
2522
|
+
}
|
|
2523
|
+
}
|
|
2524
|
+
// Borrowed handle: the caller retains it until this best-effort cleanup finishes.
|
|
2525
|
+
async function cleanupPinnedFilePath(params) {
|
|
2526
|
+
if (!params.identity)
|
|
2527
|
+
return;
|
|
2528
|
+
try {
|
|
2529
|
+
const guard = params.parentGuard;
|
|
2530
|
+
if ([guard.stat.dev, guard.stat.ino].some((value) => typeof value === "number" && !Number.isSafeInteger(value)))
|
|
2531
|
+
return;
|
|
2532
|
+
await directory_guard_assertAsyncDirectoryGuard(guard);
|
|
2533
|
+
const parent = external_node_fs_namespaceObject.lstatSync(guard.dir, { bigint: true });
|
|
2534
|
+
if (parent.isSymbolicLink() || !parent.isDirectory() ||
|
|
2535
|
+
!file_identity_sameFileIdentityForCleanup(parent, guard.stat))
|
|
2536
|
+
return;
|
|
2537
|
+
const opened = external_node_fs_namespaceObject.fstatSync(params.handle.fd, { bigint: true });
|
|
2538
|
+
if (!opened.isFile() || opened.nlink !== 1n ||
|
|
2539
|
+
!file_identity_sameFileIdentityForCleanup(opened, params.identity))
|
|
2540
|
+
return;
|
|
2541
|
+
await cleanupOwnedPath({
|
|
2542
|
+
fsModule: promises_namespaceObject,
|
|
2543
|
+
pathname: params.pathname,
|
|
2544
|
+
identity: params.identity,
|
|
2545
|
+
throwOnCleanupError: false,
|
|
2546
|
+
});
|
|
2547
|
+
}
|
|
2548
|
+
catch {
|
|
2549
|
+
// Unverifiable authority must preserve the path and the original write failure.
|
|
2550
|
+
}
|
|
2551
|
+
}
|
|
2552
|
+
function cleanupOwnedPathSync(params) {
|
|
2553
|
+
if (!params.identity)
|
|
2554
|
+
return true;
|
|
2555
|
+
try {
|
|
2556
|
+
const current = params.fsModule.lstatSync(params.pathname, { bigint: true });
|
|
2557
|
+
if (current.isSymbolicLink() ||
|
|
2558
|
+
!current.isFile() ||
|
|
2559
|
+
current.nlink !== 1n ||
|
|
2560
|
+
!sameFileIdentityForCleanup(current, params.identity)) {
|
|
2561
|
+
return true;
|
|
2562
|
+
}
|
|
2563
|
+
params.fsModule.unlinkSync(params.pathname);
|
|
2564
|
+
return true;
|
|
2565
|
+
}
|
|
2566
|
+
catch (cleanupError) {
|
|
2567
|
+
if (cleanupError.code === "ENOENT")
|
|
2568
|
+
return true;
|
|
2569
|
+
if (params.throwOnCleanupError) {
|
|
2570
|
+
throw cleanupFailure(params.originalError, cleanupError);
|
|
2571
|
+
}
|
|
2572
|
+
return false;
|
|
2573
|
+
}
|
|
2574
|
+
}
|
|
2575
|
+
class AsyncAtomicTempOwner {
|
|
2576
|
+
pathname;
|
|
2577
|
+
#handle;
|
|
2578
|
+
#identity;
|
|
2579
|
+
#exists = false;
|
|
2580
|
+
#unregister;
|
|
2581
|
+
constructor(pathname) {
|
|
2582
|
+
this.pathname = pathname;
|
|
2583
|
+
this.#unregister = registerTempPathForExit(pathname, { singleLinkFile: true });
|
|
2584
|
+
}
|
|
2585
|
+
start() {
|
|
2586
|
+
this.#exists = true;
|
|
2587
|
+
}
|
|
2588
|
+
onIdentity = (identity) => {
|
|
2589
|
+
this.#identity = identity;
|
|
2590
|
+
this.#unregister.setIdentity(identity);
|
|
2591
|
+
};
|
|
2592
|
+
adopt(temp) {
|
|
2593
|
+
this.#handle = temp.handle;
|
|
2594
|
+
this.onIdentity(temp.identity);
|
|
2595
|
+
}
|
|
2596
|
+
get identity() {
|
|
2597
|
+
if (!this.#identity)
|
|
2598
|
+
throw new Error("Atomic temp owner has no identity");
|
|
2599
|
+
return this.#identity;
|
|
2600
|
+
}
|
|
2601
|
+
async assertCurrent(fsModule, pathname = this.pathname) {
|
|
2602
|
+
const opened = await inspectFileIdentity(async () => {
|
|
2603
|
+
const stat = fsModule === fs ? syncFs.fstatSync(this.#handle.fd, { bigint: true })
|
|
2604
|
+
: await this.#handle.stat({ bigint: true });
|
|
2605
|
+
assertOwnedFile(stat, pathname, false);
|
|
2606
|
+
return stat;
|
|
2607
|
+
}, this.identity);
|
|
2608
|
+
try {
|
|
2609
|
+
await inspectFileIdentity(async () => {
|
|
2610
|
+
const stat = fsModule === fs ? syncFs.lstatSync(pathname, { bigint: true })
|
|
2611
|
+
: await fsModule.lstat(pathname, { bigint: true });
|
|
2612
|
+
assertOwnedFile(stat, pathname, true);
|
|
2613
|
+
return stat;
|
|
2614
|
+
}, opened);
|
|
2615
|
+
}
|
|
2616
|
+
catch (error) {
|
|
2617
|
+
if (error.code === "ENOENT") {
|
|
2618
|
+
throw missingOwnedFile(pathname, error);
|
|
2619
|
+
}
|
|
2620
|
+
throw error;
|
|
2621
|
+
}
|
|
2622
|
+
}
|
|
2623
|
+
async assertPublished(fsModule, pathname, expectedHash) {
|
|
2624
|
+
try {
|
|
2625
|
+
await this.assertCurrent(fsModule, pathname);
|
|
2626
|
+
return;
|
|
2627
|
+
}
|
|
2628
|
+
catch (error) {
|
|
2629
|
+
if (!(error instanceof FsSafeError) || error.code !== "path-mismatch" || !expectedHash) {
|
|
2630
|
+
throw error;
|
|
2631
|
+
}
|
|
2632
|
+
}
|
|
2633
|
+
let published;
|
|
2634
|
+
try {
|
|
2635
|
+
try {
|
|
2636
|
+
published = await fsModule.open(pathname, PUBLISHED_READ_FLAGS);
|
|
2637
|
+
}
|
|
2638
|
+
catch (error) {
|
|
2639
|
+
if (error.code === "ELOOP") {
|
|
2640
|
+
throw new FsSafeError("symlink", `Atomic replace published file became a symlink: ${pathname}`, {
|
|
2641
|
+
cause: error,
|
|
2642
|
+
});
|
|
2643
|
+
}
|
|
2644
|
+
throw error;
|
|
2645
|
+
}
|
|
2646
|
+
const identity = await inspectFileIdentity(async () => {
|
|
2647
|
+
const stat = fsModule === fs ? syncFs.fstatSync(published.fd, { bigint: true })
|
|
2648
|
+
: await published.stat({ bigint: true });
|
|
2649
|
+
assertOwnedFile(stat, pathname, false);
|
|
2650
|
+
return stat;
|
|
2651
|
+
});
|
|
2652
|
+
await inspectFileIdentity(async () => {
|
|
2653
|
+
const stat = fsModule === fs ? syncFs.lstatSync(pathname, { bigint: true })
|
|
2654
|
+
: await fsModule.lstat(pathname, { bigint: true });
|
|
2655
|
+
assertOwnedFile(stat, pathname, true);
|
|
2656
|
+
return stat;
|
|
2657
|
+
}, identity);
|
|
2658
|
+
if (sha256Hex(await published.readFile()) !== expectedHash) {
|
|
2659
|
+
throw new FsSafeError("path-mismatch", `Atomic replace published content changed: ${pathname}`);
|
|
2660
|
+
}
|
|
2661
|
+
await this.#handle?.close();
|
|
2662
|
+
this.#handle = published;
|
|
2663
|
+
this.#identity = identity;
|
|
2664
|
+
published = undefined;
|
|
2665
|
+
}
|
|
2666
|
+
finally {
|
|
2667
|
+
await published?.close().catch(() => undefined);
|
|
2668
|
+
}
|
|
2669
|
+
}
|
|
2670
|
+
markRenamed() {
|
|
2671
|
+
this.#exists = false;
|
|
2672
|
+
this.#unregister();
|
|
2673
|
+
}
|
|
2674
|
+
async finish(params) {
|
|
2675
|
+
let deferredError;
|
|
2676
|
+
let cleanupComplete = !this.#exists;
|
|
2677
|
+
if (this.#exists) {
|
|
2678
|
+
try {
|
|
2679
|
+
cleanupComplete = await cleanupOwnedPath({
|
|
2680
|
+
fsModule: params.fsModule,
|
|
2681
|
+
pathname: this.pathname,
|
|
2682
|
+
identity: this.#identity,
|
|
2683
|
+
originalError: params.originalError,
|
|
2684
|
+
throwOnCleanupError: params.throwOnCleanupError,
|
|
2685
|
+
});
|
|
2686
|
+
}
|
|
2687
|
+
catch (error) {
|
|
2688
|
+
deferredError = error;
|
|
2689
|
+
}
|
|
2690
|
+
}
|
|
2691
|
+
if (cleanupComplete)
|
|
2692
|
+
this.#unregister();
|
|
2693
|
+
try {
|
|
2694
|
+
await this.#handle?.close();
|
|
2695
|
+
}
|
|
2696
|
+
catch (closeError) {
|
|
2697
|
+
deferredError = deferredError
|
|
2698
|
+
? new AggregateError([deferredError, closeError], "Atomic temp cleanup and close failed")
|
|
2699
|
+
: params.originalError !== undefined
|
|
2700
|
+
? new AggregateError([params.originalError, closeError], "Atomic file replace and close failed")
|
|
2701
|
+
: closeError;
|
|
2702
|
+
}
|
|
2703
|
+
if (deferredError)
|
|
2704
|
+
throw deferredError;
|
|
2705
|
+
}
|
|
2706
|
+
}
|
|
2707
|
+
class SyncAtomicTempOwner {
|
|
2708
|
+
pathname;
|
|
2709
|
+
#fd;
|
|
2710
|
+
#identity;
|
|
2711
|
+
#exists = false;
|
|
2712
|
+
#unregister;
|
|
2713
|
+
constructor(pathname) {
|
|
2714
|
+
this.pathname = pathname;
|
|
2715
|
+
this.#unregister = registerTempPathForExit(pathname, { singleLinkFile: true });
|
|
2716
|
+
}
|
|
2717
|
+
start() {
|
|
2718
|
+
this.#exists = true;
|
|
2719
|
+
}
|
|
2720
|
+
onIdentity = (identity) => {
|
|
2721
|
+
this.#identity = identity;
|
|
2722
|
+
this.#unregister.setIdentity(identity);
|
|
2723
|
+
};
|
|
2724
|
+
adopt(temp) {
|
|
2725
|
+
this.#fd = temp.fd;
|
|
2726
|
+
this.onIdentity(temp.identity);
|
|
2727
|
+
}
|
|
2728
|
+
get identity() {
|
|
2729
|
+
if (!this.#identity)
|
|
2730
|
+
throw new Error("Atomic temp owner has no identity");
|
|
2731
|
+
return this.#identity;
|
|
2732
|
+
}
|
|
2733
|
+
assertCurrent(fsModule, pathname = this.pathname) {
|
|
2734
|
+
const opened = inspectFileIdentitySync(() => {
|
|
2735
|
+
const stat = fsModule.fstatSync(this.#fd, { bigint: true });
|
|
2736
|
+
assertOwnedFile(stat, pathname, false);
|
|
2737
|
+
return stat;
|
|
2738
|
+
}, this.identity);
|
|
2739
|
+
try {
|
|
2740
|
+
inspectFileIdentitySync(() => {
|
|
2741
|
+
const stat = fsModule.lstatSync(pathname, { bigint: true });
|
|
2742
|
+
assertOwnedFile(stat, pathname, true);
|
|
2743
|
+
return stat;
|
|
2744
|
+
}, opened);
|
|
2745
|
+
}
|
|
2746
|
+
catch (error) {
|
|
2747
|
+
if (error.code === "ENOENT") {
|
|
2748
|
+
throw missingOwnedFile(pathname, error);
|
|
2749
|
+
}
|
|
2750
|
+
throw error;
|
|
2751
|
+
}
|
|
2752
|
+
}
|
|
2753
|
+
assertPublished(fsModule, pathname, expectedHash) {
|
|
2754
|
+
try {
|
|
2755
|
+
this.assertCurrent(fsModule, pathname);
|
|
2756
|
+
return;
|
|
2757
|
+
}
|
|
2758
|
+
catch (error) {
|
|
2759
|
+
if (!(error instanceof FsSafeError) || error.code !== "path-mismatch" || !expectedHash) {
|
|
2760
|
+
throw error;
|
|
2761
|
+
}
|
|
2762
|
+
}
|
|
2763
|
+
let publishedFd;
|
|
2764
|
+
try {
|
|
2765
|
+
try {
|
|
2766
|
+
publishedFd = fsModule.openSync(pathname, PUBLISHED_READ_FLAGS);
|
|
2767
|
+
}
|
|
2768
|
+
catch (error) {
|
|
2769
|
+
if (error.code === "ELOOP") {
|
|
2770
|
+
throw new FsSafeError("symlink", `Atomic replace published file became a symlink: ${pathname}`, {
|
|
2771
|
+
cause: error,
|
|
2772
|
+
});
|
|
2773
|
+
}
|
|
2774
|
+
throw error;
|
|
2775
|
+
}
|
|
2776
|
+
const identity = inspectFileIdentitySync(() => {
|
|
2777
|
+
const stat = fsModule.fstatSync(publishedFd, { bigint: true });
|
|
2778
|
+
assertOwnedFile(stat, pathname, false);
|
|
2779
|
+
return stat;
|
|
2780
|
+
});
|
|
2781
|
+
inspectFileIdentitySync(() => {
|
|
2782
|
+
const stat = fsModule.lstatSync(pathname, { bigint: true });
|
|
2783
|
+
assertOwnedFile(stat, pathname, true);
|
|
2784
|
+
return stat;
|
|
2785
|
+
}, identity);
|
|
2786
|
+
if (sha256Hex(fsModule.readFileSync(publishedFd)) !== expectedHash) {
|
|
2787
|
+
throw new FsSafeError("path-mismatch", `Atomic replace published content changed: ${pathname}`);
|
|
2788
|
+
}
|
|
2789
|
+
fsModule.closeSync(this.#fd);
|
|
2790
|
+
this.#fd = publishedFd;
|
|
2791
|
+
this.#identity = identity;
|
|
2792
|
+
publishedFd = undefined;
|
|
2793
|
+
}
|
|
2794
|
+
finally {
|
|
2795
|
+
if (publishedFd !== undefined) {
|
|
2796
|
+
try {
|
|
2797
|
+
fsModule.closeSync(publishedFd);
|
|
2798
|
+
}
|
|
2799
|
+
catch {
|
|
2800
|
+
// Best-effort close after a rejected content verification.
|
|
2801
|
+
}
|
|
2802
|
+
}
|
|
2803
|
+
}
|
|
2804
|
+
}
|
|
2805
|
+
markRenamed() {
|
|
2806
|
+
this.#exists = false;
|
|
2807
|
+
this.#unregister();
|
|
2808
|
+
}
|
|
2809
|
+
finish(params) {
|
|
2810
|
+
let deferredError;
|
|
2811
|
+
let cleanupComplete = !this.#exists;
|
|
2812
|
+
if (this.#exists) {
|
|
2813
|
+
try {
|
|
2814
|
+
cleanupComplete = cleanupOwnedPathSync({
|
|
2815
|
+
fsModule: params.fsModule,
|
|
2816
|
+
pathname: this.pathname,
|
|
2817
|
+
identity: this.#identity,
|
|
2818
|
+
originalError: params.originalError,
|
|
2819
|
+
throwOnCleanupError: params.throwOnCleanupError,
|
|
2820
|
+
});
|
|
2821
|
+
}
|
|
2822
|
+
catch (error) {
|
|
2823
|
+
deferredError = error;
|
|
2824
|
+
}
|
|
2825
|
+
}
|
|
2826
|
+
if (cleanupComplete)
|
|
2827
|
+
this.#unregister();
|
|
2828
|
+
if (this.#fd !== undefined) {
|
|
2829
|
+
try {
|
|
2830
|
+
params.fsModule.closeSync(this.#fd);
|
|
2831
|
+
}
|
|
2832
|
+
catch (closeError) {
|
|
2833
|
+
deferredError = deferredError
|
|
2834
|
+
? new AggregateError([deferredError, closeError], "Atomic temp cleanup and close failed")
|
|
2835
|
+
: params.originalError !== undefined
|
|
2836
|
+
? new AggregateError([params.originalError, closeError], "Atomic file replace and close failed")
|
|
2837
|
+
: closeError;
|
|
2838
|
+
}
|
|
2839
|
+
}
|
|
2840
|
+
if (deferredError)
|
|
2841
|
+
throw deferredError;
|
|
2842
|
+
}
|
|
2843
|
+
}
|
|
2844
|
+
|
|
2398
2845
|
;// CONCATENATED MODULE: ../../node_modules/@openclaw/fs-safe/dist/bounded-read.js
|
|
2399
2846
|
|
|
2400
2847
|
|
|
@@ -2419,11 +2866,24 @@ function appendChunk(params) {
|
|
|
2419
2866
|
params.chunks.push(Buffer.from(params.scratch.subarray(0, params.bytesRead)));
|
|
2420
2867
|
return total;
|
|
2421
2868
|
}
|
|
2422
|
-
async function readBoundedAsync(maxBytes, readChunk) {
|
|
2869
|
+
async function readBoundedAsync(maxBytes, readChunk, observeRegularFileSize) {
|
|
2423
2870
|
byte_budget_normalizeMaxBytes(maxBytes);
|
|
2424
2871
|
const chunks = [];
|
|
2425
|
-
const scratch = createScratchBuffer(maxBytes);
|
|
2426
2872
|
let total = 0;
|
|
2873
|
+
const size = observeRegularFileSize?.();
|
|
2874
|
+
if (size !== undefined) {
|
|
2875
|
+
const first = Buffer.allocUnsafe(Math.min(maxBytes, size) + 1);
|
|
2876
|
+
const bytesRead = await readChunk(first, first.length);
|
|
2877
|
+
if (bytesRead === 0)
|
|
2878
|
+
return first.subarray(0, 0);
|
|
2879
|
+
// Short reads can occur before EOF. Only accept one when a fresh fd size
|
|
2880
|
+
// observation proves we consumed at least the entire current file size.
|
|
2881
|
+
const currentSize = bytesRead < first.length ? observeRegularFileSize?.() : undefined;
|
|
2882
|
+
if (currentSize !== undefined && bytesRead >= currentSize)
|
|
2883
|
+
return first.subarray(0, bytesRead);
|
|
2884
|
+
total = appendChunk({ chunks, scratch: first, bytesRead, total, maxBytes });
|
|
2885
|
+
}
|
|
2886
|
+
const scratch = createScratchBuffer(maxBytes);
|
|
2427
2887
|
while (true) {
|
|
2428
2888
|
const length = nextReadLength(total, maxBytes, scratch.length);
|
|
2429
2889
|
const bytesRead = await readChunk(scratch, length);
|
|
@@ -2439,9 +2899,22 @@ async function readBoundedAsync(maxBytes, readChunk) {
|
|
|
2439
2899
|
* force an unbounded allocation.
|
|
2440
2900
|
*/
|
|
2441
2901
|
async function readFileHandleBounded(handle, maxBytes) {
|
|
2902
|
+
byte_budget_normalizeMaxBytes(maxBytes);
|
|
2903
|
+
const fd = "fd" in handle && typeof handle.fd === "number" ? handle.fd : undefined;
|
|
2442
2904
|
return await readBoundedAsync(maxBytes, async (scratch, length) => {
|
|
2443
2905
|
return (await handle.read(scratch, 0, length, null)).bytesRead;
|
|
2444
|
-
});
|
|
2906
|
+
}, fd === undefined ? undefined : () => regularFileSize(fd));
|
|
2907
|
+
}
|
|
2908
|
+
function regularFileSize(fd) {
|
|
2909
|
+
try {
|
|
2910
|
+
const stat = external_node_fs_namespaceObject.fstatSync(fd);
|
|
2911
|
+
return stat.isFile() && Number.isSafeInteger(stat.size) && stat.size >= 0
|
|
2912
|
+
? stat.size : undefined;
|
|
2913
|
+
}
|
|
2914
|
+
catch {
|
|
2915
|
+
// Size is only an optimization hint; retain the reader's original errors.
|
|
2916
|
+
return undefined;
|
|
2917
|
+
}
|
|
2445
2918
|
}
|
|
2446
2919
|
function readDescriptorChunk(fd, scratch, length) {
|
|
2447
2920
|
return new Promise((resolve, reject) => {
|
|
@@ -2456,9 +2929,10 @@ function readDescriptorChunk(fd, scratch, length) {
|
|
|
2456
2929
|
}
|
|
2457
2930
|
/** Async bounded read from a numeric descriptor. The caller owns the descriptor. */
|
|
2458
2931
|
async function readFileDescriptorBounded(fd, maxBytes) {
|
|
2932
|
+
normalizeMaxBytes(maxBytes);
|
|
2459
2933
|
return await readBoundedAsync(maxBytes, async (scratch, length) => {
|
|
2460
2934
|
return await readDescriptorChunk(fd, scratch, length);
|
|
2461
|
-
});
|
|
2935
|
+
}, () => regularFileSize(fd));
|
|
2462
2936
|
}
|
|
2463
2937
|
/** Sync bounded read from a numeric descriptor. The caller owns the descriptor. */
|
|
2464
2938
|
function bounded_read_readFileDescriptorBoundedSync(fd, maxBytes) {
|
|
@@ -2476,11 +2950,19 @@ function bounded_read_readFileDescriptorBoundedSync(fd, maxBytes) {
|
|
|
2476
2950
|
}
|
|
2477
2951
|
}
|
|
2478
2952
|
|
|
2953
|
+
;// CONCATENATED MODULE: external "node:os"
|
|
2954
|
+
const external_node_os_namespaceObject = __rspack_createRequire_require("node:os");
|
|
2479
2955
|
;// CONCATENATED MODULE: ../../node_modules/@openclaw/fs-safe/dist/error-detail.js
|
|
2956
|
+
|
|
2480
2957
|
const UNSAFE_ERROR_DETAIL_CHARACTERS = /[\u0000-\u001f\u007f-\u009f\u2028\u2029]/gu;
|
|
2481
2958
|
function formatErrorDetail(value) {
|
|
2482
2959
|
return value.replace(UNSAFE_ERROR_DETAIL_CHARACTERS, (character) => `\\u${character.charCodeAt(0).toString(16).padStart(4, "0")}`);
|
|
2483
2960
|
}
|
|
2961
|
+
function shortPath(value) {
|
|
2962
|
+
const home = external_node_os_namespaceObject.homedir();
|
|
2963
|
+
const shortened = value.startsWith(home) ? `~${value.slice(home.length)}` : value;
|
|
2964
|
+
return formatErrorDetail(shortened);
|
|
2965
|
+
}
|
|
2484
2966
|
|
|
2485
2967
|
;// CONCATENATED MODULE: ../../node_modules/@openclaw/fs-safe/dist/root-path-symlink.js
|
|
2486
2968
|
|
|
@@ -2488,9 +2970,9 @@ function formatErrorDetail(value) {
|
|
|
2488
2970
|
|
|
2489
2971
|
|
|
2490
2972
|
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2973
|
+
function normalizeSymlinkResolutionError(error, options) {
|
|
2974
|
+
if (isSymlinkOpenError(error) ||
|
|
2975
|
+
(options.rejectUnresolved && path_isNotFoundPathError(error))) {
|
|
2494
2976
|
throw new errors_FsSafeError("symlink", "symlink path could not be resolved", {
|
|
2495
2977
|
cause: error instanceof Error ? error : undefined,
|
|
2496
2978
|
});
|
|
@@ -2498,22 +2980,22 @@ function normalizeSymlinkResolutionError(error) {
|
|
|
2498
2980
|
if (!path_isNotFoundPathError(error))
|
|
2499
2981
|
throw error;
|
|
2500
2982
|
}
|
|
2501
|
-
async function resolveSymlinkHopPath(symlinkPath) {
|
|
2983
|
+
async function resolveSymlinkHopPath(symlinkPath, options = {}) {
|
|
2502
2984
|
try {
|
|
2503
|
-
return external_node_path_namespaceObject.resolve(
|
|
2985
|
+
return external_node_path_namespaceObject.resolve(external_node_fs_namespaceObject.realpathSync.native(symlinkPath));
|
|
2504
2986
|
}
|
|
2505
2987
|
catch (error) {
|
|
2506
|
-
normalizeSymlinkResolutionError(error);
|
|
2507
|
-
const linkTarget =
|
|
2988
|
+
normalizeSymlinkResolutionError(error, options);
|
|
2989
|
+
const linkTarget = external_node_fs_namespaceObject.readlinkSync(symlinkPath);
|
|
2508
2990
|
return resolvePathViaExistingAncestor(external_node_path_namespaceObject.resolve(external_node_path_namespaceObject.dirname(symlinkPath), linkTarget));
|
|
2509
2991
|
}
|
|
2510
2992
|
}
|
|
2511
|
-
function root_path_symlink_resolveSymlinkHopPathSync(symlinkPath) {
|
|
2993
|
+
function root_path_symlink_resolveSymlinkHopPathSync(symlinkPath, options = {}) {
|
|
2512
2994
|
try {
|
|
2513
2995
|
return path.resolve(fs.realpathSync(symlinkPath));
|
|
2514
2996
|
}
|
|
2515
2997
|
catch (error) {
|
|
2516
|
-
normalizeSymlinkResolutionError(error);
|
|
2998
|
+
normalizeSymlinkResolutionError(error, options);
|
|
2517
2999
|
const linkTarget = fs.readlinkSync(symlinkPath);
|
|
2518
3000
|
return resolvePathViaExistingAncestorSync(path.resolve(path.dirname(symlinkPath), linkTarget));
|
|
2519
3001
|
}
|
|
@@ -2596,17 +3078,6 @@ function assertSafePathPrefix(prefix, options = {}) {
|
|
|
2596
3078
|
});
|
|
2597
3079
|
}
|
|
2598
3080
|
|
|
2599
|
-
;// CONCATENATED MODULE: external "node:os"
|
|
2600
|
-
const external_node_os_namespaceObject = __rspack_createRequire_require("node:os");
|
|
2601
|
-
;// CONCATENATED MODULE: ../../node_modules/@openclaw/fs-safe/dist/short-path.js
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
function shortPath(value) {
|
|
2605
|
-
const home = external_node_os_namespaceObject.homedir();
|
|
2606
|
-
const shortened = value.startsWith(home) ? `~${value.slice(home.length)}` : value;
|
|
2607
|
-
return formatErrorDetail(shortened);
|
|
2608
|
-
}
|
|
2609
|
-
|
|
2610
3081
|
;// CONCATENATED MODULE: ../../node_modules/@openclaw/fs-safe/dist/root-path.js
|
|
2611
3082
|
|
|
2612
3083
|
|
|
@@ -2617,8 +3088,6 @@ function shortPath(value) {
|
|
|
2617
3088
|
|
|
2618
3089
|
|
|
2619
3090
|
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
3091
|
const ROOT_PATH_ALIAS_POLICIES = {
|
|
2623
3092
|
strict: Object.freeze({
|
|
2624
3093
|
allowFinalSymlinkForUnlink: false,
|
|
@@ -2629,7 +3098,7 @@ const ROOT_PATH_ALIAS_POLICIES = {
|
|
|
2629
3098
|
allowFinalHardlinkForUnlink: true,
|
|
2630
3099
|
}),
|
|
2631
3100
|
};
|
|
2632
|
-
async function
|
|
3101
|
+
async function root_path_resolveRootPath(params) {
|
|
2633
3102
|
try {
|
|
2634
3103
|
return await resolveRootPathInternal(params);
|
|
2635
3104
|
}
|
|
@@ -2730,12 +3199,6 @@ function assertNoEmbeddedDriveRelativeSegment(filePath, label) {
|
|
|
2730
3199
|
const root = external_node_path_namespaceObject.parse(filePath).root;
|
|
2731
3200
|
assertNoDriveRelativePathSegments(filePath.slice(root.length).replaceAll("\\", "/"), label);
|
|
2732
3201
|
}
|
|
2733
|
-
function isPromiseLike(value) {
|
|
2734
|
-
return Boolean(value &&
|
|
2735
|
-
(typeof value === "object" || typeof value === "function") &&
|
|
2736
|
-
"then" in value &&
|
|
2737
|
-
typeof value.then === "function");
|
|
2738
|
-
}
|
|
2739
3202
|
function createLexicalTraversalState(params) {
|
|
2740
3203
|
const rawAbsolutePath = params.params.absolutePath;
|
|
2741
3204
|
const rawRelativePath = rawPathRelativeToRoot(params.rootPath, rawAbsolutePath);
|
|
@@ -2815,26 +3278,13 @@ function handleLexicalLstatFailure(context, error, missingFromIndex) {
|
|
|
2815
3278
|
applyMissingSuffixToCanonicalCursor(context, missingFromIndex);
|
|
2816
3279
|
return true;
|
|
2817
3280
|
}
|
|
2818
|
-
function
|
|
2819
|
-
if (
|
|
2820
|
-
return null;
|
|
2821
|
-
}
|
|
2822
|
-
throw error;
|
|
2823
|
-
}
|
|
2824
|
-
function handleLexicalStatDisposition(context, params) {
|
|
2825
|
-
if (!params.isSymbolicLink) {
|
|
2826
|
-
advanceCanonicalCursorForSegment(context, params.segment);
|
|
3281
|
+
function lexicalStatDisposition(params) {
|
|
3282
|
+
if (!params.isSymbolicLink)
|
|
2827
3283
|
return "continue";
|
|
2828
|
-
|
|
2829
|
-
if (context.resolveParams.rejectSymlinks === true && params.isLast) {
|
|
3284
|
+
if (params.rejectSymlinks === true && params.isLast) {
|
|
2830
3285
|
throw new errors_FsSafeError("symlink", "symlink path component not allowed");
|
|
2831
3286
|
}
|
|
2832
|
-
|
|
2833
|
-
context.state.preserveFinalSymlink = true;
|
|
2834
|
-
advanceCanonicalCursorForSegment(context, params.segment);
|
|
2835
|
-
return "break";
|
|
2836
|
-
}
|
|
2837
|
-
return "resolve-link";
|
|
3287
|
+
return params.allowFinalSymlink && params.isLast ? "break" : "resolve-link";
|
|
2838
3288
|
}
|
|
2839
3289
|
function applyResolvedSymlinkHop(context, linkCanonical) {
|
|
2840
3290
|
if (!path_isPathInside(context.rootCanonicalPath, linkCanonical)) {
|
|
@@ -2847,68 +3297,48 @@ function applyResolvedSymlinkHop(context, linkCanonical) {
|
|
|
2847
3297
|
context.state.canonicalCursor = linkCanonical;
|
|
2848
3298
|
context.state.lexicalCursor = linkCanonical;
|
|
2849
3299
|
}
|
|
2850
|
-
function readLexicalStat(context, params) {
|
|
2851
|
-
try {
|
|
2852
|
-
const stat = params.read(context.state.lexicalCursor);
|
|
2853
|
-
if (isPromiseLike(stat)) {
|
|
2854
|
-
return Promise.resolve(stat).catch((error) => handleLexicalStatReadFailure(context, error, params.missingFromIndex));
|
|
2855
|
-
}
|
|
2856
|
-
return stat;
|
|
2857
|
-
}
|
|
2858
|
-
catch (error) {
|
|
2859
|
-
return handleLexicalStatReadFailure(context, error, params.missingFromIndex);
|
|
2860
|
-
}
|
|
2861
|
-
}
|
|
2862
|
-
function resolveAndApplySymlinkHop(context, params) {
|
|
2863
|
-
const linkCanonical = params.resolveLinkCanonical(context.state.lexicalCursor);
|
|
2864
|
-
if (isPromiseLike(linkCanonical)) {
|
|
2865
|
-
return Promise.resolve(linkCanonical).then((value) => {
|
|
2866
|
-
applyResolvedSymlinkHop(context, value);
|
|
2867
|
-
});
|
|
2868
|
-
}
|
|
2869
|
-
applyResolvedSymlinkHop(context, linkCanonical);
|
|
2870
|
-
}
|
|
2871
3300
|
function applyParentTraversalStep(context) {
|
|
2872
3301
|
context.state.lexicalCursor = external_node_path_namespaceObject.resolve(context.state.lexicalCursor, "..");
|
|
2873
3302
|
advanceCanonicalCursorForSegment(context, "..");
|
|
2874
3303
|
}
|
|
2875
|
-
function* iterateLexicalTraversal(state) {
|
|
2876
|
-
for (let idx = 0; idx < state.segments.length; idx += 1) {
|
|
2877
|
-
const segment = state.segments[idx] ?? "";
|
|
2878
|
-
const isLast = idx === state.segments.length - 1;
|
|
2879
|
-
yield { idx, segment, isLast };
|
|
2880
|
-
}
|
|
2881
|
-
}
|
|
2882
3304
|
async function resolveRootPathLexicalAsync(params) {
|
|
2883
3305
|
const context = createLexicalTraversalContext(params);
|
|
2884
3306
|
const { state } = context;
|
|
2885
|
-
for (
|
|
3307
|
+
for (let idx = 0; idx < state.segments.length; idx += 1) {
|
|
3308
|
+
const segment = state.segments[idx] ?? "";
|
|
3309
|
+
const isLast = idx === state.segments.length - 1;
|
|
2886
3310
|
if (segment === "..") {
|
|
2887
3311
|
applyParentTraversalStep(context);
|
|
2888
3312
|
continue;
|
|
2889
3313
|
}
|
|
2890
3314
|
state.lexicalCursor = external_node_path_namespaceObject.join(state.lexicalCursor, segment);
|
|
2891
|
-
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
}
|
|
2895
|
-
|
|
2896
|
-
|
|
3315
|
+
let stat;
|
|
3316
|
+
try {
|
|
3317
|
+
stat = external_node_fs_namespaceObject.lstatSync(state.lexicalCursor);
|
|
3318
|
+
}
|
|
3319
|
+
catch (error) {
|
|
3320
|
+
if (handleLexicalLstatFailure(context, error, idx))
|
|
3321
|
+
break;
|
|
3322
|
+
throw error;
|
|
2897
3323
|
}
|
|
2898
|
-
const
|
|
2899
|
-
|
|
2900
|
-
|
|
3324
|
+
const isSymbolicLink = stat.isSymbolicLink();
|
|
3325
|
+
const disposition = lexicalStatDisposition({
|
|
3326
|
+
isSymbolicLink,
|
|
2901
3327
|
isLast,
|
|
3328
|
+
rejectSymlinks: isSymbolicLink ? context.resolveParams.rejectSymlinks : undefined,
|
|
3329
|
+
allowFinalSymlink: state.allowFinalSymlink,
|
|
2902
3330
|
});
|
|
2903
|
-
if (disposition
|
|
3331
|
+
if (disposition !== "resolve-link") {
|
|
3332
|
+
state.preserveFinalSymlink = disposition === "break";
|
|
3333
|
+
advanceCanonicalCursorForSegment(context, segment);
|
|
3334
|
+
if (state.preserveFinalSymlink)
|
|
3335
|
+
break;
|
|
2904
3336
|
continue;
|
|
2905
3337
|
}
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
}
|
|
2909
|
-
await resolveAndApplySymlinkHop(context, {
|
|
2910
|
-
resolveLinkCanonical: (cursor) => resolveSymlinkHopPath(cursor),
|
|
3338
|
+
const linkCanonical = await resolveSymlinkHopPath(state.lexicalCursor, {
|
|
3339
|
+
rejectUnresolved: context.resolveParams.rejectUnresolvedSymlinks,
|
|
2911
3340
|
});
|
|
3341
|
+
applyResolvedSymlinkHop(context, linkCanonical);
|
|
2912
3342
|
if (context.resolveParams.rejectSymlinks === true) {
|
|
2913
3343
|
throw new errors_FsSafeError("symlink", "symlink path component not allowed");
|
|
2914
3344
|
}
|
|
@@ -2927,34 +3357,33 @@ function resolveRootPathLexicalSync(params) {
|
|
|
2927
3357
|
continue;
|
|
2928
3358
|
}
|
|
2929
3359
|
state.lexicalCursor = path.join(state.lexicalCursor, segment);
|
|
2930
|
-
|
|
2931
|
-
|
|
2932
|
-
|
|
2933
|
-
});
|
|
2934
|
-
if (isPromiseLike(maybeStat)) {
|
|
2935
|
-
throw new Error("Unexpected async lexical stat");
|
|
3360
|
+
let stat;
|
|
3361
|
+
try {
|
|
3362
|
+
stat = fs.lstatSync(state.lexicalCursor);
|
|
2936
3363
|
}
|
|
2937
|
-
|
|
2938
|
-
|
|
2939
|
-
|
|
3364
|
+
catch (error) {
|
|
3365
|
+
if (handleLexicalLstatFailure(context, error, idx))
|
|
3366
|
+
break;
|
|
3367
|
+
throw error;
|
|
2940
3368
|
}
|
|
2941
|
-
const
|
|
2942
|
-
|
|
2943
|
-
|
|
3369
|
+
const isSymbolicLink = stat.isSymbolicLink();
|
|
3370
|
+
const disposition = lexicalStatDisposition({
|
|
3371
|
+
isSymbolicLink,
|
|
2944
3372
|
isLast,
|
|
3373
|
+
rejectSymlinks: isSymbolicLink ? context.resolveParams.rejectSymlinks : undefined,
|
|
3374
|
+
allowFinalSymlink: state.allowFinalSymlink,
|
|
2945
3375
|
});
|
|
2946
|
-
if (disposition
|
|
3376
|
+
if (disposition !== "resolve-link") {
|
|
3377
|
+
state.preserveFinalSymlink = disposition === "break";
|
|
3378
|
+
advanceCanonicalCursorForSegment(context, segment);
|
|
3379
|
+
if (state.preserveFinalSymlink)
|
|
3380
|
+
break;
|
|
2947
3381
|
continue;
|
|
2948
3382
|
}
|
|
2949
|
-
|
|
2950
|
-
|
|
2951
|
-
}
|
|
2952
|
-
const maybeApplied = resolveAndApplySymlinkHop(context, {
|
|
2953
|
-
resolveLinkCanonical: (cursor) => resolveSymlinkHopPathSync(cursor),
|
|
3383
|
+
const linkCanonical = resolveSymlinkHopPathSync(state.lexicalCursor, {
|
|
3384
|
+
rejectUnresolved: context.resolveParams.rejectUnresolvedSymlinks,
|
|
2954
3385
|
});
|
|
2955
|
-
|
|
2956
|
-
throw new Error("Unexpected async symlink resolution");
|
|
2957
|
-
}
|
|
3386
|
+
applyResolvedSymlinkHop(context, linkCanonical);
|
|
2958
3387
|
if (context.resolveParams.rejectSymlinks === true) {
|
|
2959
3388
|
throw new FsSafeError("symlink", "symlink path component not allowed");
|
|
2960
3389
|
}
|
|
@@ -3074,8 +3503,8 @@ function buildResolvedRootPath(params) {
|
|
|
3074
3503
|
async function getPathKind(absolutePath, preserveFinalSymlink) {
|
|
3075
3504
|
try {
|
|
3076
3505
|
const stat = preserveFinalSymlink
|
|
3077
|
-
?
|
|
3078
|
-
:
|
|
3506
|
+
? external_node_fs_namespaceObject.lstatSync(absolutePath)
|
|
3507
|
+
: external_node_fs_namespaceObject.statSync(absolutePath);
|
|
3079
3508
|
return { exists: true, kind: toResolvedKind(stat) };
|
|
3080
3509
|
}
|
|
3081
3510
|
catch (error) {
|
|
@@ -3141,7 +3570,7 @@ function symlinkEscapeError(params) {
|
|
|
3141
3570
|
|
|
3142
3571
|
async function openSidecarRoot(lockRoot, relative, discardObservation, onOpenFailure) {
|
|
3143
3572
|
const resolved = await lockRoot.resolve(relative);
|
|
3144
|
-
const canonicalPath = async () => (await
|
|
3573
|
+
const canonicalPath = async () => (await root_path_resolveRootPath({
|
|
3145
3574
|
absolutePath: resolved,
|
|
3146
3575
|
rootPath: lockRoot.rootReal,
|
|
3147
3576
|
rootCanonicalPath: lockRoot.rootReal,
|
|
@@ -3258,10 +3687,12 @@ function readSidecarLockOwnershipToken(raw) {
|
|
|
3258
3687
|
}
|
|
3259
3688
|
function serializeSidecarLockPayload(payload) {
|
|
3260
3689
|
const ownershipToken = createSidecarLockOwnershipToken();
|
|
3261
|
-
|
|
3262
|
-
|
|
3263
|
-
|
|
3264
|
-
|
|
3690
|
+
const raw = `${JSON.stringify(payload, null, 2)}\n${ownershipToken}\n`;
|
|
3691
|
+
const bytes = Buffer.byteLength(raw, "utf8");
|
|
3692
|
+
if (bytes > MAX_LOCK_PAYLOAD_BYTES) {
|
|
3693
|
+
throw new errors_FsSafeError("too-large", `sidecar lock payload exceeds limit of ${MAX_LOCK_PAYLOAD_BYTES} bytes (got ${bytes})`);
|
|
3694
|
+
}
|
|
3695
|
+
return { raw, ownershipToken };
|
|
3265
3696
|
}
|
|
3266
3697
|
function relativeSidecarLockPath(lockRoot, lockPath) {
|
|
3267
3698
|
const resolved = external_node_path_namespaceObject.resolve(lockPath);
|
|
@@ -3316,7 +3747,13 @@ async function readSidecarLockRawSnapshot(lockPath, options = {}) {
|
|
|
3316
3747
|
await opened.handle.close().catch(() => undefined);
|
|
3317
3748
|
}
|
|
3318
3749
|
}
|
|
3319
|
-
|
|
3750
|
+
let before;
|
|
3751
|
+
try {
|
|
3752
|
+
before = external_node_fs_namespaceObject.lstatSync(lockPath);
|
|
3753
|
+
}
|
|
3754
|
+
catch (error) {
|
|
3755
|
+
before = missingSnapshotPath(error);
|
|
3756
|
+
}
|
|
3320
3757
|
if (!before)
|
|
3321
3758
|
return null;
|
|
3322
3759
|
if (!before.isFile() || before.isSymbolicLink()) {
|
|
@@ -3345,7 +3782,7 @@ async function readSidecarLockRawSnapshot(lockPath, options = {}) {
|
|
|
3345
3782
|
options.onOpenFailure?.(error);
|
|
3346
3783
|
throw error;
|
|
3347
3784
|
}
|
|
3348
|
-
const opened =
|
|
3785
|
+
const opened = external_node_fs_namespaceObject.fstatSync(handle.fd);
|
|
3349
3786
|
if (!opened.isFile()) {
|
|
3350
3787
|
if (options.rejectNonFile) {
|
|
3351
3788
|
throw new errors_FsSafeError("not-file", `sidecar lock is not a regular file: ${lockPath}`);
|
|
@@ -3355,7 +3792,13 @@ async function readSidecarLockRawSnapshot(lockPath, options = {}) {
|
|
|
3355
3792
|
if (!options.allowDescriptorIdentityDrift && !file_identity_sameFileIdentity(before, opened))
|
|
3356
3793
|
return null;
|
|
3357
3794
|
const raw = (await readFileHandleBounded(handle, MAX_LOCK_PAYLOAD_BYTES)).toString("utf8");
|
|
3358
|
-
|
|
3795
|
+
let after;
|
|
3796
|
+
try {
|
|
3797
|
+
after = external_node_fs_namespaceObject.lstatSync(lockPath);
|
|
3798
|
+
}
|
|
3799
|
+
catch (error) {
|
|
3800
|
+
after = missingSnapshotPath(error);
|
|
3801
|
+
}
|
|
3359
3802
|
if (!after || !after.isFile() || !file_identity_sameFileIdentity(before, after))
|
|
3360
3803
|
return null;
|
|
3361
3804
|
return { raw, stat: after };
|
|
@@ -3465,69 +3908,378 @@ async function sidecarLockSnapshotStillPresent(lockPath, observed, options = {})
|
|
|
3465
3908
|
});
|
|
3466
3909
|
return !!current && !!observed && sidecarLockSnapshotMatches(current, observed);
|
|
3467
3910
|
}
|
|
3468
|
-
async function sidecarReclaimGuardExists(pathname) {
|
|
3911
|
+
async function sidecarReclaimGuardExists(pathname) {
|
|
3912
|
+
try {
|
|
3913
|
+
external_node_fs_namespaceObject.lstatSync(pathname);
|
|
3914
|
+
return true;
|
|
3915
|
+
}
|
|
3916
|
+
catch (err) {
|
|
3917
|
+
if (err.code === "ENOENT") {
|
|
3918
|
+
return false;
|
|
3919
|
+
}
|
|
3920
|
+
throw err;
|
|
3921
|
+
}
|
|
3922
|
+
}
|
|
3923
|
+
async function tryAcquireSidecarReclaimGuard(reclaimGuards, reclaimGuardPath) {
|
|
3924
|
+
try {
|
|
3925
|
+
await promises_namespaceObject.mkdir(reclaimGuardPath);
|
|
3926
|
+
reclaimGuards.add(reclaimGuardPath);
|
|
3927
|
+
return true;
|
|
3928
|
+
}
|
|
3929
|
+
catch (err) {
|
|
3930
|
+
if (err.code === "EEXIST") {
|
|
3931
|
+
return false;
|
|
3932
|
+
}
|
|
3933
|
+
throw err;
|
|
3934
|
+
}
|
|
3935
|
+
}
|
|
3936
|
+
async function releaseSidecarReclaimGuard(reclaimGuards, reclaimGuardPath) {
|
|
3937
|
+
await promises_namespaceObject.rmdir(reclaimGuardPath);
|
|
3938
|
+
reclaimGuards.delete(reclaimGuardPath);
|
|
3939
|
+
}
|
|
3940
|
+
async function removeStaleSidecarLockIfAllowed(params) {
|
|
3941
|
+
if (!params.shouldRemoveStaleLock || params.snapshot.raw === undefined) {
|
|
3942
|
+
return "not-approved";
|
|
3943
|
+
}
|
|
3944
|
+
const ioOptions = { lockRoot: params.lockRoot, parsePayload: params.parsePayload };
|
|
3945
|
+
if (!(await sidecarLockSnapshotStillPresent(params.lockPath, params.snapshot, ioOptions))) {
|
|
3946
|
+
return "changed";
|
|
3947
|
+
}
|
|
3948
|
+
if (!(await params.shouldRemoveStaleLock({
|
|
3949
|
+
lockPath: params.lockPath,
|
|
3950
|
+
normalizedTargetPath: params.normalizedTargetPath,
|
|
3951
|
+
raw: params.snapshot.raw,
|
|
3952
|
+
payload: params.snapshot.payload,
|
|
3953
|
+
}))) {
|
|
3954
|
+
return "not-approved";
|
|
3955
|
+
}
|
|
3956
|
+
if (!(await sidecarLockSnapshotStillPresent(params.lockPath, params.snapshot, ioOptions))) {
|
|
3957
|
+
return "changed";
|
|
3958
|
+
}
|
|
3959
|
+
try {
|
|
3960
|
+
if (params.lockRoot) {
|
|
3961
|
+
await params.lockRoot.remove(relativeSidecarLockPath(params.lockRoot, params.lockPath));
|
|
3962
|
+
}
|
|
3963
|
+
else {
|
|
3964
|
+
await promises_namespaceObject.rm(params.lockPath);
|
|
3965
|
+
}
|
|
3966
|
+
return "removed";
|
|
3967
|
+
}
|
|
3968
|
+
catch (err) {
|
|
3969
|
+
if (err.code === "ENOENT") {
|
|
3970
|
+
return "changed";
|
|
3971
|
+
}
|
|
3972
|
+
throw err;
|
|
3973
|
+
}
|
|
3974
|
+
}
|
|
3975
|
+
|
|
3976
|
+
;// CONCATENATED MODULE: ../../node_modules/@openclaw/fs-safe/dist/absolute-path.js
|
|
3977
|
+
|
|
3978
|
+
|
|
3979
|
+
|
|
3980
|
+
|
|
3981
|
+
|
|
3982
|
+
|
|
3983
|
+
|
|
3984
|
+
function resolveSymlinkPolicy(policy) {
|
|
3985
|
+
if (policy === undefined)
|
|
3986
|
+
return "reject";
|
|
3987
|
+
if (policy !== "reject" && policy !== "follow") {
|
|
3988
|
+
throw new TypeError(`invalid absolute path symlink policy: ${String(policy)}`);
|
|
3989
|
+
}
|
|
3990
|
+
return policy;
|
|
3991
|
+
}
|
|
3992
|
+
function ensureDirectoryFailure(code, message, cause) {
|
|
3993
|
+
return {
|
|
3994
|
+
ok: false,
|
|
3995
|
+
code,
|
|
3996
|
+
error: new FsSafeError(code, message, { cause }),
|
|
3997
|
+
};
|
|
3998
|
+
}
|
|
3999
|
+
async function assertGuardResult(guard, scopeLabel) {
|
|
4000
|
+
try {
|
|
4001
|
+
await assertAsyncDirectoryGuard(guard);
|
|
4002
|
+
return { ok: true };
|
|
4003
|
+
}
|
|
4004
|
+
catch (err) {
|
|
4005
|
+
if (err instanceof FsSafeError) {
|
|
4006
|
+
return await directoryGuardFailure(err, guard.dir, scopeLabel);
|
|
4007
|
+
}
|
|
4008
|
+
throw err;
|
|
4009
|
+
}
|
|
4010
|
+
}
|
|
4011
|
+
async function createDirectoryGuardResult(dir, scopeLabel) {
|
|
4012
|
+
try {
|
|
4013
|
+
return { ok: true, guard: await createAsyncDirectoryGuard(dir) };
|
|
4014
|
+
}
|
|
4015
|
+
catch (err) {
|
|
4016
|
+
if (err instanceof FsSafeError) {
|
|
4017
|
+
return await directoryGuardFailure(err, dir, scopeLabel);
|
|
4018
|
+
}
|
|
4019
|
+
throw err;
|
|
4020
|
+
}
|
|
4021
|
+
}
|
|
4022
|
+
function classifyDirectoryLookupError(err, scopeLabel) {
|
|
4023
|
+
const code = err.code;
|
|
4024
|
+
if (code === "ENOENT") {
|
|
4025
|
+
return ensureDirectoryFailure("not-found", `directory path must have a real existing ancestor within ${scopeLabel}`, err);
|
|
4026
|
+
}
|
|
4027
|
+
if (code === "ENOTDIR") {
|
|
4028
|
+
return ensureDirectoryFailure("not-file", `path must be a real directory within ${scopeLabel}`, err);
|
|
4029
|
+
}
|
|
4030
|
+
return null;
|
|
4031
|
+
}
|
|
4032
|
+
function classifyExistingDirectorySegment(stat, scopeLabel) {
|
|
4033
|
+
if (stat.isSymbolicLink()) {
|
|
4034
|
+
return ensureDirectoryFailure("symlink", `directory path traverses a symlink within ${scopeLabel}`);
|
|
4035
|
+
}
|
|
4036
|
+
if (!stat.isDirectory()) {
|
|
4037
|
+
return ensureDirectoryFailure("not-file", `path must be a real directory within ${scopeLabel}`);
|
|
4038
|
+
}
|
|
4039
|
+
return null;
|
|
4040
|
+
}
|
|
4041
|
+
async function directoryGuardFailure(err, dir, scopeLabel) {
|
|
4042
|
+
if (err.code !== "not-file") {
|
|
4043
|
+
return { ok: false, code: err.code, error: err };
|
|
4044
|
+
}
|
|
4045
|
+
try {
|
|
4046
|
+
const stat = fsSync.lstatSync(dir);
|
|
4047
|
+
const failure = classifyExistingDirectorySegment(stat, scopeLabel);
|
|
4048
|
+
if (failure) {
|
|
4049
|
+
return failure;
|
|
4050
|
+
}
|
|
4051
|
+
}
|
|
4052
|
+
catch (lookupErr) {
|
|
4053
|
+
const failure = classifyDirectoryLookupError(lookupErr, scopeLabel);
|
|
4054
|
+
if (failure) {
|
|
4055
|
+
return failure;
|
|
4056
|
+
}
|
|
4057
|
+
throw lookupErr;
|
|
4058
|
+
}
|
|
4059
|
+
return { ok: false, code: err.code, error: err };
|
|
4060
|
+
}
|
|
4061
|
+
async function resolveTrustedDirectoryPrefix(targetPath, scopeLabel) {
|
|
4062
|
+
const root = path.parse(targetPath).root;
|
|
4063
|
+
let current = root;
|
|
4064
|
+
let currentStat;
|
|
4065
|
+
try {
|
|
4066
|
+
currentStat = fsSync.lstatSync(current);
|
|
4067
|
+
}
|
|
4068
|
+
catch (err) {
|
|
4069
|
+
const failure = classifyDirectoryLookupError(err, scopeLabel);
|
|
4070
|
+
if (failure) {
|
|
4071
|
+
return failure;
|
|
4072
|
+
}
|
|
4073
|
+
throw err;
|
|
4074
|
+
}
|
|
4075
|
+
const rootFailure = classifyExistingDirectorySegment(currentStat, scopeLabel);
|
|
4076
|
+
if (rootFailure) {
|
|
4077
|
+
return rootFailure;
|
|
4078
|
+
}
|
|
4079
|
+
// Walk forward with lstat. Looking backward for the "nearest existing
|
|
4080
|
+
// ancestor" can cross an existing suffix through a symlinked parent before
|
|
4081
|
+
// this helper gets a chance to reject that parent.
|
|
4082
|
+
const segments = path.relative(root, targetPath).split(path.sep).filter(Boolean);
|
|
4083
|
+
for (let index = 0; index < segments.length; index += 1) {
|
|
4084
|
+
const segment = segments[index];
|
|
4085
|
+
if (!segment) {
|
|
4086
|
+
continue;
|
|
4087
|
+
}
|
|
4088
|
+
const next = path.join(current, segment);
|
|
4089
|
+
try {
|
|
4090
|
+
const nextStat = fsSync.lstatSync(next);
|
|
4091
|
+
const segmentFailure = classifyExistingDirectorySegment(nextStat, scopeLabel);
|
|
4092
|
+
if (segmentFailure) {
|
|
4093
|
+
return segmentFailure;
|
|
4094
|
+
}
|
|
4095
|
+
current = next;
|
|
4096
|
+
currentStat = nextStat;
|
|
4097
|
+
}
|
|
4098
|
+
catch (err) {
|
|
4099
|
+
const code = err.code;
|
|
4100
|
+
if (code === "ENOENT") {
|
|
4101
|
+
return {
|
|
4102
|
+
ok: true,
|
|
4103
|
+
ancestorPath: current,
|
|
4104
|
+
missingSegments: segments.slice(index),
|
|
4105
|
+
};
|
|
4106
|
+
}
|
|
4107
|
+
const failure = classifyDirectoryLookupError(err, scopeLabel);
|
|
4108
|
+
if (failure) {
|
|
4109
|
+
return failure;
|
|
4110
|
+
}
|
|
4111
|
+
throw err;
|
|
4112
|
+
}
|
|
4113
|
+
}
|
|
4114
|
+
return { ok: true, ancestorPath: current, missingSegments: [] };
|
|
4115
|
+
}
|
|
4116
|
+
function assertAbsolutePathInput(filePath) {
|
|
4117
|
+
if (!filePath) {
|
|
4118
|
+
throw new FsSafeError("invalid-path", "path is required");
|
|
4119
|
+
}
|
|
4120
|
+
if (filePath.includes("\0")) {
|
|
4121
|
+
throw new FsSafeError("invalid-path", "path must not contain NUL bytes");
|
|
4122
|
+
}
|
|
4123
|
+
if (!path.isAbsolute(filePath)) {
|
|
4124
|
+
throw new FsSafeError("invalid-path", "path must be absolute");
|
|
4125
|
+
}
|
|
4126
|
+
return path.normalize(filePath);
|
|
4127
|
+
}
|
|
4128
|
+
async function findExistingAncestor(filePath) {
|
|
4129
|
+
return (await findExistingAncestorWithStat(filePath))?.path ?? null;
|
|
4130
|
+
}
|
|
4131
|
+
async function findExistingAncestorWithStat(filePath) {
|
|
4132
|
+
let current = external_node_path_namespaceObject.resolve(filePath);
|
|
4133
|
+
while (true) {
|
|
4134
|
+
try {
|
|
4135
|
+
return { path: current, stat: external_node_fs_namespaceObject.lstatSync(current) };
|
|
4136
|
+
}
|
|
4137
|
+
catch (err) {
|
|
4138
|
+
if (err.code !== "ENOENT") {
|
|
4139
|
+
throw err;
|
|
4140
|
+
}
|
|
4141
|
+
}
|
|
4142
|
+
const parent = external_node_path_namespaceObject.dirname(current);
|
|
4143
|
+
if (parent === current) {
|
|
4144
|
+
return null;
|
|
4145
|
+
}
|
|
4146
|
+
current = parent;
|
|
4147
|
+
}
|
|
4148
|
+
}
|
|
4149
|
+
async function absolute_path_ensureAbsoluteDirectory(dirPath, options = {}) {
|
|
4150
|
+
const scopeLabel = options.scopeLabel ?? "directory";
|
|
4151
|
+
let targetPath;
|
|
3469
4152
|
try {
|
|
3470
|
-
|
|
3471
|
-
return true;
|
|
4153
|
+
targetPath = assertAbsolutePathInput(dirPath);
|
|
3472
4154
|
}
|
|
3473
4155
|
catch (err) {
|
|
3474
|
-
if (err
|
|
3475
|
-
return false;
|
|
4156
|
+
if (err instanceof FsSafeError) {
|
|
4157
|
+
return { ok: false, code: err.code, error: err };
|
|
3476
4158
|
}
|
|
3477
4159
|
throw err;
|
|
3478
4160
|
}
|
|
3479
|
-
|
|
3480
|
-
|
|
3481
|
-
|
|
3482
|
-
await promises_namespaceObject.mkdir(reclaimGuardPath);
|
|
3483
|
-
reclaimGuards.add(reclaimGuardPath);
|
|
3484
|
-
return true;
|
|
4161
|
+
const prefix = await resolveTrustedDirectoryPrefix(targetPath, scopeLabel);
|
|
4162
|
+
if (!prefix.ok) {
|
|
4163
|
+
return prefix;
|
|
3485
4164
|
}
|
|
3486
|
-
|
|
3487
|
-
|
|
3488
|
-
|
|
4165
|
+
let current = prefix.ancestorPath;
|
|
4166
|
+
const initialGuard = await createDirectoryGuardResult(prefix.ancestorPath, scopeLabel);
|
|
4167
|
+
if (!initialGuard.ok) {
|
|
4168
|
+
return initialGuard;
|
|
4169
|
+
}
|
|
4170
|
+
let currentGuard = initialGuard.guard;
|
|
4171
|
+
for (const segment of prefix.missingSegments) {
|
|
4172
|
+
current = path.join(current, segment);
|
|
4173
|
+
while (true) {
|
|
4174
|
+
const guardResult = await assertGuardResult(currentGuard, scopeLabel);
|
|
4175
|
+
if (!guardResult.ok) {
|
|
4176
|
+
return guardResult;
|
|
4177
|
+
}
|
|
4178
|
+
try {
|
|
4179
|
+
const stat = fsSync.lstatSync(current);
|
|
4180
|
+
if (stat.isSymbolicLink()) {
|
|
4181
|
+
return ensureDirectoryFailure("symlink", `directory path traverses a symlink within ${scopeLabel}`);
|
|
4182
|
+
}
|
|
4183
|
+
if (!stat.isDirectory()) {
|
|
4184
|
+
return ensureDirectoryFailure("not-file", `path must be a real directory within ${scopeLabel}`);
|
|
4185
|
+
}
|
|
4186
|
+
break;
|
|
4187
|
+
}
|
|
4188
|
+
catch (err) {
|
|
4189
|
+
if (err.code !== "ENOENT") {
|
|
4190
|
+
throw err;
|
|
4191
|
+
}
|
|
4192
|
+
const parentStillValid = await assertGuardResult(currentGuard, scopeLabel);
|
|
4193
|
+
if (!parentStillValid.ok) {
|
|
4194
|
+
return parentStillValid;
|
|
4195
|
+
}
|
|
4196
|
+
try {
|
|
4197
|
+
await fs.mkdir(current, { mode: options.mode });
|
|
4198
|
+
}
|
|
4199
|
+
catch (mkdirErr) {
|
|
4200
|
+
if (mkdirErr.code === "EEXIST") {
|
|
4201
|
+
continue;
|
|
4202
|
+
}
|
|
4203
|
+
throw mkdirErr;
|
|
4204
|
+
}
|
|
4205
|
+
}
|
|
3489
4206
|
}
|
|
3490
|
-
|
|
4207
|
+
const nextGuard = await createDirectoryGuardResult(current, scopeLabel);
|
|
4208
|
+
if (!nextGuard.ok) {
|
|
4209
|
+
return nextGuard;
|
|
4210
|
+
}
|
|
4211
|
+
const previousGuardStillValid = await assertGuardResult(currentGuard, scopeLabel);
|
|
4212
|
+
if (!previousGuardStillValid.ok) {
|
|
4213
|
+
return previousGuardStillValid;
|
|
4214
|
+
}
|
|
4215
|
+
currentGuard = nextGuard.guard;
|
|
3491
4216
|
}
|
|
3492
|
-
|
|
3493
|
-
|
|
3494
|
-
|
|
3495
|
-
reclaimGuards.delete(reclaimGuardPath);
|
|
3496
|
-
}
|
|
3497
|
-
async function removeStaleSidecarLockIfAllowed(params) {
|
|
3498
|
-
if (!params.shouldRemoveStaleLock || params.snapshot.raw === undefined) {
|
|
3499
|
-
return "not-approved";
|
|
4217
|
+
const finalGuardResult = await assertGuardResult(currentGuard, scopeLabel);
|
|
4218
|
+
if (!finalGuardResult.ok) {
|
|
4219
|
+
return finalGuardResult;
|
|
3500
4220
|
}
|
|
3501
|
-
|
|
3502
|
-
|
|
3503
|
-
|
|
4221
|
+
return { ok: true, path: targetPath };
|
|
4222
|
+
}
|
|
4223
|
+
async function canonicalPathFromExistingAncestor(filePath) {
|
|
4224
|
+
const ancestor = await findExistingAncestor(filePath);
|
|
4225
|
+
if (!ancestor) {
|
|
4226
|
+
return external_node_path_namespaceObject.resolve(filePath);
|
|
3504
4227
|
}
|
|
3505
|
-
|
|
3506
|
-
|
|
3507
|
-
|
|
3508
|
-
raw: params.snapshot.raw,
|
|
3509
|
-
payload: params.snapshot.payload,
|
|
3510
|
-
}))) {
|
|
3511
|
-
return "not-approved";
|
|
4228
|
+
let canonicalAncestor = ancestor;
|
|
4229
|
+
try {
|
|
4230
|
+
canonicalAncestor = external_node_fs_namespaceObject.realpathSync.native(ancestor);
|
|
3512
4231
|
}
|
|
3513
|
-
|
|
3514
|
-
|
|
4232
|
+
catch {
|
|
4233
|
+
// Keep lexical path when the existing ancestor cannot be canonicalized.
|
|
3515
4234
|
}
|
|
4235
|
+
const relative = external_node_path_namespaceObject.relative(ancestor, filePath);
|
|
4236
|
+
return relative ? external_node_path_namespaceObject.join(canonicalAncestor, relative) : canonicalAncestor;
|
|
4237
|
+
}
|
|
4238
|
+
async function resolveAbsolutePathForRead(filePath, options = {}) {
|
|
4239
|
+
const symlinks = resolveSymlinkPolicy(options.symlinks);
|
|
4240
|
+
const normalized = assertAbsolutePathInput(filePath);
|
|
4241
|
+
let canonicalPath;
|
|
3516
4242
|
try {
|
|
3517
|
-
|
|
3518
|
-
await params.lockRoot.remove(relativeSidecarLockPath(params.lockRoot, params.lockPath));
|
|
3519
|
-
}
|
|
3520
|
-
else {
|
|
3521
|
-
await promises_namespaceObject.rm(params.lockPath);
|
|
3522
|
-
}
|
|
3523
|
-
return "removed";
|
|
4243
|
+
canonicalPath = fsSync.realpathSync.native(normalized);
|
|
3524
4244
|
}
|
|
3525
4245
|
catch (err) {
|
|
3526
4246
|
if (err.code === "ENOENT") {
|
|
3527
|
-
|
|
4247
|
+
throw new FsSafeError("not-found", "path not found", { cause: err });
|
|
3528
4248
|
}
|
|
3529
4249
|
throw err;
|
|
3530
4250
|
}
|
|
4251
|
+
if (symlinks === "reject" && canonicalPath !== normalized) {
|
|
4252
|
+
throw new FsSafeError("symlink", "path traverses a symlink", { cause: { canonicalPath } });
|
|
4253
|
+
}
|
|
4254
|
+
return { path: normalized, canonicalPath };
|
|
4255
|
+
}
|
|
4256
|
+
async function resolveAbsolutePathForWrite(filePath, options = {}) {
|
|
4257
|
+
const symlinks = resolveSymlinkPolicy(options.symlinks);
|
|
4258
|
+
const normalized = assertAbsolutePathInput(filePath);
|
|
4259
|
+
const parentDir = path.dirname(normalized);
|
|
4260
|
+
const parentExists = await pathExists(parentDir);
|
|
4261
|
+
if (symlinks === "reject") {
|
|
4262
|
+
const filesystemRoot = path.parse(normalized).root;
|
|
4263
|
+
await resolveRootPath({
|
|
4264
|
+
absolutePath: normalized,
|
|
4265
|
+
rootPath: filesystemRoot,
|
|
4266
|
+
rootCanonicalPath: filesystemRoot,
|
|
4267
|
+
boundaryLabel: "absolute path",
|
|
4268
|
+
rejectSymlinks: true,
|
|
4269
|
+
});
|
|
4270
|
+
}
|
|
4271
|
+
const canonicalPath = await canonicalPathFromExistingAncestor(normalized);
|
|
4272
|
+
if (symlinks === "reject" && canonicalPath !== normalized) {
|
|
4273
|
+
throw new FsSafeError("symlink", "path traverses a symlink", {
|
|
4274
|
+
cause: { canonicalPath },
|
|
4275
|
+
});
|
|
4276
|
+
}
|
|
4277
|
+
return {
|
|
4278
|
+
path: normalized,
|
|
4279
|
+
canonicalPath,
|
|
4280
|
+
parentDir,
|
|
4281
|
+
parentExists,
|
|
4282
|
+
};
|
|
3531
4283
|
}
|
|
3532
4284
|
|
|
3533
4285
|
;// CONCATENATED MODULE: ../../node_modules/@openclaw/fs-safe/dist/sidecar-lock-policy.js
|
|
@@ -3581,10 +4333,6 @@ function isTransientLockFileDenial(error, lockPath) {
|
|
|
3581
4333
|
const denial = error;
|
|
3582
4334
|
return process.platform === "win32" && denial?.code === "EPERM" && denial.path === lockPath;
|
|
3583
4335
|
}
|
|
3584
|
-
function sidecarLockPayloadIsStale(payload, staleMs, nowMs) {
|
|
3585
|
-
const createdAtMs = sidecarLockPayloadCreatedAtMs(payload);
|
|
3586
|
-
return createdAtMs !== null && nowMs - createdAtMs > staleMs;
|
|
3587
|
-
}
|
|
3588
4336
|
function sidecarLockPayloadCreatedAtMs(payload) {
|
|
3589
4337
|
const createdAt = payload &&
|
|
3590
4338
|
typeof payload === "object" &&
|
|
@@ -3600,7 +4348,7 @@ async function defaultSidecarLockShouldReclaim(params) {
|
|
|
3600
4348
|
if (createdAtMs !== null)
|
|
3601
4349
|
return params.nowMs - createdAtMs > params.staleMs;
|
|
3602
4350
|
try {
|
|
3603
|
-
return params.nowMs -
|
|
4351
|
+
return params.nowMs - external_node_fs_namespaceObject.statSync(params.lockPath).mtimeMs > params.staleMs;
|
|
3604
4352
|
}
|
|
3605
4353
|
catch {
|
|
3606
4354
|
return true;
|
|
@@ -3634,12 +4382,23 @@ function createSuppressedError(error, suppressed, message) {
|
|
|
3634
4382
|
|
|
3635
4383
|
|
|
3636
4384
|
|
|
3637
|
-
|
|
4385
|
+
|
|
4386
|
+
|
|
4387
|
+
|
|
4388
|
+
async function resolveNormalizedTargetPath(targetPath, lockRoot) {
|
|
3638
4389
|
const resolved = external_node_path_namespaceObject.resolve(targetPath);
|
|
3639
4390
|
const dir = external_node_path_namespaceObject.dirname(resolved);
|
|
4391
|
+
if (lockRoot) {
|
|
4392
|
+
// The target is an arbitration key, not necessarily inside the lock Root.
|
|
4393
|
+
// Leave parent creation to the Root-backed sidecar write.
|
|
4394
|
+
await lockRoot.resolve(".");
|
|
4395
|
+
const parent = await canonicalPathFromExistingAncestor(dir);
|
|
4396
|
+
await lockRoot.resolve(".");
|
|
4397
|
+
return external_node_path_namespaceObject.join(parent, external_node_path_namespaceObject.basename(resolved));
|
|
4398
|
+
}
|
|
3640
4399
|
await promises_namespaceObject.mkdir(dir, { recursive: true });
|
|
3641
4400
|
try {
|
|
3642
|
-
return external_node_path_namespaceObject.join(
|
|
4401
|
+
return external_node_path_namespaceObject.join(external_node_fs_namespaceObject.realpathSync.native(dir), external_node_path_namespaceObject.basename(resolved));
|
|
3643
4402
|
}
|
|
3644
4403
|
catch {
|
|
3645
4404
|
return resolved;
|
|
@@ -3650,7 +4409,7 @@ async function acquireSidecarLock(options, context) {
|
|
|
3650
4409
|
validateSidecarLockRetryOptions(retry);
|
|
3651
4410
|
validateSidecarLockTimeoutMs(options.timeoutMs);
|
|
3652
4411
|
context.ensureExitCleanupRegistered();
|
|
3653
|
-
const normalizedTargetPath = await resolveNormalizedTargetPath(options.targetPath);
|
|
4412
|
+
const normalizedTargetPath = await resolveNormalizedTargetPath(options.targetPath, options.lockRoot);
|
|
3654
4413
|
const lockPath = options.lockPath ?? `${normalizedTargetPath}.lock`;
|
|
3655
4414
|
let held = context.held.get(normalizedTargetPath);
|
|
3656
4415
|
if (held &&
|
|
@@ -3670,11 +4429,15 @@ async function acquireSidecarLock(options, context) {
|
|
|
3670
4429
|
held.reentrantOwner !== undefined &&
|
|
3671
4430
|
options.reentrantOwner === held.reentrantOwner) {
|
|
3672
4431
|
held.refCount += 1;
|
|
4432
|
+
// Retention is monotonic: any same-owner request to keep the sidecar on
|
|
4433
|
+
// exit upgrades the held lock; a later default acquisition never revokes it.
|
|
4434
|
+
if (options.retainOnExit === true) {
|
|
4435
|
+
held.retainOnExit = true;
|
|
4436
|
+
}
|
|
3673
4437
|
return context.handleForHeldLock(normalizedTargetPath, held);
|
|
3674
4438
|
}
|
|
3675
4439
|
}
|
|
3676
4440
|
const startedAt = Date.now();
|
|
3677
|
-
const maxRetries = options.timeoutMs === Number.POSITIVE_INFINITY ? undefined : retry.retries;
|
|
3678
4441
|
const reclaimGuardPath = `${lockPath}.reclaim`;
|
|
3679
4442
|
let ownsReclaimGuard = false;
|
|
3680
4443
|
let attempt = 0;
|
|
@@ -3686,7 +4449,7 @@ async function acquireSidecarLock(options, context) {
|
|
|
3686
4449
|
if ((options.timeoutMs !== undefined &&
|
|
3687
4450
|
options.timeoutMs !== Number.POSITIVE_INFINITY &&
|
|
3688
4451
|
elapsed >= options.timeoutMs) ||
|
|
3689
|
-
(
|
|
4452
|
+
(retry.retries !== undefined && attempt >= retry.retries)) {
|
|
3690
4453
|
throw Object.assign(new Error(`file lock timeout for ${normalizedTargetPath}`), {
|
|
3691
4454
|
code: "file_lock_timeout",
|
|
3692
4455
|
lockPath,
|
|
@@ -3728,10 +4491,14 @@ async function acquireSidecarLock(options, context) {
|
|
|
3728
4491
|
if (options.lockRoot) {
|
|
3729
4492
|
const lockRoot = options.lockRoot;
|
|
3730
4493
|
const relativeLockPath = relativeSidecarLockPath(lockRoot, lockPath);
|
|
4494
|
+
const observation = fileObservation();
|
|
3731
4495
|
try {
|
|
3732
|
-
await lockRoot.create(relativeLockPath, raw, { mkdir: true, mode: 0o600 });
|
|
4496
|
+
await observation.run(() => lockRoot.create(relativeLockPath, raw, { mkdir: true, mode: 0o600 }));
|
|
3733
4497
|
}
|
|
3734
4498
|
catch (error) {
|
|
4499
|
+
// Only this invocation's failed exclusive open grants denial retry authority.
|
|
4500
|
+
lockFileCreateDenied = observation.has(error, `exclusive-create:${lockPath}`) &&
|
|
4501
|
+
isTransientLockFileDenial(error, lockPath);
|
|
3735
4502
|
if (error instanceof errors_FsSafeError && error.code === "already-exists") {
|
|
3736
4503
|
throw Object.assign(new Error("sidecar lock exists"), { code: "EEXIST" });
|
|
3737
4504
|
}
|
|
@@ -3768,7 +4535,7 @@ async function acquireSidecarLock(options, context) {
|
|
|
3768
4535
|
}
|
|
3769
4536
|
await handle.writeFile(raw, "utf8");
|
|
3770
4537
|
}
|
|
3771
|
-
const snapshot = { raw, payload, stat:
|
|
4538
|
+
const snapshot = { raw, payload, stat: external_node_fs_namespaceObject.fstatSync(handle.fd), ownershipToken };
|
|
3772
4539
|
if (snapshot.stat.nlink === 0) {
|
|
3773
4540
|
await handle.close();
|
|
3774
4541
|
handle = null;
|
|
@@ -3784,6 +4551,7 @@ async function acquireSidecarLock(options, context) {
|
|
|
3784
4551
|
acquiredAt: Date.now(),
|
|
3785
4552
|
metadata: options.metadata ?? {},
|
|
3786
4553
|
lockRoot: options.lockRoot,
|
|
4554
|
+
retainOnExit: options.retainOnExit,
|
|
3787
4555
|
parsePayload: options.parsePayload,
|
|
3788
4556
|
};
|
|
3789
4557
|
context.held.set(normalizedTargetPath, createdHeld);
|
|
@@ -3821,7 +4589,7 @@ async function acquireSidecarLock(options, context) {
|
|
|
3821
4589
|
if (handle) {
|
|
3822
4590
|
const failedSnapshot = createdSnapshot ?? { payload: null };
|
|
3823
4591
|
try {
|
|
3824
|
-
failedSnapshot.stat =
|
|
4592
|
+
failedSnapshot.stat = external_node_fs_namespaceObject.fstatSync(handle.fd);
|
|
3825
4593
|
}
|
|
3826
4594
|
catch {
|
|
3827
4595
|
// Best-effort cleanup of a failed exclusive create.
|
|
@@ -3994,9 +4762,15 @@ function createHeldSidecarLockHandle(params) {
|
|
|
3994
4762
|
|
|
3995
4763
|
|
|
3996
4764
|
|
|
4765
|
+
|
|
3997
4766
|
const GLOBAL_STATE_KEY = Symbol.for("fsSafe.sidecarLockManagers");
|
|
3998
4767
|
const GLOBAL_CLEANUP_KEY = Symbol.for("fsSafe.sidecarLockCleanupRegistered");
|
|
3999
4768
|
const GLOBAL_CLEANUP_HANDLER_KEY = Symbol.for("fsSafe.sidecarLockCleanupHandler");
|
|
4769
|
+
const GLOBAL_BEFORE_EXIT_KEY = Symbol.for("fsSafe.sidecarLockBeforeExitCleanup");
|
|
4770
|
+
// Set by copies whose exit handlers honor retainOnExit. When an older package
|
|
4771
|
+
// copy registered the handlers first, this marker stays absent and retained
|
|
4772
|
+
// acquisitions must fail closed rather than silently lose the guarantee.
|
|
4773
|
+
const GLOBAL_RETAIN_AWARE_KEY = Symbol.for("fsSafe.sidecarLockRetainAwareCleanup");
|
|
4000
4774
|
function getGlobalManagers() {
|
|
4001
4775
|
const globalWithState = globalThis;
|
|
4002
4776
|
if (!globalWithState[GLOBAL_STATE_KEY]) {
|
|
@@ -4069,7 +4843,8 @@ function snapshotMatchesSync(lockPath, observed) {
|
|
|
4069
4843
|
}
|
|
4070
4844
|
}
|
|
4071
4845
|
function releaseAllReclaimGuardsSync(state) {
|
|
4072
|
-
|
|
4846
|
+
// Exit cleanup also visits managers created by older copies and never reopened here.
|
|
4847
|
+
for (const reclaimGuardPath of state.reclaimGuards ?? []) {
|
|
4073
4848
|
try {
|
|
4074
4849
|
external_node_fs_namespaceObject.rmdirSync(reclaimGuardPath);
|
|
4075
4850
|
state.reclaimGuards.delete(reclaimGuardPath);
|
|
@@ -4079,11 +4854,12 @@ function releaseAllReclaimGuardsSync(state) {
|
|
|
4079
4854
|
}
|
|
4080
4855
|
}
|
|
4081
4856
|
}
|
|
4082
|
-
function releaseAllLocksSync(state) {
|
|
4857
|
+
function releaseAllLocksSync(state, options) {
|
|
4083
4858
|
for (const [normalizedTargetPath, held] of state.held) {
|
|
4084
4859
|
void held.handle.close().catch(() => undefined);
|
|
4085
4860
|
try {
|
|
4086
|
-
|
|
4861
|
+
const retained = options?.preserveRetained === true && held.retainOnExit;
|
|
4862
|
+
if (!retained && !held.lockRoot && snapshotMatchesSync(held.lockPath, held.snapshot)) {
|
|
4087
4863
|
external_node_fs_namespaceObject.rmSync(held.lockPath, { force: true });
|
|
4088
4864
|
}
|
|
4089
4865
|
}
|
|
@@ -4099,14 +4875,43 @@ function ensureGlobalExitCleanupRegistered() {
|
|
|
4099
4875
|
if (globalWithCleanup[GLOBAL_CLEANUP_KEY])
|
|
4100
4876
|
return;
|
|
4101
4877
|
globalWithCleanup[GLOBAL_CLEANUP_KEY] = true;
|
|
4878
|
+
globalWithCleanup[GLOBAL_RETAIN_AWARE_KEY] = true;
|
|
4102
4879
|
const cleanup = () => {
|
|
4103
4880
|
for (const state of getGlobalManagers().values()) {
|
|
4104
|
-
releaseAllLocksSync(state);
|
|
4881
|
+
releaseAllLocksSync(state, { preserveRetained: true });
|
|
4105
4882
|
}
|
|
4106
4883
|
};
|
|
4107
4884
|
globalWithCleanup[GLOBAL_CLEANUP_HANDLER_KEY] = cleanup;
|
|
4108
4885
|
process.on("exit", cleanup);
|
|
4109
4886
|
}
|
|
4887
|
+
/** True when a retain-unaware package copy registered the process-exit handlers first. */
|
|
4888
|
+
function exitCleanupCannotRetain() {
|
|
4889
|
+
const globalWithCleanup = globalThis;
|
|
4890
|
+
return globalWithCleanup[GLOBAL_CLEANUP_KEY] === true && globalWithCleanup[GLOBAL_RETAIN_AWARE_KEY] !== true;
|
|
4891
|
+
}
|
|
4892
|
+
function ensureGlobalBeforeExitCleanupRegistered() {
|
|
4893
|
+
const globalWithCleanup = globalThis;
|
|
4894
|
+
if (globalWithCleanup[GLOBAL_BEFORE_EXIT_KEY]) {
|
|
4895
|
+
return globalWithCleanup[GLOBAL_BEFORE_EXIT_KEY];
|
|
4896
|
+
}
|
|
4897
|
+
// Independent of the exit registration, which an older package copy may own.
|
|
4898
|
+
const lifecycle = { armed: false };
|
|
4899
|
+
globalWithCleanup[GLOBAL_BEFORE_EXIT_KEY] = lifecycle;
|
|
4900
|
+
process.on("beforeExit", () => {
|
|
4901
|
+
if (!lifecycle.armed)
|
|
4902
|
+
return;
|
|
4903
|
+
// Cleanup itself schedules I/O; retry only after another acquisition.
|
|
4904
|
+
lifecycle.armed = false;
|
|
4905
|
+
for (const state of getGlobalManagers().values()) {
|
|
4906
|
+
for (const [normalizedTargetPath, held] of Array.from(state.held.entries())) {
|
|
4907
|
+
if (held.lockRoot && !held.retainOnExit) {
|
|
4908
|
+
void releaseHeldLock(state, normalizedTargetPath, held, { force: true }).catch(() => undefined);
|
|
4909
|
+
}
|
|
4910
|
+
}
|
|
4911
|
+
}
|
|
4912
|
+
});
|
|
4913
|
+
return lifecycle;
|
|
4914
|
+
}
|
|
4110
4915
|
async function releaseHeldLock(state, normalizedTargetPath, held, options = {}) {
|
|
4111
4916
|
const current = state.held.get(normalizedTargetPath);
|
|
4112
4917
|
if (current !== held) {
|
|
@@ -4148,6 +4953,7 @@ async function releaseHeldLock(state, normalizedTargetPath, held, options = {})
|
|
|
4148
4953
|
}
|
|
4149
4954
|
}
|
|
4150
4955
|
function handleForHeldLock(state, normalizedTargetPath, held) {
|
|
4956
|
+
ensureGlobalBeforeExitCleanupRegistered().armed = true;
|
|
4151
4957
|
return createHeldSidecarLockHandle({
|
|
4152
4958
|
normalizedTargetPath,
|
|
4153
4959
|
held,
|
|
@@ -4160,8 +4966,12 @@ function createSidecarLockManager(key) {
|
|
|
4160
4966
|
state.cleanupRegistered = true;
|
|
4161
4967
|
state.reclaimCleanupRegistered = true;
|
|
4162
4968
|
ensureGlobalExitCleanupRegistered();
|
|
4969
|
+
ensureGlobalBeforeExitCleanupRegistered().armed = true;
|
|
4163
4970
|
}
|
|
4164
4971
|
async function acquire(options) {
|
|
4972
|
+
if (options.retainOnExit === true && exitCleanupCannotRetain()) {
|
|
4973
|
+
throw new errors_FsSafeError("helper-unavailable", "retainOnExit requires this process's exit handlers to be retain-aware; an older package copy registered them first");
|
|
4974
|
+
}
|
|
4165
4975
|
return await acquireSidecarLock(options, {
|
|
4166
4976
|
held: state.held,
|
|
4167
4977
|
reclaimGuards: state.reclaimGuards,
|
|
@@ -4231,6 +5041,8 @@ async function withSidecarLock(targetPath, options, fn) {
|
|
|
4231
5041
|
|
|
4232
5042
|
|
|
4233
5043
|
|
|
5044
|
+
|
|
5045
|
+
|
|
4234
5046
|
function byteLength(input, encoding) {
|
|
4235
5047
|
return typeof input === "string"
|
|
4236
5048
|
? Buffer.byteLength(input, encoding ?? "utf8")
|
|
@@ -4250,16 +5062,6 @@ function assertWithinMaxBytes(bytes, maxBytes) {
|
|
|
4250
5062
|
throw new errors_FsSafeError("too-large", `file exceeds limit of ${maxBytes} bytes (got at least ${bytes})`);
|
|
4251
5063
|
}
|
|
4252
5064
|
}
|
|
4253
|
-
async function syncFileBestEffort(handle) {
|
|
4254
|
-
try {
|
|
4255
|
-
await handle.sync();
|
|
4256
|
-
}
|
|
4257
|
-
catch (error) {
|
|
4258
|
-
if (error?.code !== "EPERM") {
|
|
4259
|
-
throw error;
|
|
4260
|
-
}
|
|
4261
|
-
}
|
|
4262
|
-
}
|
|
4263
5065
|
async function writeStreamToHandle(stream, handle, maxBytes) {
|
|
4264
5066
|
let bytes = 0;
|
|
4265
5067
|
for await (const chunk of stream) {
|
|
@@ -4301,7 +5103,7 @@ async function runPinnedWriteWithRenamePolicy(params) {
|
|
|
4301
5103
|
const relativeTargetPath = writeParams.relativeParentPath
|
|
4302
5104
|
? `${writeParams.relativeParentPath}/${writeParams.basename}`
|
|
4303
5105
|
: writeParams.basename;
|
|
4304
|
-
const lockPath = external_node_path_namespaceObject.join(writeParams.rootPath, `.fs-safe-write-${
|
|
5106
|
+
const lockPath = external_node_path_namespaceObject.join(writeParams.rootPath, `.fs-safe-write-${file_identity_sha256Hex(relativeTargetPath)}.lock`);
|
|
4305
5107
|
return await withSidecarLock(writeParams.rootPath, {
|
|
4306
5108
|
managerKey: `fs-safe.write:${targetPath}`,
|
|
4307
5109
|
lockPath,
|
|
@@ -4315,6 +5117,11 @@ async function runPinnedWriteWithRenamePolicy(params) {
|
|
|
4315
5117
|
}));
|
|
4316
5118
|
}
|
|
4317
5119
|
async function runPinnedWriteFallback(params) {
|
|
5120
|
+
const exactRoot = typeof params.rootIdentity?.dev === "bigint" && typeof params.rootIdentity.ino === "bigint"
|
|
5121
|
+
? { dev: params.rootIdentity.dev, ino: params.rootIdentity.ino } : undefined;
|
|
5122
|
+
if (exactRoot)
|
|
5123
|
+
await inspectDirectoryIdentity(params.rootPath, exactRoot);
|
|
5124
|
+
const guardOptions = { bigint: exactRoot !== undefined };
|
|
4318
5125
|
let parentPath = params.relativeParentPath
|
|
4319
5126
|
? external_node_path_namespaceObject.join(params.rootPath, ...params.relativeParentPath.split("/"))
|
|
4320
5127
|
: params.rootPath;
|
|
@@ -4330,8 +5137,8 @@ async function runPinnedWriteFallback(params) {
|
|
|
4330
5137
|
});
|
|
4331
5138
|
}
|
|
4332
5139
|
const parentGuard = params.mkdir
|
|
4333
|
-
? await directory_guard_createAsyncDirectoryGuard(parentPath)
|
|
4334
|
-
: await directory_guard_createNearestExistingDirectoryGuard(params.rootPath, parentPath);
|
|
5140
|
+
? await directory_guard_createAsyncDirectoryGuard(parentPath, guardOptions)
|
|
5141
|
+
: await directory_guard_createNearestExistingDirectoryGuard(params.rootPath, parentPath, guardOptions);
|
|
4335
5142
|
const targetPath = external_node_path_namespaceObject.join(parentPath, params.basename);
|
|
4336
5143
|
if (params.overwrite === false) {
|
|
4337
5144
|
const handle = await withAsyncDirectoryGuards([parentGuard], async () => await promises_namespaceObject.open(targetPath, external_node_fs_namespaceObject.constants.O_WRONLY | external_node_fs_namespaceObject.constants.O_CREAT | external_node_fs_namespaceObject.constants.O_EXCL, params.mode), {
|
|
@@ -4342,9 +5149,10 @@ async function runPinnedWriteFallback(params) {
|
|
|
4342
5149
|
},
|
|
4343
5150
|
});
|
|
4344
5151
|
let created = true;
|
|
5152
|
+
let createdIdentity;
|
|
4345
5153
|
try {
|
|
4346
|
-
const verificationIdentity =
|
|
4347
|
-
|
|
5154
|
+
const verificationIdentity = external_node_fs_namespaceObject.fstatSync(handle.fd, { bigint: true });
|
|
5155
|
+
createdIdentity = verificationIdentity;
|
|
4348
5156
|
if (params.input.kind === "buffer") {
|
|
4349
5157
|
assertWithinMaxBytes(byteLength(params.input.data, params.input.encoding), params.maxBytes);
|
|
4350
5158
|
if (typeof params.input.data === "string") {
|
|
@@ -4357,18 +5165,26 @@ async function runPinnedWriteFallback(params) {
|
|
|
4357
5165
|
else {
|
|
4358
5166
|
await writeStreamToHandle(params.input.stream, handle, params.maxBytes);
|
|
4359
5167
|
}
|
|
4360
|
-
|
|
4361
|
-
|
|
4362
|
-
|
|
5168
|
+
// Content writes may clear set-ID bits; finalize them through the owned fd.
|
|
5169
|
+
await handle.chmod(params.mode);
|
|
5170
|
+
if (params.sync !== false)
|
|
5171
|
+
await syncFileBestEffort(handle);
|
|
5172
|
+
const stat = external_node_fs_namespaceObject.fstatSync(handle.fd);
|
|
5173
|
+
if (params.sync !== false)
|
|
5174
|
+
await syncDirectoryBestEffort(parentPath);
|
|
4363
5175
|
// Publication is complete. A failed outer check must not remove its target.
|
|
4364
5176
|
created = false;
|
|
4365
5177
|
await params.verifyPublished?.(handle.fd, verificationIdentity, parentGuard);
|
|
4366
5178
|
return { dev: stat.dev, ino: stat.ino };
|
|
4367
5179
|
}
|
|
4368
5180
|
finally {
|
|
4369
|
-
|
|
4370
|
-
|
|
4371
|
-
|
|
5181
|
+
try {
|
|
5182
|
+
if (created) {
|
|
5183
|
+
await cleanupPinnedFilePath({ pathname: targetPath, handle, identity: createdIdentity, parentGuard });
|
|
5184
|
+
}
|
|
5185
|
+
}
|
|
5186
|
+
finally {
|
|
5187
|
+
await handle.close().catch(() => undefined);
|
|
4372
5188
|
}
|
|
4373
5189
|
}
|
|
4374
5190
|
}
|
|
@@ -4382,12 +5198,13 @@ async function runPinnedWriteFallback(params) {
|
|
|
4382
5198
|
: 0);
|
|
4383
5199
|
let handle;
|
|
4384
5200
|
let tempStat;
|
|
5201
|
+
let tempIdentity;
|
|
4385
5202
|
let readHandle;
|
|
4386
5203
|
let renamed = false;
|
|
4387
5204
|
try {
|
|
4388
5205
|
handle = await promises_namespaceObject.open(tempPath, tempFlags, params.mode);
|
|
4389
|
-
let verificationIdentity =
|
|
4390
|
-
|
|
5206
|
+
let verificationIdentity = external_node_fs_namespaceObject.fstatSync(handle.fd, { bigint: true });
|
|
5207
|
+
tempIdentity = verificationIdentity;
|
|
4391
5208
|
if (params.input.kind === "buffer") {
|
|
4392
5209
|
assertWithinMaxBytes(byteLength(params.input.data, params.input.encoding), params.maxBytes);
|
|
4393
5210
|
if (typeof params.input.data === "string") {
|
|
@@ -4400,20 +5217,23 @@ async function runPinnedWriteFallback(params) {
|
|
|
4400
5217
|
else {
|
|
4401
5218
|
await writeStreamToHandle(params.input.stream, handle, params.maxBytes);
|
|
4402
5219
|
}
|
|
4403
|
-
tempStat =
|
|
4404
|
-
const tempPathStat =
|
|
5220
|
+
tempStat = external_node_fs_namespaceObject.fstatSync(handle.fd);
|
|
5221
|
+
const tempPathStat = external_node_fs_namespaceObject.lstatSync(tempPath);
|
|
4405
5222
|
if (tempPathStat.isSymbolicLink() || !file_identity_sameFileIdentity(tempPathStat, tempStat)) {
|
|
4406
5223
|
throw new errors_FsSafeError("path-mismatch", "fallback temp path changed during write");
|
|
4407
5224
|
}
|
|
4408
5225
|
const expectedTempStat = tempStat;
|
|
4409
|
-
await
|
|
5226
|
+
await handle.chmod(params.mode);
|
|
5227
|
+
if (params.sync !== false)
|
|
5228
|
+
await syncFileBestEffort(handle);
|
|
4410
5229
|
let verifiedIdentity = expectedTempStat;
|
|
4411
5230
|
await withAsyncDirectoryGuards([parentGuard], async () => {
|
|
4412
5231
|
await promises_namespaceObject.rename(tempPath, targetPath);
|
|
4413
5232
|
renamed = true;
|
|
4414
5233
|
await getFsSafeTestHooks()?.afterPinnedWriteFallbackRename?.(targetPath);
|
|
4415
|
-
|
|
4416
|
-
|
|
5234
|
+
if (params.sync !== false)
|
|
5235
|
+
await syncDirectoryBestEffort(parentPath);
|
|
5236
|
+
const targetStat = external_node_fs_namespaceObject.lstatSync(targetPath);
|
|
4417
5237
|
if (targetStat.isSymbolicLink()) {
|
|
4418
5238
|
throw new errors_FsSafeError("path-mismatch", "fallback target changed during write");
|
|
4419
5239
|
}
|
|
@@ -4428,10 +5248,10 @@ async function runPinnedWriteFallback(params) {
|
|
|
4428
5248
|
if (params.input.kind !== "buffer") {
|
|
4429
5249
|
throw new errors_FsSafeError("path-mismatch", "fallback target changed during write");
|
|
4430
5250
|
}
|
|
4431
|
-
const expectedHash =
|
|
5251
|
+
const expectedHash = file_identity_sha256Hex(params.input.data, params.input.encoding);
|
|
4432
5252
|
readHandle = await promises_namespaceObject.open(targetPath, read_open_flags_resolveReadOpenFlags());
|
|
4433
|
-
const readHandleStat =
|
|
4434
|
-
const actualHash =
|
|
5253
|
+
const readHandleStat = external_node_fs_namespaceObject.fstatSync(readHandle.fd, { bigint: true });
|
|
5254
|
+
const actualHash = file_identity_sha256Hex(await readHandle.readFile());
|
|
4435
5255
|
if (actualHash !== expectedHash) {
|
|
4436
5256
|
throw new errors_FsSafeError("path-mismatch", "fallback target changed during write");
|
|
4437
5257
|
}
|
|
@@ -4445,10 +5265,14 @@ async function runPinnedWriteFallback(params) {
|
|
|
4445
5265
|
return { dev: verifiedIdentity.dev, ino: verifiedIdentity.ino };
|
|
4446
5266
|
}
|
|
4447
5267
|
finally {
|
|
4448
|
-
|
|
4449
|
-
|
|
4450
|
-
|
|
4451
|
-
|
|
5268
|
+
try {
|
|
5269
|
+
if (!renamed && handle) {
|
|
5270
|
+
await cleanupPinnedFilePath({ pathname: tempPath, handle, identity: tempIdentity, parentGuard });
|
|
5271
|
+
}
|
|
5272
|
+
}
|
|
5273
|
+
finally {
|
|
5274
|
+
await readHandle?.close().catch(() => undefined);
|
|
5275
|
+
await handle?.close().catch(() => undefined);
|
|
4452
5276
|
}
|
|
4453
5277
|
}
|
|
4454
5278
|
}
|
|
@@ -4460,7 +5284,7 @@ async function runPinnedWriteFallback(params) {
|
|
|
4460
5284
|
|
|
4461
5285
|
const PATH_ALIAS_POLICIES = ROOT_PATH_ALIAS_POLICIES;
|
|
4462
5286
|
async function assertNoPathAliasEscape(params) {
|
|
4463
|
-
const resolved = await
|
|
5287
|
+
const resolved = await root_path_resolveRootPath({
|
|
4464
5288
|
absolutePath: params.absolutePath,
|
|
4465
5289
|
rootPath: params.rootPath,
|
|
4466
5290
|
boundaryLabel: params.boundaryLabel,
|
|
@@ -4483,7 +5307,7 @@ async function assertNoHardlinkedFinalPath(params) {
|
|
|
4483
5307
|
}
|
|
4484
5308
|
let stat;
|
|
4485
5309
|
try {
|
|
4486
|
-
stat =
|
|
5310
|
+
stat = external_node_fs_namespaceObject.statSync(params.filePath);
|
|
4487
5311
|
}
|
|
4488
5312
|
catch (err) {
|
|
4489
5313
|
if (path_isNotFoundPathError(err)) {
|
|
@@ -4502,9 +5326,6 @@ async function assertNoHardlinkedFinalPath(params) {
|
|
|
4502
5326
|
;// CONCATENATED MODULE: external "node:url"
|
|
4503
5327
|
const external_node_url_namespaceObject = __rspack_createRequire_require("node:url");
|
|
4504
5328
|
;// CONCATENATED MODULE: ../../node_modules/@openclaw/fs-safe/dist/string-coerce.js
|
|
4505
|
-
function readStringValue(value) {
|
|
4506
|
-
return typeof value === "string" ? value : undefined;
|
|
4507
|
-
}
|
|
4508
5329
|
function normalizeNullableString(value) {
|
|
4509
5330
|
if (typeof value !== "string") {
|
|
4510
5331
|
return null;
|
|
@@ -4515,65 +5336,12 @@ function normalizeNullableString(value) {
|
|
|
4515
5336
|
function normalizeOptionalString(value) {
|
|
4516
5337
|
return normalizeNullableString(value) ?? undefined;
|
|
4517
5338
|
}
|
|
4518
|
-
function normalizeStringifiedOptionalString(value) {
|
|
4519
|
-
if (typeof value === "string") {
|
|
4520
|
-
return normalizeOptionalString(value);
|
|
4521
|
-
}
|
|
4522
|
-
if (typeof value === "number" || typeof value === "boolean" || typeof value === "bigint") {
|
|
4523
|
-
return normalizeOptionalString(String(value));
|
|
4524
|
-
}
|
|
4525
|
-
return undefined;
|
|
4526
|
-
}
|
|
4527
5339
|
function normalizeOptionalLowercaseString(value) {
|
|
4528
5340
|
return normalizeOptionalString(value)?.toLowerCase();
|
|
4529
5341
|
}
|
|
4530
5342
|
function normalizeLowercaseStringOrEmpty(value) {
|
|
4531
5343
|
return normalizeOptionalLowercaseString(value) ?? "";
|
|
4532
5344
|
}
|
|
4533
|
-
function normalizeFastMode(raw) {
|
|
4534
|
-
if (typeof raw === "boolean") {
|
|
4535
|
-
return raw;
|
|
4536
|
-
}
|
|
4537
|
-
if (!raw) {
|
|
4538
|
-
return undefined;
|
|
4539
|
-
}
|
|
4540
|
-
const key = normalizeLowercaseStringOrEmpty(raw);
|
|
4541
|
-
if (["off", "false", "no", "0", "disable", "disabled", "normal"].includes(key)) {
|
|
4542
|
-
return false;
|
|
4543
|
-
}
|
|
4544
|
-
if (["on", "true", "yes", "1", "enable", "enabled", "fast"].includes(key)) {
|
|
4545
|
-
return true;
|
|
4546
|
-
}
|
|
4547
|
-
return undefined;
|
|
4548
|
-
}
|
|
4549
|
-
function lowercasePreservingWhitespace(value) {
|
|
4550
|
-
return value.toLowerCase();
|
|
4551
|
-
}
|
|
4552
|
-
function localeLowercasePreservingWhitespace(value) {
|
|
4553
|
-
return value.toLocaleLowerCase();
|
|
4554
|
-
}
|
|
4555
|
-
function resolvePrimaryStringValue(value) {
|
|
4556
|
-
if (typeof value === "string") {
|
|
4557
|
-
return normalizeOptionalString(value);
|
|
4558
|
-
}
|
|
4559
|
-
if (!value || typeof value !== "object") {
|
|
4560
|
-
return undefined;
|
|
4561
|
-
}
|
|
4562
|
-
return normalizeOptionalString(value.primary);
|
|
4563
|
-
}
|
|
4564
|
-
function normalizeOptionalThreadValue(value) {
|
|
4565
|
-
if (typeof value === "number") {
|
|
4566
|
-
return Number.isFinite(value) ? Math.trunc(value) : undefined;
|
|
4567
|
-
}
|
|
4568
|
-
return normalizeOptionalString(value);
|
|
4569
|
-
}
|
|
4570
|
-
function normalizeOptionalStringifiedId(value) {
|
|
4571
|
-
const normalized = normalizeOptionalThreadValue(value);
|
|
4572
|
-
return normalized == null ? undefined : String(normalized);
|
|
4573
|
-
}
|
|
4574
|
-
function hasNonEmptyString(value) {
|
|
4575
|
-
return normalizeOptionalString(value) !== undefined;
|
|
4576
|
-
}
|
|
4577
5345
|
|
|
4578
5346
|
;// CONCATENATED MODULE: ../../node_modules/@openclaw/fs-safe/dist/local-file-access.js
|
|
4579
5347
|
|
|
@@ -4765,8 +5533,11 @@ function normalizeWindowsDeviceBaseName(filePath) {
|
|
|
4765
5533
|
const normalized = trimTrailingWindowsSeparators(filePath.replace(/\//g, "\\"));
|
|
4766
5534
|
const lastSegment = normalized.split("\\").filter(Boolean).at(-1) ?? normalized;
|
|
4767
5535
|
const withoutStream = lastSegment.split(":")[0] ?? lastSegment;
|
|
4768
|
-
const
|
|
4769
|
-
return (
|
|
5536
|
+
const stem = withoutStream.split(".")[0] ?? withoutStream;
|
|
5537
|
+
return trimTrailingWindowsIgnoredChars(stem).toUpperCase();
|
|
5538
|
+
}
|
|
5539
|
+
function isWindowsReservedDeviceName(name) {
|
|
5540
|
+
return name.length > 0 && WINDOWS_RESERVED_DEVICE_NAMES.has(normalizeWindowsDeviceBaseName(name));
|
|
4770
5541
|
}
|
|
4771
5542
|
function matchWindowsDeviceReadPath(filePath) {
|
|
4772
5543
|
const normalized = filePath.replace(/\//g, "\\");
|
|
@@ -4820,6 +5591,42 @@ async function read_opened_file_readOpenedFileSafely(params) {
|
|
|
4820
5591
|
};
|
|
4821
5592
|
}
|
|
4822
5593
|
|
|
5594
|
+
;// CONCATENATED MODULE: ../../node_modules/@openclaw/fs-safe/dist/write-open-flags.js
|
|
5595
|
+
|
|
5596
|
+
|
|
5597
|
+
function resolveNonblockingWriteFlag(constants = external_node_fs_namespaceObject.constants) {
|
|
5598
|
+
return process.platform !== "win32" && typeof constants.O_NONBLOCK === "number"
|
|
5599
|
+
? constants.O_NONBLOCK
|
|
5600
|
+
: 0;
|
|
5601
|
+
}
|
|
5602
|
+
function isNonblockingWriteEnxio(error, flags) {
|
|
5603
|
+
return hasNodeErrorCode(error, "ENXIO") &&
|
|
5604
|
+
(flags & (external_node_fs_namespaceObject.constants.O_WRONLY | external_node_fs_namespaceObject.constants.O_RDWR)) === external_node_fs_namespaceObject.constants.O_WRONLY &&
|
|
5605
|
+
(flags & resolveNonblockingWriteFlag()) !== 0;
|
|
5606
|
+
}
|
|
5607
|
+
// A no-reader FIFO rejects a nonblocking write-only open before fstat is possible.
|
|
5608
|
+
// Reclassify only a confirmed non-regular path; inconclusive races keep the errno.
|
|
5609
|
+
async function isNonRegularWriteOpenError(error, filePath, flags) {
|
|
5610
|
+
if (!isNonblockingWriteEnxio(error, flags))
|
|
5611
|
+
return false;
|
|
5612
|
+
try {
|
|
5613
|
+
return !external_node_fs_namespaceObject.lstatSync(filePath).isFile();
|
|
5614
|
+
}
|
|
5615
|
+
catch {
|
|
5616
|
+
return false;
|
|
5617
|
+
}
|
|
5618
|
+
}
|
|
5619
|
+
function isNonRegularWriteOpenErrorSync(error, filePath, flags) {
|
|
5620
|
+
if (!isNonblockingWriteEnxio(error, flags))
|
|
5621
|
+
return false;
|
|
5622
|
+
try {
|
|
5623
|
+
return !fsSync.lstatSync(filePath).isFile();
|
|
5624
|
+
}
|
|
5625
|
+
catch {
|
|
5626
|
+
return false;
|
|
5627
|
+
}
|
|
5628
|
+
}
|
|
5629
|
+
|
|
4823
5630
|
;// CONCATENATED MODULE: ../../node_modules/@openclaw/fs-safe/dist/home-dir.js
|
|
4824
5631
|
|
|
4825
5632
|
|
|
@@ -4838,10 +5645,6 @@ function resolveEffectiveHomeDir(env = process.env, homedir = external_node_os_n
|
|
|
4838
5645
|
const raw = resolveRawHomeDir(env, homedir);
|
|
4839
5646
|
return raw ? external_node_path_namespaceObject.resolve(raw) : undefined;
|
|
4840
5647
|
}
|
|
4841
|
-
function resolveOsHomeDir(env = process.env, homedir = os.homedir) {
|
|
4842
|
-
const raw = resolveRawOsHomeDir(env, homedir);
|
|
4843
|
-
return raw ? path.resolve(raw) : undefined;
|
|
4844
|
-
}
|
|
4845
5648
|
function resolveRawHomeDir(env, homedir) {
|
|
4846
5649
|
const explicitHome = normalize(env.OPENCLAW_HOME);
|
|
4847
5650
|
if (!explicitHome) {
|
|
@@ -4882,9 +5685,6 @@ function normalizeSafe(homedir) {
|
|
|
4882
5685
|
function resolveRequiredHomeDir(env = process.env, homedir = os.homedir) {
|
|
4883
5686
|
return resolveEffectiveHomeDir(env, homedir) ?? path.resolve(process.cwd());
|
|
4884
5687
|
}
|
|
4885
|
-
function resolveRequiredOsHomeDir(env = process.env, homedir = os.homedir) {
|
|
4886
|
-
return resolveOsHomeDir(env, homedir) ?? path.resolve(process.cwd());
|
|
4887
|
-
}
|
|
4888
5688
|
function expandHomePrefix(input, opts) {
|
|
4889
5689
|
const segments = external_node_path_namespaceObject.normalize(input).split(external_node_path_namespaceObject.sep);
|
|
4890
5690
|
if (segments[0] !== "~") {
|
|
@@ -4912,27 +5712,6 @@ function resolveHomeRelativePath(input, opts) {
|
|
|
4912
5712
|
});
|
|
4913
5713
|
return path.resolve(expanded);
|
|
4914
5714
|
}
|
|
4915
|
-
function resolveUserPath(input, optsOrEnv, homedir) {
|
|
4916
|
-
const opts = optsOrEnv && ("env" in optsOrEnv || "homedir" in optsOrEnv)
|
|
4917
|
-
? optsOrEnv
|
|
4918
|
-
: { env: optsOrEnv, homedir };
|
|
4919
|
-
return resolveHomeRelativePath(input, opts);
|
|
4920
|
-
}
|
|
4921
|
-
function resolveOsHomeRelativePath(input, opts) {
|
|
4922
|
-
if (!input) {
|
|
4923
|
-
return input;
|
|
4924
|
-
}
|
|
4925
|
-
const segments = path.normalize(input).split(path.sep);
|
|
4926
|
-
if (segments[0] !== "~") {
|
|
4927
|
-
return path.resolve(input);
|
|
4928
|
-
}
|
|
4929
|
-
const expanded = expandHomePrefix(input, {
|
|
4930
|
-
home: resolveRequiredOsHomeDir(opts?.env ?? process.env, opts?.homedir ?? os.homedir),
|
|
4931
|
-
env: opts?.env,
|
|
4932
|
-
homedir: opts?.homedir,
|
|
4933
|
-
});
|
|
4934
|
-
return path.resolve(expanded);
|
|
4935
|
-
}
|
|
4936
5715
|
|
|
4937
5716
|
;// CONCATENATED MODULE: ../../node_modules/@openclaw/fs-safe/dist/root-context.js
|
|
4938
5717
|
|
|
@@ -4945,6 +5724,7 @@ function resolveOsHomeRelativePath(input, opts) {
|
|
|
4945
5724
|
|
|
4946
5725
|
|
|
4947
5726
|
|
|
5727
|
+
|
|
4948
5728
|
const ensureTrailingSep = (value) => value.endsWith(external_node_path_namespaceObject.sep) ? value : value + external_node_path_namespaceObject.sep;
|
|
4949
5729
|
function assertValidRootRelativePath(relativePath) {
|
|
4950
5730
|
path_assertNoNulPathInput(relativePath, "relative path contains a NUL byte");
|
|
@@ -4961,7 +5741,7 @@ async function expandRelativePathWithHome(relativePath) {
|
|
|
4961
5741
|
if (cachedHomePath?.raw !== rawHome) {
|
|
4962
5742
|
let realHome = rawHome;
|
|
4963
5743
|
try {
|
|
4964
|
-
realHome =
|
|
5744
|
+
realHome = external_node_fs_namespaceObject.realpathSync.native(rawHome);
|
|
4965
5745
|
}
|
|
4966
5746
|
catch {
|
|
4967
5747
|
// If the home dir cannot be canonicalized, keep lexical expansion behavior.
|
|
@@ -4975,8 +5755,8 @@ async function resolveRootContext(rootDir) {
|
|
|
4975
5755
|
let rootReal;
|
|
4976
5756
|
let rootIdentity;
|
|
4977
5757
|
try {
|
|
4978
|
-
rootReal =
|
|
4979
|
-
const rootStat =
|
|
5758
|
+
rootReal = external_node_fs_namespaceObject.realpathSync.native(rootDir);
|
|
5759
|
+
const rootStat = external_node_fs_namespaceObject.statSync(rootReal);
|
|
4980
5760
|
if (!rootStat.isDirectory()) {
|
|
4981
5761
|
throw new errors_FsSafeError("invalid-path", "root dir is not a directory");
|
|
4982
5762
|
}
|
|
@@ -4998,10 +5778,28 @@ async function resolveRootContext(rootDir) {
|
|
|
4998
5778
|
rootWithSep: ensureTrailingSep(rootReal),
|
|
4999
5779
|
};
|
|
5000
5780
|
}
|
|
5781
|
+
function rootRelativeReadPath(root, filePath) {
|
|
5782
|
+
const absoluteInput = external_node_path_namespaceObject.isAbsolute(filePath);
|
|
5783
|
+
const candidatePath = absoluteInput
|
|
5784
|
+
? external_node_path_namespaceObject.resolve(filePath)
|
|
5785
|
+
: external_node_path_namespaceObject.resolve(root.rootDir, filePath);
|
|
5786
|
+
let relativeBase = root.rootDir;
|
|
5787
|
+
if (absoluteInput &&
|
|
5788
|
+
!path_isPathInside(root.rootDir, candidatePath) &&
|
|
5789
|
+
path_isPathInside(root.rootReal, candidatePath)) {
|
|
5790
|
+
// A Root created through an alias has two valid in-root absolute spellings.
|
|
5791
|
+
relativeBase = root.rootReal;
|
|
5792
|
+
}
|
|
5793
|
+
return external_node_path_namespaceObject.relative(relativeBase, candidatePath);
|
|
5794
|
+
}
|
|
5001
5795
|
async function assertRootIdentityCurrent(root) {
|
|
5002
5796
|
let current;
|
|
5003
5797
|
try {
|
|
5004
|
-
|
|
5798
|
+
if (typeof root.rootIdentity.dev === "bigint" && typeof root.rootIdentity.ino === "bigint") {
|
|
5799
|
+
await inspectDirectoryIdentity(root.rootReal, { dev: root.rootIdentity.dev, ino: root.rootIdentity.ino });
|
|
5800
|
+
return;
|
|
5801
|
+
}
|
|
5802
|
+
current = external_node_fs_namespaceObject.lstatSync(root.rootReal);
|
|
5005
5803
|
}
|
|
5006
5804
|
catch (error) {
|
|
5007
5805
|
throw new errors_FsSafeError("path-mismatch", "root path changed during operation", {
|
|
@@ -5029,7 +5827,7 @@ async function resolvePathInRoot(root, relativePath, options) {
|
|
|
5029
5827
|
? expanded
|
|
5030
5828
|
: `${root.rootWithSep}${expanded}`;
|
|
5031
5829
|
try {
|
|
5032
|
-
await
|
|
5830
|
+
await root_path_resolveRootPath({
|
|
5033
5831
|
absolutePath: rawAbsolutePath,
|
|
5034
5832
|
rootPath: root.rootReal,
|
|
5035
5833
|
rootCanonicalPath: root.rootReal,
|
|
@@ -5107,17 +5905,19 @@ async function* walkRoot(root, relativePath, options) {
|
|
|
5107
5905
|
const maxEntries = validateBudget("maxEntries", options.maxEntries);
|
|
5108
5906
|
const visitedDirectories = new Set();
|
|
5109
5907
|
let examined = 0;
|
|
5908
|
+
let truncated = false;
|
|
5110
5909
|
const onLimit = (atPath) => {
|
|
5111
5910
|
if ((options.limitBehavior ?? "truncate") === "throw") {
|
|
5112
5911
|
throw new errors_FsSafeError("too-large", `root walk budget exceeded at ${atPath || "."}`);
|
|
5113
5912
|
}
|
|
5913
|
+
truncated = true;
|
|
5114
5914
|
return limitEntry(atPath);
|
|
5115
5915
|
};
|
|
5116
5916
|
async function* visit(directory, depth) {
|
|
5117
5917
|
options.signal?.throwIfAborted();
|
|
5118
5918
|
let entries;
|
|
5119
5919
|
try {
|
|
5120
|
-
const resolvedDirectory = await
|
|
5920
|
+
const resolvedDirectory = await root_path_resolveRootPath({
|
|
5121
5921
|
absolutePath: external_node_path_namespaceObject.resolve(root.rootReal, directory),
|
|
5122
5922
|
rootPath: root.rootReal,
|
|
5123
5923
|
rootCanonicalPath: root.rootReal,
|
|
@@ -5161,7 +5961,7 @@ async function* walkRoot(root, relativePath, options) {
|
|
|
5161
5961
|
if (options.symlinkPolicy === "skip") {
|
|
5162
5962
|
continue;
|
|
5163
5963
|
}
|
|
5164
|
-
const resolved = await
|
|
5964
|
+
const resolved = await root_path_resolveRootPath({
|
|
5165
5965
|
absolutePath: external_node_path_namespaceObject.resolve(root.rootReal, child),
|
|
5166
5966
|
rootPath: root.rootReal,
|
|
5167
5967
|
rootCanonicalPath: root.rootReal,
|
|
@@ -5192,6 +5992,8 @@ async function* walkRoot(root, relativePath, options) {
|
|
|
5192
5992
|
return;
|
|
5193
5993
|
}
|
|
5194
5994
|
yield* visit(child, depth + 1);
|
|
5995
|
+
if (truncated)
|
|
5996
|
+
return;
|
|
5195
5997
|
}
|
|
5196
5998
|
}
|
|
5197
5999
|
yield* visit(relativePath, 0);
|
|
@@ -5209,7 +6011,7 @@ function pathStillMatchesReceipt(entry) {
|
|
|
5209
6011
|
try {
|
|
5210
6012
|
const current = external_node_fs_namespaceObject.lstatSync(entry.path, { bigint: true });
|
|
5211
6013
|
return (!entry.singleLinkFile || (current.isFile() && current.nlink === 1n)) &&
|
|
5212
|
-
|
|
6014
|
+
file_identity_sameFileIdentityForCleanup(current, entry.identity);
|
|
5213
6015
|
}
|
|
5214
6016
|
catch (error) {
|
|
5215
6017
|
return !entry.singleLinkFile && error.code === "ENOENT";
|
|
@@ -5240,7 +6042,7 @@ function cleanupRegisteredTempPathsSync() {
|
|
|
5240
6042
|
}
|
|
5241
6043
|
tempCleanupEntries.clear();
|
|
5242
6044
|
}
|
|
5243
|
-
function
|
|
6045
|
+
function temp_cleanup_registerTempPathForExit(tempPath, options) {
|
|
5244
6046
|
if (!cleanupRegistered) {
|
|
5245
6047
|
cleanupRegistered = true;
|
|
5246
6048
|
process.once("exit", cleanupRegisteredTempPathsSync);
|
|
@@ -5344,21 +6146,27 @@ async function verifyAtomicWriteResult(params) {
|
|
|
5344
6146
|
throw new errors_FsSafeError("path-mismatch", "descriptor changed during write");
|
|
5345
6147
|
}
|
|
5346
6148
|
assertFile(stat);
|
|
6149
|
+
if (process.platform !== "win32" && params.expectedMode !== undefined) {
|
|
6150
|
+
const actualMode = Number(stat.mode & 4095n);
|
|
6151
|
+
if (actualMode !== params.expectedMode) {
|
|
6152
|
+
throw new Error(`Private secret file ${params.targetPath} has insecure permissions ${actualMode.toString(8)}.`);
|
|
6153
|
+
}
|
|
6154
|
+
}
|
|
5347
6155
|
return stat;
|
|
5348
6156
|
};
|
|
5349
6157
|
try {
|
|
5350
6158
|
// This descriptor remains owned by the writer, even when final mode forbids opens.
|
|
5351
6159
|
const stat = assertDescriptor();
|
|
5352
|
-
assertPath(
|
|
5353
|
-
const realPath = await resolveOpenedFileRealPathForFd(params.fd, stat, params.targetPath);
|
|
5354
|
-
assertPath(
|
|
6160
|
+
assertPath(external_node_fs_namespaceObject.lstatSync(params.targetPath, { bigint: true }));
|
|
6161
|
+
const { realPath } = await resolveOpenedFileRealPathForFd(params.fd, stat, params.targetPath);
|
|
6162
|
+
assertPath(external_node_fs_namespaceObject.statSync(realPath, { bigint: true }));
|
|
5355
6163
|
if (!path_isPathInside(params.root.rootWithSep, realPath)) {
|
|
5356
6164
|
throw outsideWorkspaceError();
|
|
5357
6165
|
}
|
|
5358
|
-
await
|
|
6166
|
+
await directory_guard_assertAsyncDirectoryGuard(params.parentGuard);
|
|
5359
6167
|
await assertRootIdentityCurrent(params.root);
|
|
5360
6168
|
// Recheck after canonical resolution and directory checks, including late links.
|
|
5361
|
-
assertPath(
|
|
6169
|
+
assertPath(external_node_fs_namespaceObject.lstatSync(params.targetPath, { bigint: true }));
|
|
5362
6170
|
assertDescriptor();
|
|
5363
6171
|
if (needsPathOpen) {
|
|
5364
6172
|
// A retained fd cannot prove that an opaque Windows pathname still names it.
|
|
@@ -5376,15 +6184,15 @@ async function verifyAtomicWriteResult(params) {
|
|
|
5376
6184
|
});
|
|
5377
6185
|
try {
|
|
5378
6186
|
const reopenedStat = assertDescriptor(opened.fd);
|
|
5379
|
-
assertPath(
|
|
5380
|
-
const reopenedPath = await resolveOpenedFileRealPathForFd(opened.fd, reopenedStat, params.targetPath);
|
|
5381
|
-
assertPath(
|
|
6187
|
+
assertPath(external_node_fs_namespaceObject.lstatSync(params.targetPath, { bigint: true }));
|
|
6188
|
+
const { realPath: reopenedPath } = await resolveOpenedFileRealPathForFd(opened.fd, reopenedStat, params.targetPath);
|
|
6189
|
+
assertPath(external_node_fs_namespaceObject.statSync(reopenedPath, { bigint: true }));
|
|
5382
6190
|
if (!path_isPathInside(params.root.rootWithSep, reopenedPath)) {
|
|
5383
6191
|
throw outsideWorkspaceError();
|
|
5384
6192
|
}
|
|
5385
|
-
await
|
|
6193
|
+
await directory_guard_assertAsyncDirectoryGuard(params.parentGuard);
|
|
5386
6194
|
await assertRootIdentityCurrent(params.root);
|
|
5387
|
-
assertPath(
|
|
6195
|
+
assertPath(external_node_fs_namespaceObject.lstatSync(params.targetPath, { bigint: true }));
|
|
5388
6196
|
assertDescriptor(opened.fd);
|
|
5389
6197
|
}
|
|
5390
6198
|
finally {
|
|
@@ -5399,6 +6207,74 @@ async function verifyAtomicWriteResult(params) {
|
|
|
5399
6207
|
}
|
|
5400
6208
|
}
|
|
5401
6209
|
|
|
6210
|
+
;// CONCATENATED MODULE: ../../node_modules/@openclaw/fs-safe/dist/root-write-mode.js
|
|
6211
|
+
|
|
6212
|
+
|
|
6213
|
+
|
|
6214
|
+
|
|
6215
|
+
|
|
6216
|
+
|
|
6217
|
+
|
|
6218
|
+
|
|
6219
|
+
// The caller has already resolved and guarded this write target.
|
|
6220
|
+
async function inheritWriteTargetMode(params) {
|
|
6221
|
+
try {
|
|
6222
|
+
const existing = await strict_file_identity_inspectFileIdentity(() => external_node_fs_namespaceObject.lstatSync(params.targetPath, { bigint: true }));
|
|
6223
|
+
if (existing.isSymbolicLink())
|
|
6224
|
+
throw new errors_FsSafeError("path-alias", "path alias escape blocked");
|
|
6225
|
+
if (!existing.isFile())
|
|
6226
|
+
throw new errors_FsSafeError("not-file", "not a file");
|
|
6227
|
+
if (existing.nlink > 1n)
|
|
6228
|
+
throw hardlinkedPathNotAllowedError();
|
|
6229
|
+
if (!path_isPathInside(params.rootWithSep, params.targetPath))
|
|
6230
|
+
throw outsideWorkspaceError();
|
|
6231
|
+
// Preserve read-open admission of the pre-existing destination. access(2)
|
|
6232
|
+
// is not equivalent: it ignores ACLs on Windows and capabilities on Linux.
|
|
6233
|
+
const handle = await promises_namespaceObject.open(params.targetPath, read_open_flags_resolveReadOpenFlags());
|
|
6234
|
+
try {
|
|
6235
|
+
// Bind admission to the inode whose metadata is inherited.
|
|
6236
|
+
if (!file_identity_sameFileIdentity(external_node_fs_namespaceObject.fstatSync(handle.fd, { bigint: true }), existing)) {
|
|
6237
|
+
throw new errors_FsSafeError("path-mismatch", "write target changed during mode inheritance");
|
|
6238
|
+
}
|
|
6239
|
+
}
|
|
6240
|
+
finally {
|
|
6241
|
+
await handle.close().catch(() => undefined);
|
|
6242
|
+
}
|
|
6243
|
+
try {
|
|
6244
|
+
// A parent can change after guarded resolution. Do not inherit metadata
|
|
6245
|
+
// from an outside inode, even if the parent is restored before publication.
|
|
6246
|
+
const realPath = external_node_fs_namespaceObject.realpathSync.native(params.targetPath);
|
|
6247
|
+
if (!path_isPathInside(params.rootWithSep, realPath))
|
|
6248
|
+
throw outsideWorkspaceError();
|
|
6249
|
+
await strict_file_identity_inspectFileIdentity(async () => {
|
|
6250
|
+
const current = external_node_fs_namespaceObject.statSync(realPath, { bigint: true });
|
|
6251
|
+
if (!current.isFile())
|
|
6252
|
+
throw new errors_FsSafeError("not-file", "not a file");
|
|
6253
|
+
if (current.nlink > 1n)
|
|
6254
|
+
throw hardlinkedPathNotAllowedError();
|
|
6255
|
+
return current;
|
|
6256
|
+
}, existing);
|
|
6257
|
+
}
|
|
6258
|
+
catch (error) {
|
|
6259
|
+
if (path_isNotFoundPathError(error)) {
|
|
6260
|
+
throw new errors_FsSafeError("path-mismatch", "write target changed during mode inheritance", { cause: error });
|
|
6261
|
+
}
|
|
6262
|
+
throw error;
|
|
6263
|
+
}
|
|
6264
|
+
return params.requestedMode ?? Number(existing.mode & 511n);
|
|
6265
|
+
}
|
|
6266
|
+
catch (error) {
|
|
6267
|
+
if (!path_isNotFoundPathError(error))
|
|
6268
|
+
throw error;
|
|
6269
|
+
return params.requestedMode ?? 0o600;
|
|
6270
|
+
}
|
|
6271
|
+
}
|
|
6272
|
+
|
|
6273
|
+
;// CONCATENATED MODULE: ../../node_modules/@openclaw/fs-safe/dist/copy-publication.js
|
|
6274
|
+
// Internal composition hook; the descriptor is borrowed until the callback returns.
|
|
6275
|
+
// Kept off RootCopyOptions and all public package exports.
|
|
6276
|
+
const onCopyPublication = Symbol("onCopyPublication");
|
|
6277
|
+
|
|
5402
6278
|
;// CONCATENATED MODULE: ../../node_modules/@openclaw/fs-safe/dist/root-impl.js
|
|
5403
6279
|
|
|
5404
6280
|
|
|
@@ -5428,6 +6304,9 @@ async function verifyAtomicWriteResult(params) {
|
|
|
5428
6304
|
|
|
5429
6305
|
|
|
5430
6306
|
|
|
6307
|
+
|
|
6308
|
+
|
|
6309
|
+
|
|
5431
6310
|
|
|
5432
6311
|
|
|
5433
6312
|
|
|
@@ -5440,12 +6319,14 @@ function logWarn(message) {
|
|
|
5440
6319
|
const SUPPORTS_NOFOLLOW = process.platform !== "win32" && "O_NOFOLLOW" in external_node_fs_namespaceObject.constants;
|
|
5441
6320
|
const OPEN_READ_FLAGS = read_open_flags_resolveReadOpenFlags();
|
|
5442
6321
|
const OPEN_READ_FOLLOW_FLAGS = read_open_flags_resolveReadOpenFlags({ followSymlinks: true });
|
|
5443
|
-
const OPEN_WRITE_EXISTING_FLAGS = external_node_fs_namespaceObject.constants.O_WRONLY | (SUPPORTS_NOFOLLOW ? external_node_fs_namespaceObject.constants.O_NOFOLLOW : 0)
|
|
6322
|
+
const OPEN_WRITE_EXISTING_FLAGS = external_node_fs_namespaceObject.constants.O_WRONLY | (SUPPORTS_NOFOLLOW ? external_node_fs_namespaceObject.constants.O_NOFOLLOW : 0) |
|
|
6323
|
+
resolveNonblockingWriteFlag();
|
|
5444
6324
|
const OPEN_WRITE_CREATE_FLAGS = external_node_fs_namespaceObject.constants.O_WRONLY |
|
|
5445
6325
|
external_node_fs_namespaceObject.constants.O_CREAT |
|
|
5446
6326
|
external_node_fs_namespaceObject.constants.O_EXCL |
|
|
5447
6327
|
(SUPPORTS_NOFOLLOW ? external_node_fs_namespaceObject.constants.O_NOFOLLOW : 0);
|
|
5448
|
-
const OPEN_APPEND_EXISTING_FLAGS = external_node_fs_namespaceObject.constants.O_RDWR | external_node_fs_namespaceObject.constants.O_APPEND | (SUPPORTS_NOFOLLOW ? external_node_fs_namespaceObject.constants.O_NOFOLLOW : 0)
|
|
6328
|
+
const OPEN_APPEND_EXISTING_FLAGS = external_node_fs_namespaceObject.constants.O_RDWR | external_node_fs_namespaceObject.constants.O_APPEND | (SUPPORTS_NOFOLLOW ? external_node_fs_namespaceObject.constants.O_NOFOLLOW : 0) |
|
|
6329
|
+
resolveNonblockingWriteFlag();
|
|
5449
6330
|
const OPEN_APPEND_CREATE_FLAGS = external_node_fs_namespaceObject.constants.O_RDWR |
|
|
5450
6331
|
external_node_fs_namespaceObject.constants.O_APPEND |
|
|
5451
6332
|
external_node_fs_namespaceObject.constants.O_CREAT |
|
|
@@ -5484,8 +6365,8 @@ async function openVerifiedLocalFile(filePath, options) {
|
|
|
5484
6365
|
// Reject directories before opening so we never surface EISDIR to callers (e.g. tool
|
|
5485
6366
|
// results that get sent to messaging channels). See openclaw/openclaw#31186.
|
|
5486
6367
|
try {
|
|
5487
|
-
preOpenStat = await
|
|
5488
|
-
const stat =
|
|
6368
|
+
preOpenStat = await strict_file_identity_inspectFileIdentity(async () => {
|
|
6369
|
+
const stat = external_node_fs_namespaceObject.lstatSync(filePath, { bigint: true });
|
|
5489
6370
|
observedBeforeOpen = true;
|
|
5490
6371
|
if (stat.isSymbolicLink() && options?.symlinks !== "follow-within-root") {
|
|
5491
6372
|
throw new errors_FsSafeError("symlink", "symlink not allowed");
|
|
@@ -5525,13 +6406,13 @@ async function openVerifiedLocalFile(filePath, options) {
|
|
|
5525
6406
|
}
|
|
5526
6407
|
try {
|
|
5527
6408
|
await fsSafeTestHooks?.afterOpen?.(filePath, handle);
|
|
5528
|
-
const stat =
|
|
6409
|
+
const stat = external_node_fs_namespaceObject.fstatSync(handle.fd);
|
|
5529
6410
|
if (!stat.isFile()) {
|
|
5530
6411
|
throw new errors_FsSafeError("not-file", "not a file");
|
|
5531
6412
|
}
|
|
5532
6413
|
// Keep numeric Stats for the public receipt, never for identity verification.
|
|
5533
6414
|
let openedIdentity;
|
|
5534
|
-
const identity = await
|
|
6415
|
+
const identity = await strict_file_identity_inspectFileIdentity(async () => (openedIdentity = external_node_fs_namespaceObject.fstatSync(handle.fd, { bigint: true })), preOpenStat && !preOpenStat.isSymbolicLink() ? preOpenStat : undefined).catch(async (error) => {
|
|
5535
6416
|
if ([0, 1].includes(stat.nlink)) {
|
|
5536
6417
|
await recordPreOpenFileChange(error, handle, filePath, preOpenStat, openedIdentity);
|
|
5537
6418
|
}
|
|
@@ -5542,7 +6423,7 @@ async function openVerifiedLocalFile(filePath, options) {
|
|
|
5542
6423
|
}
|
|
5543
6424
|
const inspectPathIdentity = async (inspect) => {
|
|
5544
6425
|
try {
|
|
5545
|
-
return await
|
|
6426
|
+
return await strict_file_identity_inspectFileIdentity(inspect, identity);
|
|
5546
6427
|
}
|
|
5547
6428
|
catch (error) {
|
|
5548
6429
|
const failure = path_isNotFoundPathError(error) ? openedPathResolutionError(fileNotFoundError()) : error;
|
|
@@ -5554,23 +6435,28 @@ async function openVerifiedLocalFile(filePath, options) {
|
|
|
5554
6435
|
};
|
|
5555
6436
|
await inspectPathIdentity(async () => {
|
|
5556
6437
|
const pathStat = options?.symlinks === "follow-within-root"
|
|
5557
|
-
?
|
|
5558
|
-
:
|
|
6438
|
+
? external_node_fs_namespaceObject.statSync(filePath, { bigint: true })
|
|
6439
|
+
: external_node_fs_namespaceObject.lstatSync(filePath, { bigint: true });
|
|
5559
6440
|
if (pathStat.isSymbolicLink() && options?.symlinks !== "follow-within-root") {
|
|
5560
6441
|
throw new errors_FsSafeError("symlink", "symlink not allowed");
|
|
5561
6442
|
}
|
|
5562
6443
|
return pathStat;
|
|
5563
6444
|
});
|
|
5564
6445
|
await fsSafeTestHooks?.afterOpenedPathIdentityCheck?.(filePath, handle);
|
|
5565
|
-
const
|
|
6446
|
+
const resolved = await resolveOpenedFileRealPathForFd(handle.fd, identity, filePath)
|
|
5566
6447
|
.catch(async (error) => {
|
|
5567
6448
|
if (stat.nlink <= 1 && (!preOpenStat || preOpenStat.nlink <= 1n)) {
|
|
5568
6449
|
await recordOpenedFileFailure(error, handle, filePath, identity);
|
|
5569
6450
|
}
|
|
5570
6451
|
throw error;
|
|
5571
6452
|
});
|
|
6453
|
+
const { realPath } = resolved;
|
|
6454
|
+
let resolvedStat = resolved.stat;
|
|
5572
6455
|
await inspectPathIdentity(async () => {
|
|
5573
|
-
|
|
6456
|
+
// Reuse the post-realpath observation; unknown Windows identities still
|
|
6457
|
+
// get a fresh observation on inspectFileIdentity's retry.
|
|
6458
|
+
const realStat = resolvedStat ?? external_node_fs_namespaceObject.statSync(realPath, { bigint: true });
|
|
6459
|
+
resolvedStat = undefined;
|
|
5574
6460
|
if (options?.hardlinks === "reject" && realStat.nlink > 1n) {
|
|
5575
6461
|
throw hardlinkedPathNotAllowedError();
|
|
5576
6462
|
}
|
|
@@ -5668,6 +6554,7 @@ class RootHandle {
|
|
|
5668
6554
|
mkdir: this.defaults.mkdir,
|
|
5669
6555
|
mode: this.defaults.mode,
|
|
5670
6556
|
...this.mutationOptions(options),
|
|
6557
|
+
durable: options.durable ?? this.defaults.durable ?? true,
|
|
5671
6558
|
});
|
|
5672
6559
|
}
|
|
5673
6560
|
async remove(relativePath, options = {}) {
|
|
@@ -5700,6 +6587,7 @@ class RootHandle {
|
|
|
5700
6587
|
mode: this.defaults.mode,
|
|
5701
6588
|
renameIdentity: this.defaults.renameIdentity,
|
|
5702
6589
|
...this.mutationOptions(options),
|
|
6590
|
+
durable: options.durable ?? this.defaults.durable ?? true,
|
|
5703
6591
|
});
|
|
5704
6592
|
}
|
|
5705
6593
|
async create(relativePath, data, options = {}) {
|
|
@@ -5710,6 +6598,7 @@ class RootHandle {
|
|
|
5710
6598
|
mkdir: this.defaults.mkdir,
|
|
5711
6599
|
mode: this.defaults.mode,
|
|
5712
6600
|
...this.mutationOptions(options),
|
|
6601
|
+
durable: options.durable ?? this.defaults.durable ?? true,
|
|
5713
6602
|
overwrite: false,
|
|
5714
6603
|
});
|
|
5715
6604
|
}
|
|
@@ -5733,6 +6622,8 @@ class RootHandle {
|
|
|
5733
6622
|
mkdir: this.defaults.mkdir,
|
|
5734
6623
|
mode: this.defaults.mode,
|
|
5735
6624
|
...copyOptions,
|
|
6625
|
+
durable: options.durable ?? this.defaults.durable ?? true,
|
|
6626
|
+
verifyPublished: options[onCopyPublication],
|
|
5736
6627
|
});
|
|
5737
6628
|
}
|
|
5738
6629
|
async exists(relativePath) {
|
|
@@ -5783,7 +6674,6 @@ function readDefaults(defaults) {
|
|
|
5783
6674
|
return {
|
|
5784
6675
|
hardlinks: defaults.hardlinks,
|
|
5785
6676
|
maxBytes: byte_budget_normalizeMaxBytes(defaults.maxBytes, { defaultValue: DEFAULT_ROOT_MAX_BYTES }),
|
|
5786
|
-
nonBlockingRead: defaults.nonBlockingRead,
|
|
5787
6677
|
symlinks: defaults.symlinks,
|
|
5788
6678
|
};
|
|
5789
6679
|
}
|
|
@@ -5792,8 +6682,6 @@ function mergeReadOptions(defaults, options) {
|
|
|
5792
6682
|
if (options.hardlinks !== undefined)
|
|
5793
6683
|
merged.hardlinks = options.hardlinks;
|
|
5794
6684
|
merged.maxBytes = byte_budget_normalizeMaxBytes(options.maxBytes, { defaultValue: merged.maxBytes });
|
|
5795
|
-
if (options.nonBlockingRead !== undefined)
|
|
5796
|
-
merged.nonBlockingRead = options.nonBlockingRead;
|
|
5797
6685
|
if (options.symlinks !== undefined)
|
|
5798
6686
|
merged.symlinks = options.symlinks;
|
|
5799
6687
|
return merged;
|
|
@@ -5809,7 +6697,6 @@ async function openFileInRoot(root, params) {
|
|
|
5809
6697
|
rejectSymlinks: params.symlinks !== "follow-within-root",
|
|
5810
6698
|
});
|
|
5811
6699
|
const { opened } = await openVerifiedLocalFile(resolved, {
|
|
5812
|
-
nonBlockingRead: params.nonBlockingRead,
|
|
5813
6700
|
symlinks: params.symlinks,
|
|
5814
6701
|
});
|
|
5815
6702
|
if (params.hardlinks !== "allow" && opened.stat.nlink > 1) {
|
|
@@ -5832,16 +6719,11 @@ async function readFileInRoot(root, params) {
|
|
|
5832
6719
|
}
|
|
5833
6720
|
}
|
|
5834
6721
|
async function readPathInRoot(root, params) {
|
|
5835
|
-
const
|
|
5836
|
-
const candidatePath = external_node_path_namespaceObject.isAbsolute(params.filePath)
|
|
5837
|
-
? external_node_path_namespaceObject.resolve(params.filePath)
|
|
5838
|
-
: external_node_path_namespaceObject.resolve(rootDir, params.filePath);
|
|
5839
|
-
const relativePath = external_node_path_namespaceObject.relative(rootDir, candidatePath);
|
|
6722
|
+
const relativePath = rootRelativeReadPath(root, params.filePath);
|
|
5840
6723
|
return await readFileInRoot(root, {
|
|
5841
6724
|
relativePath,
|
|
5842
6725
|
hardlinks: params.hardlinks,
|
|
5843
6726
|
maxBytes: params.maxBytes,
|
|
5844
|
-
nonBlockingRead: params.nonBlockingRead,
|
|
5845
6727
|
symlinks: params.symlinks,
|
|
5846
6728
|
});
|
|
5847
6729
|
}
|
|
@@ -5888,7 +6770,7 @@ async function writeTempFileForAtomicReplace(params) {
|
|
|
5888
6770
|
}
|
|
5889
6771
|
return {
|
|
5890
6772
|
handle: tempHandle,
|
|
5891
|
-
identity:
|
|
6773
|
+
identity: external_node_fs_namespaceObject.fstatSync(tempHandle.fd, { bigint: true }),
|
|
5892
6774
|
};
|
|
5893
6775
|
}
|
|
5894
6776
|
catch (error) {
|
|
@@ -5927,7 +6809,7 @@ async function openWritableFileInRoot(root, params) {
|
|
|
5927
6809
|
? resolved
|
|
5928
6810
|
: await prepareRootWriteTarget(rootReal, resolved);
|
|
5929
6811
|
try {
|
|
5930
|
-
const resolvedRealPath =
|
|
6812
|
+
const resolvedRealPath = external_node_fs_namespaceObject.realpathSync.native(ioPath);
|
|
5931
6813
|
if (!path_isPathInside(rootWithSep, resolvedRealPath)) {
|
|
5932
6814
|
throw outsideWorkspaceError();
|
|
5933
6815
|
}
|
|
@@ -5951,6 +6833,9 @@ async function openWritableFileInRoot(root, params) {
|
|
|
5951
6833
|
handle = await promises_namespaceObject.open(ioPath, existingFlags, mode);
|
|
5952
6834
|
}
|
|
5953
6835
|
catch (err) {
|
|
6836
|
+
if (await isNonRegularWriteOpenError(err, ioPath, existingFlags)) {
|
|
6837
|
+
throw new errors_FsSafeError("not-file", "path is not a regular file under root");
|
|
6838
|
+
}
|
|
5954
6839
|
if (!path_isNotFoundPathError(err)) {
|
|
5955
6840
|
throw err;
|
|
5956
6841
|
}
|
|
@@ -5973,7 +6858,7 @@ async function openWritableFileInRoot(root, params) {
|
|
|
5973
6858
|
let realPathForCleanup = null;
|
|
5974
6859
|
let createdIdentity = null;
|
|
5975
6860
|
try {
|
|
5976
|
-
const stat =
|
|
6861
|
+
const stat = external_node_fs_namespaceObject.fstatSync(handle.fd);
|
|
5977
6862
|
if (createdForWrite) {
|
|
5978
6863
|
createdIdentity = stat;
|
|
5979
6864
|
}
|
|
@@ -5984,7 +6869,7 @@ async function openWritableFileInRoot(root, params) {
|
|
|
5984
6869
|
throw hardlinkedPathNotAllowedError();
|
|
5985
6870
|
}
|
|
5986
6871
|
try {
|
|
5987
|
-
const lstat =
|
|
6872
|
+
const lstat = external_node_fs_namespaceObject.lstatSync(ioPath);
|
|
5988
6873
|
if (lstat.isSymbolicLink() || !lstat.isFile()) {
|
|
5989
6874
|
throw new errors_FsSafeError(lstat.isSymbolicLink() ? "symlink" : "not-file", "path is not a regular file under root");
|
|
5990
6875
|
}
|
|
@@ -5999,7 +6884,7 @@ async function openWritableFileInRoot(root, params) {
|
|
|
5999
6884
|
}
|
|
6000
6885
|
const realPath = await resolveOpenedFileRealPathForHandle(handle, ioPath);
|
|
6001
6886
|
realPathForCleanup = realPath;
|
|
6002
|
-
const realStat =
|
|
6887
|
+
const realStat = external_node_fs_namespaceObject.statSync(realPath);
|
|
6003
6888
|
if (!file_identity_sameFileIdentity(stat, realStat)) {
|
|
6004
6889
|
throw new errors_FsSafeError("path-mismatch", "path mismatch");
|
|
6005
6890
|
}
|
|
@@ -6062,8 +6947,9 @@ async function appendFileInRoot(root, params) {
|
|
|
6062
6947
|
const payload = prefix.length > 0 ? Buffer.concat([Buffer.from(prefix, "utf8"), params.data]) : params.data;
|
|
6063
6948
|
await target.handle.appendFile(payload);
|
|
6064
6949
|
}
|
|
6065
|
-
|
|
6066
|
-
|
|
6950
|
+
if (params.durable !== false)
|
|
6951
|
+
await target.handle.sync();
|
|
6952
|
+
if (params.durable !== false && target.createdForWrite) {
|
|
6067
6953
|
await syncDirectoryBestEffort(external_node_path_namespaceObject.dirname(target.realPath));
|
|
6068
6954
|
}
|
|
6069
6955
|
}
|
|
@@ -6119,6 +7005,7 @@ async function commitPinnedWriteInRoot(root, pinned, params) {
|
|
|
6119
7005
|
renameIdentity: params.renameIdentity,
|
|
6120
7006
|
mkdir: params.mkdir !== false,
|
|
6121
7007
|
mode: params.mode ?? pinned.mode,
|
|
7008
|
+
sync: params.durable !== false,
|
|
6122
7009
|
overwrite: params.overwrite,
|
|
6123
7010
|
input: { kind: "buffer", data: params.data, encoding: params.encoding },
|
|
6124
7011
|
rootIdentity: root.rootIdentity,
|
|
@@ -6180,6 +7067,8 @@ async function copyFileInRoot(root, params) {
|
|
|
6180
7067
|
mode: pinned.mode,
|
|
6181
7068
|
overwrite: true,
|
|
6182
7069
|
maxBytes: params.maxBytes,
|
|
7070
|
+
sync: params.durable !== false,
|
|
7071
|
+
verifyPublished: params.verifyPublished,
|
|
6183
7072
|
input: { kind: "stream", stream: source.handle.createReadStream() },
|
|
6184
7073
|
rootIdentity: root.rootIdentity,
|
|
6185
7074
|
});
|
|
@@ -6202,12 +7091,12 @@ async function copyFileInRoot(root, params) {
|
|
|
6202
7091
|
}
|
|
6203
7092
|
}
|
|
6204
7093
|
async function assertCopySourceCurrent(source, identity) {
|
|
6205
|
-
await
|
|
7094
|
+
await strict_file_identity_inspectFileIdentity(() => external_node_fs_namespaceObject.fstatSync(source.handle.fd, { bigint: true }), identity);
|
|
6206
7095
|
await assertCopySourcePathCurrent(source, identity);
|
|
6207
7096
|
}
|
|
6208
7097
|
async function assertCopySourcePathCurrent(source, identity) {
|
|
6209
|
-
await
|
|
6210
|
-
const current =
|
|
7098
|
+
await strict_file_identity_inspectFileIdentity(async () => {
|
|
7099
|
+
const current = external_node_fs_namespaceObject.lstatSync(source.realPath, { bigint: true });
|
|
6211
7100
|
if (current.isSymbolicLink() || !current.isFile()) {
|
|
6212
7101
|
throw new errors_FsSafeError("path-mismatch", "copy source path changed");
|
|
6213
7102
|
}
|
|
@@ -6216,8 +7105,8 @@ async function assertCopySourcePathCurrent(source, identity) {
|
|
|
6216
7105
|
}
|
|
6217
7106
|
async function removePathIfIdentityUnchanged(targetPath, identity) {
|
|
6218
7107
|
const parentGuard = await directory_guard_createAsyncDirectoryGuard(external_node_path_namespaceObject.dirname(targetPath));
|
|
6219
|
-
const current =
|
|
6220
|
-
if (current.isSymbolicLink() || !
|
|
7108
|
+
const current = external_node_fs_namespaceObject.lstatSync(targetPath);
|
|
7109
|
+
if (current.isSymbolicLink() || !file_identity_sameFileIdentityForCleanup(current, identity)) {
|
|
6221
7110
|
return;
|
|
6222
7111
|
}
|
|
6223
7112
|
await withAsyncDirectoryGuards([parentGuard], async () => {
|
|
@@ -6246,7 +7135,7 @@ async function resolvePinnedWriteTargetInRoot(root, relativePath, requestedMode,
|
|
|
6246
7135
|
// and alias checks, but never open a competing owner's record just to reject it.
|
|
6247
7136
|
if (!overwrite) {
|
|
6248
7137
|
try {
|
|
6249
|
-
const existing =
|
|
7138
|
+
const existing = external_node_fs_namespaceObject.statSync(resolved);
|
|
6250
7139
|
if (!existing.isFile())
|
|
6251
7140
|
throw new errors_FsSafeError("not-file", "not a file");
|
|
6252
7141
|
if (existing.nlink > 1)
|
|
@@ -6258,31 +7147,9 @@ async function resolvePinnedWriteTargetInRoot(root, relativePath, requestedMode,
|
|
|
6258
7147
|
throw error;
|
|
6259
7148
|
}
|
|
6260
7149
|
}
|
|
6261
|
-
|
|
6262
|
-
|
|
6263
|
-
|
|
6264
|
-
const opened = await openFileInRoot(root, {
|
|
6265
|
-
relativePath,
|
|
6266
|
-
hardlinks: "reject",
|
|
6267
|
-
nonBlockingRead: true,
|
|
6268
|
-
symlinks: "follow-within-root",
|
|
6269
|
-
});
|
|
6270
|
-
try {
|
|
6271
|
-
mode = requestedMode ?? (opened.stat.mode & 0o777);
|
|
6272
|
-
if (!path_isPathInside(rootWithSep, opened.realPath)) {
|
|
6273
|
-
throw outsideWorkspaceError();
|
|
6274
|
-
}
|
|
6275
|
-
}
|
|
6276
|
-
finally {
|
|
6277
|
-
await opened.handle.close().catch(() => { });
|
|
6278
|
-
}
|
|
6279
|
-
}
|
|
6280
|
-
}
|
|
6281
|
-
catch (err) {
|
|
6282
|
-
if (!(err instanceof errors_FsSafeError) || err.code !== "not-found") {
|
|
6283
|
-
throw err;
|
|
6284
|
-
}
|
|
6285
|
-
}
|
|
7150
|
+
const mode = overwrite
|
|
7151
|
+
? await inheritWriteTargetMode({ targetPath: resolved, rootWithSep, requestedMode })
|
|
7152
|
+
: requestedMode ?? 0o600;
|
|
6286
7153
|
return {
|
|
6287
7154
|
rootReal,
|
|
6288
7155
|
targetPath: resolved,
|
|
@@ -6332,7 +7199,7 @@ async function resolvePinnedRootPathInRoot(root, params) {
|
|
|
6332
7199
|
let resolved;
|
|
6333
7200
|
try {
|
|
6334
7201
|
const expandedPath = await expandRelativePathWithHome(params.relativePath);
|
|
6335
|
-
resolved = await
|
|
7202
|
+
resolved = await root_path_resolveRootPath({
|
|
6336
7203
|
absolutePath: external_node_path_namespaceObject.isAbsolute(expandedPath)
|
|
6337
7204
|
? expandedPath
|
|
6338
7205
|
: `${ensureTrailingSep(rootReal)}${expandedPath}`,
|
|
@@ -6356,7 +7223,7 @@ async function prepareRemoveGuard(targetPath) {
|
|
|
6356
7223
|
try {
|
|
6357
7224
|
const guard = await directory_guard_createAsyncDirectoryGuard(external_node_path_namespaceObject.dirname(targetPath));
|
|
6358
7225
|
await getFsSafeTestHooks()?.beforeRootFallbackMutation?.("remove", targetPath);
|
|
6359
|
-
await
|
|
7226
|
+
await directory_guard_assertAsyncDirectoryGuard(guard);
|
|
6360
7227
|
return guard;
|
|
6361
7228
|
}
|
|
6362
7229
|
catch (error) {
|
|
@@ -6366,12 +7233,12 @@ async function prepareRemoveGuard(targetPath) {
|
|
|
6366
7233
|
async function removePathFallback(resolved) {
|
|
6367
7234
|
const guard = await prepareRemoveGuard(resolved.resolved);
|
|
6368
7235
|
try {
|
|
6369
|
-
await (
|
|
7236
|
+
await (external_node_fs_namespaceObject.lstatSync(resolved.resolved).isDirectory() ? promises_namespaceObject.rmdir(resolved.resolved) : promises_namespaceObject.rm(resolved.resolved));
|
|
6370
7237
|
}
|
|
6371
7238
|
catch (error) {
|
|
6372
7239
|
throw normalizeRemovePathError(error);
|
|
6373
7240
|
}
|
|
6374
|
-
await
|
|
7241
|
+
await directory_guard_assertAsyncDirectoryGuard(guard).catch(() => undefined);
|
|
6375
7242
|
}
|
|
6376
7243
|
async function mkdirPathFallback(resolved) {
|
|
6377
7244
|
await mkdirPathComponentsWithGuards({
|
|
@@ -6382,7 +7249,7 @@ async function mkdirPathFallback(resolved) {
|
|
|
6382
7249
|
async function statPathFallback(root, relativePath) {
|
|
6383
7250
|
const resolved = await resolvePinnedPathInRoot(root, { relativePath, allowRoot: true });
|
|
6384
7251
|
try {
|
|
6385
|
-
const stat = pathStatFromStats(
|
|
7252
|
+
const stat = pathStatFromStats(external_node_fs_namespaceObject.lstatSync(resolved.resolved));
|
|
6386
7253
|
await assertRootIdentityCurrent(root);
|
|
6387
7254
|
return stat;
|
|
6388
7255
|
}
|
|
@@ -6406,7 +7273,7 @@ async function listPathFallback(root, relativePath, withFileTypes) {
|
|
|
6406
7273
|
for (const name of sortedNames) {
|
|
6407
7274
|
entries.push({
|
|
6408
7275
|
name,
|
|
6409
|
-
...pathStatFromStats(
|
|
7276
|
+
...pathStatFromStats(external_node_fs_namespaceObject.lstatSync(external_node_path_namespaceObject.join(resolved.resolved, name))),
|
|
6410
7277
|
});
|
|
6411
7278
|
}
|
|
6412
7279
|
await assertRootIdentityCurrent(root);
|
|
@@ -6455,7 +7322,11 @@ async function movePathFallback(root, params) {
|
|
|
6455
7322
|
relativePath: params.toRelative,
|
|
6456
7323
|
policy: PATH_ALIAS_POLICIES.unlinkTarget,
|
|
6457
7324
|
});
|
|
6458
|
-
|
|
7325
|
+
let targetStat;
|
|
7326
|
+
try {
|
|
7327
|
+
targetStat = external_node_fs_namespaceObject.lstatSync(resolvedTarget.resolved);
|
|
7328
|
+
}
|
|
7329
|
+
catch { /* Advisory lookup. */ }
|
|
6459
7330
|
return !(process.platform !== "win32" &&
|
|
6460
7331
|
params.overwrite &&
|
|
6461
7332
|
targetStat?.isSymbolicLink() === true);
|
|
@@ -6463,7 +7334,7 @@ async function movePathFallback(root, params) {
|
|
|
6463
7334
|
});
|
|
6464
7335
|
let sourceStat;
|
|
6465
7336
|
try {
|
|
6466
|
-
sourceStat =
|
|
7337
|
+
sourceStat = external_node_fs_namespaceObject.lstatSync(source.resolved);
|
|
6467
7338
|
}
|
|
6468
7339
|
catch (error) {
|
|
6469
7340
|
if (path_isNotFoundPathError(error)) {
|
|
@@ -6482,7 +7353,7 @@ async function movePathFallback(root, params) {
|
|
|
6482
7353
|
}
|
|
6483
7354
|
if (!params.overwrite) {
|
|
6484
7355
|
try {
|
|
6485
|
-
|
|
7356
|
+
external_node_fs_namespaceObject.lstatSync(target.resolved);
|
|
6486
7357
|
throw new errors_FsSafeError("already-exists", "destination exists");
|
|
6487
7358
|
}
|
|
6488
7359
|
catch (error) {
|
|
@@ -6497,8 +7368,8 @@ async function movePathFallback(root, params) {
|
|
|
6497
7368
|
const sourceParentGuard = await directory_guard_createAsyncDirectoryGuard(external_node_path_namespaceObject.dirname(source.resolved));
|
|
6498
7369
|
const targetParentGuard = await directory_guard_createNearestExistingDirectoryGuard(target.rootReal, external_node_path_namespaceObject.dirname(target.resolved));
|
|
6499
7370
|
await getFsSafeTestHooks()?.beforeRootFallbackMutation?.("move", target.resolved);
|
|
6500
|
-
await
|
|
6501
|
-
await
|
|
7371
|
+
await directory_guard_assertAsyncDirectoryGuard(sourceParentGuard);
|
|
7372
|
+
await directory_guard_assertAsyncDirectoryGuard(targetParentGuard);
|
|
6502
7373
|
try {
|
|
6503
7374
|
await promises_namespaceObject.rename(source.resolved, target.resolved);
|
|
6504
7375
|
}
|
|
@@ -6513,7 +7384,7 @@ async function movePathFallback(root, params) {
|
|
|
6513
7384
|
}
|
|
6514
7385
|
throw error;
|
|
6515
7386
|
}
|
|
6516
|
-
await
|
|
7387
|
+
await directory_guard_assertAsyncDirectoryGuard(targetParentGuard).catch(() => undefined);
|
|
6517
7388
|
}
|
|
6518
7389
|
async function writeFileFallback(root, params) {
|
|
6519
7390
|
if (params.overwrite === false) {
|
|
@@ -6523,7 +7394,8 @@ async function writeFileFallback(root, params) {
|
|
|
6523
7394
|
const target = await openWritableFileInRoot(root, {
|
|
6524
7395
|
relativePath: params.relativePath,
|
|
6525
7396
|
mkdir: params.mkdir,
|
|
6526
|
-
|
|
7397
|
+
// Private, writable placeholder: Windows cannot rename over a read-only file.
|
|
7398
|
+
mode: 0o600,
|
|
6527
7399
|
denyMutations: params.denyMutations,
|
|
6528
7400
|
truncateExisting: false,
|
|
6529
7401
|
});
|
|
@@ -6536,12 +7408,12 @@ async function writeFileFallback(root, params) {
|
|
|
6536
7408
|
let writtenHandle;
|
|
6537
7409
|
try {
|
|
6538
7410
|
tempPath = buildAtomicWriteTempPath(destinationPath);
|
|
6539
|
-
unregisterTempPath =
|
|
7411
|
+
unregisterTempPath = temp_cleanup_registerTempPathForExit(tempPath);
|
|
6540
7412
|
const written = await writeTempFileForAtomicReplace({
|
|
6541
7413
|
tempPath,
|
|
6542
7414
|
data: params.data,
|
|
6543
7415
|
encoding: params.encoding,
|
|
6544
|
-
mode,
|
|
7416
|
+
mode: 0o600,
|
|
6545
7417
|
});
|
|
6546
7418
|
writtenHandle = written.handle;
|
|
6547
7419
|
unregisterTempPath.setIdentity(written.identity);
|
|
@@ -6552,6 +7424,14 @@ async function writeFileFallback(root, params) {
|
|
|
6552
7424
|
});
|
|
6553
7425
|
unregisterTempPath();
|
|
6554
7426
|
unregisterTempPath = null;
|
|
7427
|
+
// Final mode via the retained handle after publication, as the native writer does.
|
|
7428
|
+
try {
|
|
7429
|
+
await written.handle.chmod(mode);
|
|
7430
|
+
}
|
|
7431
|
+
catch (error) {
|
|
7432
|
+
await removePathIfIdentityUnchanged(destinationPath, written.identity).catch(() => { });
|
|
7433
|
+
throw error;
|
|
7434
|
+
}
|
|
6555
7435
|
try {
|
|
6556
7436
|
await verifyAtomicWriteResult({
|
|
6557
7437
|
root,
|
|
@@ -6589,11 +7469,11 @@ async function writeMissingFileFallback(root, params) {
|
|
|
6589
7469
|
let verifyingPublication = false;
|
|
6590
7470
|
try {
|
|
6591
7471
|
const { handle, writtenStat } = await withAsyncDirectoryGuards([parentGuard], async () => {
|
|
6592
|
-
const handle = await promises_namespaceObject.open(targetPath, OPEN_WRITE_CREATE_FLAGS, params.mode ?? 0o600);
|
|
7472
|
+
const handle = await promises_namespaceObject.open(targetPath, OPEN_WRITE_CREATE_FLAGS, params.mode ?? 0o600).catch((error) => recordExclusiveCreateFailure(error, targetPath));
|
|
6593
7473
|
created = true;
|
|
6594
7474
|
try {
|
|
6595
|
-
createdIdentity =
|
|
6596
|
-
const writtenStat =
|
|
7475
|
+
createdIdentity = external_node_fs_namespaceObject.fstatSync(handle.fd);
|
|
7476
|
+
const writtenStat = external_node_fs_namespaceObject.fstatSync(handle.fd, { bigint: true });
|
|
6597
7477
|
if (typeof params.data === "string") {
|
|
6598
7478
|
await handle.writeFile(params.data, params.encoding ?? "utf8");
|
|
6599
7479
|
}
|
|
@@ -19065,4 +19945,4 @@ if (installedChunkData !== 0) { // 0 means "already installed".'
|
|
|
19065
19945
|
// module factories are used so entry inlining is disabled
|
|
19066
19946
|
// startup
|
|
19067
19947
|
// Load entry module and return exports
|
|
19068
|
-
var __webpack_exports__ = __webpack_require__(
|
|
19948
|
+
var __webpack_exports__ = __webpack_require__(446);
|