InternalArray of remaining backup filenames (e.g., ["backup-123.json"]).
export function reconcileBackupHistory(backupFilenames: string[]): void {
try {
let history = getBackupHistory();
const originalCount = history.length;
// Filter history to only include backups that exist on disk
// Extract IDs from filenames: "backup-1234.json" -> "backup_1234"
const existingIds = new Set(
backupFilenames.map((filename) => {
const regex = /backup-(\d+)\.json/;
const match = regex.exec(filename);
return match ? `backup_${match[1]}` : null;
}),
);
history = history.filter((entry) => existingIds.has(entry.id));
if (history.length < originalCount) {
console.log(
`[Backup] Reconciled history: removed ${originalCount - history.length} entries for deleted backups`,
);
storage.setItem(STORAGE_KEYS.BACKUP_HISTORY, JSON.stringify(history));
}
} catch (error) {
console.error("[Backup] Failed to reconcile backup history:", error);
}
}
Reconciles backup history with actual files on disk. Removes history entries for backups that no longer exist on disk. Called after deleting backups during rotation.