Peach: Local-first video metadata scraper and media manager.
fix(ledger): 清退报告的字节数在删除前量好
longmeidaod412ae465fe5
diff --git a/src/peach/ledger_backups.py b/src/peach/ledger_backups.pyindex 21a0ab1e1..6db993ad8 100644--- a/src/peach/ledger_backups.py+++ b/src/peach/ledger_backups.py@@ -28,17 +28,17 @@ class BackupPlan:keep: tuple[Path, ...]remove: tuple[Path, ...]refused: str | None = None # 不为 None 时一份都不删,这里写原因+ removable_bytes: int = 0 # 算计划时量好,删完文件就量不到了- @property- def removable_bytes(self) -> int:- total = 0- for path in self.remove:- for candidate in (path, *(path.with_name(path.name + s) for s in SIDECAR_SUFFIXES)):- try:- total += candidate.stat().st_size- except OSError:- continue- return total++def _size_with_sidecars(path: Path) -> int:+ total = 0+ for candidate in (path, *(path.with_name(path.name + s) for s in SIDECAR_SUFFIXES)):+ try:+ total += candidate.stat().st_size+ except OSError:+ continue+ return totaldef list_backups(live: Path) -> list[Path]:@@ -101,7 +101,8 @@ def plan(keep.append(backup)else:remove.append(backup)- return BackupPlan(tuple(keep), tuple(remove))+ return BackupPlan(tuple(keep), tuple(remove),+ removable_bytes=sum(_size_with_sidecars(path) for path in remove))def prune(diff --git a/tests/test_ledger_backups.py b/tests/test_ledger_backups.pyindex b0df4d83a..acce33e2e 100644--- a/tests/test_ledger_backups.py+++ b/tests/test_ledger_backups.py@@ -80,6 +80,8 @@ class LedgerBackupRetentionTests(unittest.TestCase):applied = ledger_backups.prune(live, apply=True, keep_recent=5, now=NOW)self.assertEqual(set(applied.remove), set(old))+ self.assertEqual(applied.removable_bytes, 4 * len(b"backup"),+ "字节数在删除前量好,报告里才不会写成 0")for path in old:self.assertFalse(path.exists())self.assertFalse((root / "ledger.pre-old-0.db-wal").exists(), "副文件一起删")@@ -141,6 +143,7 @@ class LedgerBackupRetentionTests(unittest.TestCase):report = json.loads(buffer.getvalue())self.assertFalse(report["applied"])self.assertEqual(report["remove"], ["ledger.pre-old.db"])+ self.assertEqual(report["removable_bytes"], len(b"backup"))self.assertTrue(old.exists(), "缺省是 dry-run")buffer = io.StringIO()