fix(installer): uninstall now selects latest install record instead of latest pointer

This commit is contained in:
2026-02-26 06:04:17 +00:00
parent 8eade446b3
commit 1746fb33ad

View File

@@ -77,6 +77,25 @@ function readRecord(file) {
return JSON.parse(fs.readFileSync(file, "utf8"));
}
function findLatestInstallRecord() {
if (!fs.existsSync(STATE_DIR)) return "";
const files = fs
.readdirSync(STATE_DIR)
.filter((f) => /^whispergate-\d+\.json$/.test(f))
.sort()
.reverse();
for (const f of files) {
const p = path.join(STATE_DIR, f);
try {
const rec = readRecord(p);
if (rec?.mode === "install") return p;
} catch {
// ignore broken records
}
}
return "";
}
if (!fs.existsSync(OPENCLAW_CONFIG_PATH)) {
console.error(`[whispergate] config not found: ${OPENCLAW_CONFIG_PATH}`);
process.exit(1);
@@ -153,9 +172,9 @@ if (mode === "install") {
process.exit(1);
}
} else {
const recFile = env.RECORD_FILE || (fs.existsSync(LATEST_RECORD_LINK) ? LATEST_RECORD_LINK : "");
const recFile = env.RECORD_FILE || findLatestInstallRecord();
if (!recFile || !fs.existsSync(recFile)) {
console.error("[whispergate] no record found. set RECORD_FILE=<path> or install first.");
console.error("[whispergate] no install record found. set RECORD_FILE=<path> to an install record.");
process.exit(1);
}