import fs from "node:fs"; import path from "node:path"; import { parseByteSize } from "../../cli/parse-bytes.js"; import { parseDurationMs } from "../../cli/parse-duration.js"; import { createSubsystemLogger } from "../../logging/subsystem.js"; import { normalizeStringifiedOptionalString } from "../../shared/string-coerce.js"; import type { SessionMaintenanceConfig, SessionMaintenanceMode } from "../types.base.js"; import type { SessionEntry } from "./types.js";
// Sort by updatedAt descending; entries without updatedAt go to the end (removed first). const sorted = keys.toSorted((a, b) => { const aTime = getEntryUpdatedAt(store[a]); const bTime = getEntryUpdatedAt(store[b]); return bTime - aTime;
});
// Check current file size (file may not exist yet). const fileSize = await getSessionFileSize(storePath); if (fileSize == null) { returnfalse;
}
if (fileSize <= maxBytes) { returnfalse;
}
// Keep the live store authoritative until the caller's later atomic write succeeds. // A rename would remove sessions.json and create a crash window where startup sees // an empty store; a copy gives us a backup without changing the live file. const backupPath = `${storePath}.bak.${Date.now()}`; try {
await fs.promises.copyFile(storePath, backupPath);
log.info("backed up session store file before rotation", {
backupPath: path.basename(backupPath),
sizeBytes: fileSize,
});
} catch (err) { // If backup creation fails (e.g. file disappeared), skip rotation backup only.
log.warn("session store rotation backup failed", { err }); returnfalse;
}
// Clean up old backups — keep only the 3 most recent .bak.* files. try { const dir = path.dirname(storePath); const baseName = path.basename(storePath); const files = await fs.promises.readdir(dir); const backups = files
.filter((f) => f.startsWith(`${baseName}.bak.`))
.toSorted()
.toReversed();
const maxBackups = 3; if (backups.length > maxBackups) { const toDelete = backups.slice(maxBackups); for (const old of toDelete) {
await fs.promises.unlink(path.join(dir, old)).catch(() => undefined);
}
log.info("cleaned up old session store backups", { deleted: toDelete.length });
}
} catch { // Best-effort cleanup; don't fail the write.
}
returntrue;
}
Messung V0.5 in Prozent
¤ 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.0.13Bemerkung:
(vorverarbeitet am 2026-06-10)
¤
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.