openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
61 lines (60 loc) • 1.85 kB
JavaScript
import { t as formatErrorMessage } from "./errors-BKzCeTYb.mjs";
import { w as root } from "./fs-safe-BbWvmdVn.mjs";
import { c as extractArchive } from "./archive-xLn9WKtS.mjs";
import path from "node:path";
//#region src/skills/lifecycle/install-extract.ts
async function extractSkillDownloadArchive(e) {
const { archivePath: t, archiveType: n, targetDir: r, stripComponents: i, timeoutMs: a } = e;
const o = n === "zip" ? "zip" : n === "tar.gz" ? "tar" : n === "tar.bz2" ? "tar-bzip2" : void 0;
if (!o) return {
stdout: "",
stderr: `unsupported archive type: ${n}`,
code: null
};
try {
await extractArchive({
archivePath: t,
destDir: r,
timeoutMs: a,
kind: o,
stripComponents: typeof i === "number" && Number.isFinite(i) ? Math.max(0, Math.floor(i)) : 0,
tarGzip: o === "tar" ? true : void 0,
entryModes: o === "tar-bzip2" ? "preserve" : "clamp",
entryUmask: o === "tar-bzip2" ? process.geteuid?.() === 0 ? 0 : process.umask() : 0
});
if (o === "tar-bzip2") {
const e = await root(r);
const validateReadable = async (t) => {
for await (const n of e.entries(t ? `./${t}` : "", {
order: "filesystem",
symlinks: "reject"
})) {
const r = path.join(t, n.name);
if (n.isSymbolicLink || !n.isFile && !n.isDirectory) throw new Error(`archive staging contains a link or unsupported entry: ${n.name}`);
if (n.isDirectory) await validateReadable(r);
else {
const { handle: t } = await e.open(path.join(e.rootReal, r), {
symlinks: "reject",
hardlinks: "reject"
});
await t.close();
}
}
};
await validateReadable("");
}
return {
stdout: "",
stderr: "",
code: 0
};
} catch (e) {
return {
stdout: "",
stderr: formatErrorMessage(e),
code: 1
};
}
}
//#endregion
export { extractSkillDownloadArchive };