config.py — share.config loading, constants, load_config(), client_cfg() cert.py — get_local_ip(), ensure_cert() cleanup.py — cleanup_loop() server.py — ShareServer, Handler, file_type() share.py — main() entry point only Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
27 lines
683 B
Python
27 lines
683 B
Python
"""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
|