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
+34
View File
@@ -573,6 +573,40 @@ def test_retention_delete_also_removes_local_copy(
assert final["local_path"] is None
def test_get_and_list_backups_clear_stale_local_path_for_missing_file(isolated_db, no_notifications, tmp_path):
from app import backup_service
missing_local = tmp_path / "gone.tar.zst"
with db() as conn:
conn.execute(
"""
INSERT INTO backups(
id, guest_vmid, guest_name, guest_type, node, state,
local_path, remote_path, started_at, completed_at, updated_at
)
VALUES ('stale-local', 110, 'test-guest', 'vm', 'pve', 'completed',
?, 'onedrive:pve-cloud-backup/stale-local/archive.tar.zst', ?, ?, ?)
""",
(str(missing_local), utc_now(), utc_now(), utc_now()),
)
fetched = backup_service.get_backup("stale-local")
assert fetched["local_path"] is None
with db() as conn:
row = conn.execute("SELECT local_path FROM backups WHERE id = 'stale-local'").fetchone()
assert row["local_path"] is None
with db() as conn:
conn.execute(
"UPDATE backups SET local_path = ? WHERE id = 'stale-local'",
(str(missing_local),),
)
listed = backup_service.list_backups()
assert listed[0]["local_path"] is None
def test_recover_unfinished_resumes_local_downloading(isolated_db, no_notifications, monkeypatch):
from app import backup_service