feat(compact): add --dry-run to check file readiness without modifying

- CLI: python main.py compact --dry-run [--db FILE]
- API: POST /api/compact {"dry_run": true}
- Checks .laccdb lock file + exclusive open to detect busy files
- Returns per-file [READY] / [BUSY] status with lock reason

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Misaka_Company
2026-08-06 11:30:00 +08:00
parent 42a2f99ed9
commit c70dac04e8
4 changed files with 108 additions and 19 deletions

24
main.py
View File

@@ -64,6 +64,8 @@ def _parse_args(argv):
pcp = sub.add_parser("compact", help="compact & repair Access databases")
pcp.add_argument("--db", help="limit to one Access file (by FileMapping.file)")
pcp.add_argument("--dry-run", action="store_true", dest="dry_run",
help="only check file accessibility and lock status, do not compact")
return p.parse_args(argv)
@@ -104,13 +106,21 @@ def main(argv=None) -> int:
return 0
if args.command == "compact":
summary = compact_files(cfg, db_filter=args.db)
for r in summary.results:
if r.ok:
print(f"[OK] {r.file} {_human(r.before_bytes)} -> {_human(r.after_bytes)} ({r.duration_s:.1f}s)")
else:
print(f"[FAIL] {r.file} {r.error}")
print(f"--- {summary.ok} OK, {summary.failed} FAIL, saved {_human(summary.saved_bytes)} ---")
summary = compact_files(cfg, db_filter=args.db, dry_run=args.dry_run)
if args.dry_run:
for r in summary.results:
if r.ok:
print(f"[READY] {r.file} {_human(r.before_bytes)}")
else:
print(f"[BUSY] {r.file} {_human(r.before_bytes)} ({r.error})")
print(f"--- {summary.ok} ready, {summary.failed} busy/missing ---")
else:
for r in summary.results:
if r.ok:
print(f"[OK] {r.file} {_human(r.before_bytes)} -> {_human(r.after_bytes)} ({r.duration_s:.1f}s)")
else:
print(f"[FAIL] {r.file} {r.error}")
print(f"--- {summary.ok} OK, {summary.failed} FAIL, saved {_human(summary.saved_bytes)} ---")
return 0 if summary.all_ok else 1
if args.command == "compare":