fix: /api/backups — fpath.st_size -> fpath.stat().st_size + try/except
CI / lint (push) Failing after 4s
CI / test (push) Has been skipped
CI / build (push) Has been skipped
CI / security (push) Successful in 8s

This commit is contained in:
2026-06-04 20:24:58 -04:00
parent 7720d9b96f
commit 7af347b6be
+11 -6
View File
@@ -3280,7 +3280,8 @@ async def api_backups_list(
):
"""List all backups across vaults, grouped by file."""
result = []
for vault_name in index.keys():
try:
for vault_name in index.keys():
if vault and vault_name != vault:
continue
if not check_vault_access(vault_name, current_user):
@@ -3298,7 +3299,8 @@ async def api_backups_list(
for fpath in vault_backup_dir.rglob("*.bak"):
if not fpath.is_file():
continue
stat = fpath.st_size
st = fpath.stat()
fsize = st.st_size
ts_part = fpath.name.rsplit(".", 2)
if len(ts_part) < 3 or not ts_part[-2].isdigit():
continue
@@ -3311,13 +3313,16 @@ async def api_backups_list(
"backup_file": fpath.name,
"timestamp": ts,
"datetime": datetime.fromtimestamp(ts, tz=timezone.utc).isoformat(),
"size": stat,
"size": fsize,
"full_path": str(fpath),
})
result.sort(key=lambda x: x["timestamp"], reverse=True)
total_size = sum(r["size"] for r in result)
return {"backups": result, "total": len(result), "total_size_bytes": total_size}
result.sort(key=lambda x: x["timestamp"], reverse=True)
total_size = sum(r["size"] for r in result)
return {"backups": result, "total": len(result), "total_size_bytes": total_size}
except Exception as e:
logger.error(f"Error listing backups: {type(e).__name__}: {e}", exc_info=True)
raise HTTPException(status_code=500, detail=f"Erreur listing backups: {str(e)}")
@app.post("/api/backups/delete")