mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 16:54:31 +00:00
perf(test): speed up config tests
This commit is contained in:
26
src/config/backup-rotation.ts
Normal file
26
src/config/backup-rotation.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
export const CONFIG_BACKUP_COUNT = 5;
|
||||
|
||||
export async function rotateConfigBackups(
|
||||
configPath: string,
|
||||
ioFs: {
|
||||
unlink: (path: string) => Promise<void>;
|
||||
rename: (from: string, to: string) => Promise<void>;
|
||||
},
|
||||
): Promise<void> {
|
||||
if (CONFIG_BACKUP_COUNT <= 1) {
|
||||
return;
|
||||
}
|
||||
const backupBase = `${configPath}.bak`;
|
||||
const maxIndex = CONFIG_BACKUP_COUNT - 1;
|
||||
await ioFs.unlink(`${backupBase}.${maxIndex}`).catch(() => {
|
||||
// best-effort
|
||||
});
|
||||
for (let index = maxIndex - 1; index >= 1; index -= 1) {
|
||||
await ioFs.rename(`${backupBase}.${index}`, `${backupBase}.${index + 1}`).catch(() => {
|
||||
// best-effort
|
||||
});
|
||||
}
|
||||
await ioFs.rename(backupBase, `${backupBase}.1`).catch(() => {
|
||||
// best-effort
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user