Log matched media cleanup files

This commit is contained in:
Abel Luck 2026-06-01 08:45:42 +02:00
parent 87288561b9
commit 89e6a4d78c
4 changed files with 31 additions and 3 deletions

View file

@ -84,8 +84,8 @@ uv run repub cleanup-media --feeds-dir out/feeds --days 25 --dry-run
```
- Remove `--dry-run` to delete matching files. The command protects media
referenced by the latest published feed and uses a lock to avoid racing with
active crawls.
referenced by the latest published feed, lists each matched file before the
aggregate summary, and uses a lock to avoid racing with active crawls.
- For config-driven deployments, pass the runtime config so cleanup uses the
configured `out_dir` and media directory names:

View file

@ -42,7 +42,8 @@ uv run repub cleanup-media --config demo/repub.toml --dry-run
With `--config`, cleanup scans `demo/out/feeds/` and honors any
`REPUBLISHER_*_DIR` media directory overrides in the config. Remove `--dry-run`
to delete old unreferenced media. The default retention window is 25 days; use
`--days N` to override it.
`--days N` to override it. Cleanup prints each matched path before the aggregate
summary.
## Local File Feed

View file

@ -160,6 +160,10 @@ def cleanup_media(
if path.resolve() in protected:
continue
result.matched_files += 1
print(
f"media cleanup: matched path={path.resolve()} bytes={stat.st_size}",
file=output,
)
if dry_run:
continue
try:

View file

@ -102,6 +102,29 @@ def test_cleanup_media_dry_run_reports_matches_without_deleting(tmp_path: Path)
assert result.failures == 0
def test_cleanup_media_lists_matched_files_before_summary(tmp_path: Path) -> None:
feeds_dir = tmp_path / "feeds"
old_file = feeds_dir / "demo" / "audio" / "old.mp3"
write_media(old_file, b"audio", age_days=40)
output = io.StringIO()
result = cleanup_media(
feeds_dir=feeds_dir,
retention_days=25,
now=NOW,
dry_run=True,
output=output,
)
assert old_file.exists()
assert result.matched_files == 1
output_lines = output.getvalue().splitlines()
assert (
output_lines[0] == f"media cleanup: matched path={old_file.resolve()} bytes=5"
)
assert "matched_files=1" in output_lines[-1]
def test_cleanup_media_uses_configured_media_dirs(tmp_path: Path) -> None:
feeds_dir = tmp_path / "feeds"
demo_dir = feeds_dir / "demo"