openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
93 lines (92 loc) • 3.59 kB
JavaScript
import { r as resolvePathViaExistingAncestorSync } from "./boundary-path-C2gXEiXe.mjs";
import { a as getOpenClawDatabaseMaintenanceScope } from "./openclaw-state-maintenance-context-D6i7Zdhn.mjs";
import { s as resolveOpenClawStateSqlitePath } from "./openclaw-state-db.paths-R3ArRCcz.mjs";
import "./openclaw-state-db-async-lifecycle-CH8q4Sdl.mjs";
import { a as resolveSqliteDatabaseFilePaths } from "./sqlite-files-rWisKj_V.mjs";
import { a as resolveUpdateRehearsalRoot } from "./update-rehearsal-paths-Dr1MbUA_.mjs";
import { t as createRehearsalPathInspector } from "./doctor-update-rehearsal-paths-D02-iFrJ.mjs";
import { lstatSync, realpathSync } from "node:fs";
import path from "node:path";
//#region src/commands/doctor-rehearsal-databases.ts
/** Only core images in Doctor's currently owned disposable namespace need no second backup. */
function createDoctorRehearsalDatabaseCoverage(e) {
const t = resolveUpdateRehearsalRoot(e);
const n = getOpenClawDatabaseMaintenanceScope();
if (!t || !n?.ownsSchemaMaintenance) return;
n.assertAdmission();
n.assertDatabaseAccess(resolveOpenClawStateSqlitePath(e));
const inspect = (e) => {
const n = createRehearsalPathInspector(t, []);
const r = n.inspectPath(e);
const i = /* @__PURE__ */ new Map();
for (const e of n.identities.keys()) {
const t = lstatSync(e, { bigint: true });
if (t.dev === 0n || t.ino === 0n) throw new Error(`Disposable database identity is unavailable: ${e}`);
i.set(e, t);
}
if (!r) i.set(e, void 0);
return {
stat: r,
identities: i
};
};
let r;
try {
if (path.resolve(t) !== t || realpathSync(t) !== t || !inspect(t).stat?.isDirectory()) return;
r = lstatSync(t, { bigint: true });
} catch {
return;
}
const i = /* @__PURE__ */ new Map([[t, r]]);
const a = /* @__PURE__ */ new Set();
const o = /* @__PURE__ */ new Set();
const s = /* @__PURE__ */ new Map();
const assertCurrent = () => {
n.assertAdmission();
n.assertDatabaseAccess(resolveOpenClawStateSqlitePath(e));
if (resolveUpdateRehearsalRoot(e) !== t || realpathSync(t) !== t) throw new Error("Disposable Doctor database namespace changed");
for (const [e, t] of i) {
const { identities: n } = inspect(e);
const r = n.get(e);
if (t ? !r || r.dev !== t.dev || r.ino !== t.ino : r !== void 0) throw new Error(`Disposable Doctor database identity changed: ${e}`);
}
for (const [e, t] of s) if (resolvePathViaExistingAncestorSync(e) !== t) throw new Error(`Disposable Doctor database alias changed: ${e}`);
};
return {
assertCurrent,
/** Call with the complete core discovery, never arbitrary plugin declarations. */
admit(e) {
assertCurrent();
for (const t of e) {
if (a.has(t)) continue;
const e = /* @__PURE__ */ new Map();
try {
if (!inspect(t).stat?.isFile() || realpathSync(t) !== t) continue;
for (const n of resolveSqliteDatabaseFilePaths(t)) {
const t = inspect(n);
if (t.stat && !t.stat.isFile()) throw new Error(`Disposable database companion is not a regular file: ${n}`);
for (const [n, r] of t.identities) e.set(n, r);
}
} catch {
continue;
}
for (const [t, n] of e) i.set(t, n);
a.add(t);
for (const e of resolveSqliteDatabaseFilePaths(t)) o.add(e);
}
assertCurrent();
return [...a];
},
excludes(e) {
const t = resolvePathViaExistingAncestorSync(e);
if (!o.has(t)) return false;
if (t !== e && !s.has(e)) s.set(e, t);
return true;
},
get paths() {
return [...o].toSorted();
}
};
}
//#endregion
export { createDoctorRehearsalDatabaseCoverage as t };