From aa7bd8568762dcbfe911ac4e2dfaf6471477dc2a Mon Sep 17 00:00:00 2001 From: benya Date: Mon, 9 Feb 2026 01:41:11 +0300 Subject: [PATCH] Filter restic forget parsing to ignore summary rows --- handlers/backup.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/handlers/backup.py b/handlers/backup.py index ab6a365..1e9c869 100644 --- a/handlers/backup.py +++ b/handlers/backup.py @@ -80,6 +80,7 @@ def _beautify_restic_forget(raw: str) -> str | None: """ if "Reasons" not in raw or "Paths" not in raw: return None + import re lines = raw.splitlines() headers = [] @@ -89,6 +90,9 @@ def _beautify_restic_forget(raw: str) -> str | None: if not headers: return None + def _valid_id(val: str) -> bool: + return bool(re.fullmatch(r"[0-9a-f]{7,64}", val.strip())) + def parse_block(start_idx: int, end_idx: int) -> list[dict]: header = lines[start_idx] cols = ["ID", "Time", "Host", "Tags", "Reasons", "Paths", "Size"] @@ -109,7 +113,7 @@ def _beautify_restic_forget(raw: str) -> str | None: for i in range(len(cols)): segments.append(line[positions[i] : positions[i + 1]].strip()) row = dict(zip(cols, segments)) - if row["ID"]: + if row["ID"] and _valid_id(row["ID"]): current = { "id": row["ID"], "time": row["Time"], @@ -125,9 +129,9 @@ def _beautify_restic_forget(raw: str) -> str | None: current["paths"].append(row["Paths"]) entries.append(current) elif current: - if row["Reasons"]: + if row["Reasons"] and not row["Reasons"].startswith("-"): current["reasons"].append(row["Reasons"]) - if row["Paths"]: + if row["Paths"] and not row["Paths"].startswith("-"): current["paths"].append(row["Paths"]) return entries