openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
53 lines (52 loc) • 2.31 kB
JavaScript
import { l as isRecord } from "./record-coerce-CVPuDqcc.mjs";
import { n as assertUpdateCandidatePluginCodeLink } from "./update-candidate-plugin-code-links-CB6ganwk.mjs";
import { lstatSync } from "node:fs";
import path from "node:path";
import { isDeepStrictEqual } from "node:util";
//#region src/commands/doctor-update-rehearsal-paths.ts
function refuseRehearsal(e) {
throw new Error(`Legacy update rehearsal was refused: ${e}. Run npx openclaw@latest update from a terminal for a protected update.`);
}
function isWithinRehearsal(e, t) {
const n = path.relative(e, t);
return n === "" || !path.isAbsolute(n) && n !== ".." && !n.startsWith(`..${path.sep}`);
}
/** Strict data inspection; only the terminal entry in a code walk may be an owned link. */
function createRehearsalPathInspector(e, t) {
const n = /* @__PURE__ */ new Map();
for (const e of t) {
const t = n.get(e.path);
if (t && !isDeepStrictEqual(t, e)) refuseRehearsal(`conflicting plugin code link identities: ${e.path}`);
n.set(e.path, e);
}
const r = process.getuid?.();
const i = /* @__PURE__ */ new Map();
function inspectPath(t, a = false, o = false) {
if (path.normalize(t) !== t) refuseRehearsal(`migration data path is not fully resolved: ${t}`);
if (!path.isAbsolute(t) || !isWithinRehearsal(e, t)) refuseRehearsal(`migration data escapes the copied state: ${t}`);
let s = e;
let c;
for (const l of ["", ...path.relative(e, t).split(path.sep).filter(Boolean)]) {
s = path.join(s, l);
try {
c = lstatSync(s);
} catch (e) {
if (isRecord(e) && e.code === "ENOENT") return;
throw e;
}
const u = o && s === t ? n.get(s) : void 0;
if (u) assertUpdateCandidatePluginCodeLink(u);
if (c.isSymbolicLink() && !u || !c.isDirectory() && !c.isFile() && !u || c.isFile() && c.nlink !== 1 || r !== void 0 && c.uid !== r || process.platform !== "win32" && (s === e || a && s === t) && (c.mode & 63) !== 0) refuseRehearsal(`copied data has unsafe ownership or links: ${s}`);
const d = i.get(s);
if (d && (d.dev !== c.dev || d.ino !== c.ino)) refuseRehearsal(`copied data identity changed: ${s}`);
i.set(s, c);
}
return c;
}
return {
identities: i,
inspectPath
};
}
//#endregion
export { isWithinRehearsal as n, refuseRehearsal as r, createRehearsalPathInspector as t };