/** *Removeorphan.bakfilesthatfalloutsidethemanagedrotationring. *Thesecanaccumulatefrominterruptedwrites,manualcopies,orPID-stamped *backups(e.g.openclaw.json.bak.1772352289,openclaw.json.bak.before-marketing). * *Onlyfilesmatching`<configBasename>.bak.*`areconsidered;theprimary *`.bak`andnumbered`.bak.1`through`.bak.{N-1}`arepreserved.
*/
export async function cleanOrphanBackups(
configPath: string,
ioFs: BackupRotationFs,
): Promise<void> { if (!ioFs.readdir) { return;
} const dir = path.dirname(configPath); const base = path.basename(configPath); const bakPrefix = `${base}.bak.`;
// Build the set of valid numbered suffixes: "1", "2", ..., "{N-1}" const validSuffixes = new Set<string>(); for (let i = 1; i < CONFIG_BACKUP_COUNT; i++) {
validSuffixes.add(String(i));
}
for (const entry of entries) { if (!entry.startsWith(bakPrefix)) { continue;
} const suffix = entry.slice(bakPrefix.length); if (validSuffixes.has(suffix)) { continue;
} // This is an orphan — remove it
await ioFs.unlink(path.join(dir, entry)).catch(() => { // best-effort
});
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.