@poe-platform/safe-bash 0.1.71 → 0.1.72
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.
|
@@ -3432,6 +3432,7 @@ function createDirectoryReader(maxEntries = 1e4) {
|
|
|
3432
3432
|
}
|
|
3433
3433
|
|
|
3434
3434
|
// packages/safe-bash/src/commands/filesystem.ts
|
|
3435
|
+
var MAX_RECURSIVE_DIRECTORY_DEPTH = 1024;
|
|
3435
3436
|
async function preflightOperands(context, operands, check) {
|
|
3436
3437
|
for (const operand of operands) {
|
|
3437
3438
|
try {
|
|
@@ -3514,11 +3515,19 @@ async function copy(context, source, target, flags, readDirectory, top = true, a
|
|
|
3514
3515
|
if (isPathWithin(physicalSource, physicalTarget)) throw new FsError("EINVAL", { path: target, message: "cannot copy a directory into itself" });
|
|
3515
3516
|
if (ancestors.has(physicalSource)) throw new FsError("ELOOP", { path: source });
|
|
3516
3517
|
if (targetStat && targetStat.type !== "directory") throw new FsError("ENOTDIR", { path: target });
|
|
3518
|
+
context.signal.throwIfAborted();
|
|
3519
|
+
if (ancestors.size > MAX_RECURSIVE_DIRECTORY_DEPTH) {
|
|
3520
|
+
throw new FsError("ELOOP", { path: source, message: `cp directory depth limit exceeded (${MAX_RECURSIVE_DIRECTORY_DEPTH})` });
|
|
3521
|
+
}
|
|
3517
3522
|
await admitFilesystemModes(context, "cp", ["recursive"], [target]);
|
|
3518
|
-
|
|
3519
|
-
|
|
3520
|
-
|
|
3521
|
-
|
|
3523
|
+
ancestors.add(physicalSource);
|
|
3524
|
+
try {
|
|
3525
|
+
if (!targetStat && !preflight) await context.fs.mkdir(target, { mode: sourceStat.mode & 511, signal: context.signal });
|
|
3526
|
+
for (const entry of await readDirectory(context, source, true)) {
|
|
3527
|
+
await copy(context, joinPath(source, entry.name), joinPath(target, entry.name), flags, readDirectory, false, ancestors, preflight);
|
|
3528
|
+
}
|
|
3529
|
+
} finally {
|
|
3530
|
+
ancestors.delete(physicalSource);
|
|
3522
3531
|
}
|
|
3523
3532
|
} else if (preserveLink) {
|
|
3524
3533
|
await admitFilesystemModes(context, "cp", ["symlink"], [target]);
|
|
@@ -3856,25 +3865,33 @@ function filesystemCommands(maxDirectoryEntries) {
|
|
|
3856
3865
|
await admitFilesystemModes(context, "ls", ["directory"], [path]);
|
|
3857
3866
|
const physical = await context.fs.realpath(path, { signal: context.signal });
|
|
3858
3867
|
if (ancestors.has(physical)) throw new FsError("ELOOP", { path });
|
|
3859
|
-
|
|
3860
|
-
if (
|
|
3861
|
-
|
|
3862
|
-
`);
|
|
3863
|
-
headerWritten = true;
|
|
3868
|
+
context.signal.throwIfAborted();
|
|
3869
|
+
if (ancestors.size > MAX_RECURSIVE_DIRECTORY_DEPTH) {
|
|
3870
|
+
throw new FsError("ELOOP", { path, message: `ls directory depth limit exceeded (${MAX_RECURSIVE_DIRECTORY_DEPTH})` });
|
|
3864
3871
|
}
|
|
3865
|
-
|
|
3866
|
-
|
|
3867
|
-
|
|
3868
|
-
|
|
3869
|
-
|
|
3870
|
-
|
|
3871
|
-
|
|
3872
|
-
|
|
3873
|
-
|
|
3874
|
-
if (
|
|
3875
|
-
|
|
3876
|
-
|
|
3877
|
-
|
|
3872
|
+
ancestors.add(physical);
|
|
3873
|
+
try {
|
|
3874
|
+
if (header) {
|
|
3875
|
+
await output(context, `${headerWritten ? "\n" : ""}${display}:
|
|
3876
|
+
`);
|
|
3877
|
+
headerWritten = true;
|
|
3878
|
+
}
|
|
3879
|
+
const entries = await readDirectory(context, path, true);
|
|
3880
|
+
const names = entries.map((entry) => entry.name).filter((name2) => parsed.flags.has("a") || parsed.flags.has("A") || !name2.startsWith("."));
|
|
3881
|
+
if (parsed.flags.has("a")) for (const name2 of [".", ".."]) {
|
|
3882
|
+
const index = names.findIndex((entry) => entry > name2);
|
|
3883
|
+
names.splice(index < 0 ? names.length : index, 0, name2);
|
|
3884
|
+
}
|
|
3885
|
+
if (parsed.flags.has("r")) names.reverse();
|
|
3886
|
+
for (const name2 of names) await render(joinPath(path, name2), name2);
|
|
3887
|
+
if (parsed.flags.has("R")) for (const name2 of names) {
|
|
3888
|
+
if (name2 === "." || name2 === "..") continue;
|
|
3889
|
+
const child = joinPath(path, name2);
|
|
3890
|
+
const childStat = await context.fs[parsed.flags.has("L") ? "stat" : "lstat"](child, { signal: context.signal });
|
|
3891
|
+
if (childStat.type === "directory") await list(child, `${display.replace(/\/$/u, "")}/${name2}`, true, ancestors);
|
|
3892
|
+
}
|
|
3893
|
+
} finally {
|
|
3894
|
+
ancestors.delete(physical);
|
|
3878
3895
|
}
|
|
3879
3896
|
};
|
|
3880
3897
|
return eachOperand(context, operands, (operand) => list(pathOf(context, operand), operand, operands.length > 1 || parsed.flags.has("R")));
|