"""Periodic cleanup of expired files.""" import time from pathlib import Path from config import CLEANUP_INTERVAL def cleanup_loop(upload_dir: Path, max_age: int): if max_age <= 0: return while True: time.sleep(CLEANUP_INTERVAL) now = time.time() try: entries = list(upload_dir.iterdir()) except OSError as e: print(f" cleanup error: {e}") continue for f in entries: try: if f.is_file() and now - f.stat().st_mtime > max_age: f.unlink() print(f" - expired: {f.name}") except OSError: pass