UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

46 lines (45 loc) • 1.34 kB
import { t as formatErrorMessage } from "./errors-BKzCeTYb.mjs"; import { d as pathExists } from "./fs-safe-BbWvmdVn.mjs"; import { n as assertCanonicalPathWithinBase, o as resolveSafeInstallDir } from "./install-safe-path-DIFL0qYY.mjs"; import fs from "node:fs/promises"; //#region src/infra/install-target.ts /** Resolves and verifies an install target directory under a canonical base directory. */ async function resolveCanonicalInstallTarget(e) { await fs.mkdir(e.baseDir, { recursive: true }); const t = resolveSafeInstallDir({ baseDir: e.baseDir, id: e.id, invalidNameMessage: e.invalidNameMessage, nameEncoder: e.nameEncoder }); if (!t.ok) return { ok: false, error: t.error }; try { await assertCanonicalPathWithinBase({ baseDir: e.baseDir, candidatePath: t.path, boundaryLabel: e.boundaryLabel }); } catch (e) { return { ok: false, error: formatErrorMessage(e) }; } return { ok: true, targetDir: t.path }; } /** Ensures install mode does not overwrite an existing target; update mode may reuse it. */ async function ensureInstallTargetAvailable(e) { if (e.mode === "install" && await pathExists(e.targetDir)) return { ok: false, error: e.alreadyExistsError }; return { ok: true }; } //#endregion export { resolveCanonicalInstallTarget as n, ensureInstallTargetAvailable as t };