fix: /api/backups — fpath.st_size -> fpath.stat().st_size + try/except
This commit is contained in:
+11
-6
@@ -3280,7 +3280,8 @@ async def api_backups_list(
|
|||||||
):
|
):
|
||||||
"""List all backups across vaults, grouped by file."""
|
"""List all backups across vaults, grouped by file."""
|
||||||
result = []
|
result = []
|
||||||
for vault_name in index.keys():
|
try:
|
||||||
|
for vault_name in index.keys():
|
||||||
if vault and vault_name != vault:
|
if vault and vault_name != vault:
|
||||||
continue
|
continue
|
||||||
if not check_vault_access(vault_name, current_user):
|
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"):
|
for fpath in vault_backup_dir.rglob("*.bak"):
|
||||||
if not fpath.is_file():
|
if not fpath.is_file():
|
||||||
continue
|
continue
|
||||||
stat = fpath.st_size
|
st = fpath.stat()
|
||||||
|
fsize = st.st_size
|
||||||
ts_part = fpath.name.rsplit(".", 2)
|
ts_part = fpath.name.rsplit(".", 2)
|
||||||
if len(ts_part) < 3 or not ts_part[-2].isdigit():
|
if len(ts_part) < 3 or not ts_part[-2].isdigit():
|
||||||
continue
|
continue
|
||||||
@@ -3311,13 +3313,16 @@ async def api_backups_list(
|
|||||||
"backup_file": fpath.name,
|
"backup_file": fpath.name,
|
||||||
"timestamp": ts,
|
"timestamp": ts,
|
||||||
"datetime": datetime.fromtimestamp(ts, tz=timezone.utc).isoformat(),
|
"datetime": datetime.fromtimestamp(ts, tz=timezone.utc).isoformat(),
|
||||||
"size": stat,
|
"size": fsize,
|
||||||
"full_path": str(fpath),
|
"full_path": str(fpath),
|
||||||
})
|
})
|
||||||
|
|
||||||
result.sort(key=lambda x: x["timestamp"], reverse=True)
|
result.sort(key=lambda x: x["timestamp"], reverse=True)
|
||||||
total_size = sum(r["size"] for r in result)
|
total_size = sum(r["size"] for r in result)
|
||||||
return {"backups": result, "total": len(result), "total_size_bytes": total_size}
|
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")
|
@app.post("/api/backups/delete")
|
||||||
|
|||||||
Reference in New Issue
Block a user