Self-heal stale local_path pointers on read
CI / Frontend build (push) Successful in 11s
CI / Backend tests (push) Successful in 16s
CI / Script syntax (push) Successful in 3s

Backups completed before the keep-local-backups feature never had
local_path nulled out after the local archive was deleted, so the new
"Local copy: Kept" indicator was trusting a stale DB column instead of
reality. GET /api/backups and GET /api/backups/{id} now verify the
file still exists and clear local_path if it doesn't, which also
covers any future case of a local file disappearing outside the app.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Codex
2026-07-15 13:06:53 +02:00
parent b3ad062941
commit 7960809b30
3 changed files with 46 additions and 2 deletions
+11 -2
View File
@@ -130,11 +130,20 @@ def list_backups(guest_vmid: int | None = None, state: str | None = None) -> lis
query += " WHERE " + " AND ".join(where)
query += " ORDER BY started_at DESC LIMIT 500"
with db() as conn:
return [dict(row) for row in conn.execute(query, args).fetchall()]
rows = [dict(row) for row in conn.execute(query, args).fetchall()]
return [_reconcile_local_path(row) for row in rows]
def _reconcile_local_path(backup: dict) -> dict:
"""Self-heal a stale local_path left over from a file that no longer exists."""
local_path = backup.get("local_path")
if local_path and not Path(local_path).exists():
return update_backup(backup["id"], local_path=None)
return backup
def get_backup(backup_id: str) -> dict:
return _backup_row(backup_id)
return _reconcile_local_path(_backup_row(backup_id))
def purge_deleted_backup(backup_id: str) -> dict: