Prune card exports whose PNG is gone
Deleting a character in the UI left _text/cards/<Name>.json behind, describing a card that no longer exists. A stale derived file is worse than a missing one because it reads as current -- which is the exact reason the pre-commit hook regenerates _text/ at all, so the script was failing its own premise. Found by testing a deletion rather than reading the code. The write path was obviously correct; the delete path had simply never been written.
This commit is contained in:
@@ -92,6 +92,18 @@ def export_cards() -> int:
|
||||
json.dump(card, fh, indent=2, ensure_ascii=False, sort_keys=True)
|
||||
fh.write("\n")
|
||||
n += 1
|
||||
|
||||
# ⚠ PRUNE EXPORTS WHOSE SOURCE IS GONE. Without this, deleting a character in
|
||||
# the UI left `_text/cards/<Name>.json` behind describing a card that no
|
||||
# longer exists — and it reads as current, which is worse than absent. Found
|
||||
# by testing a deletion rather than by reading the code: the write path was
|
||||
# obviously correct and the delete path was simply never written.
|
||||
live = {f[:-4] + ".json" for f in os.listdir(src)
|
||||
if f.lower().endswith(".png") and not f.startswith("default_")} if os.path.isdir(src) else set()
|
||||
for stale in sorted(set(os.listdir(dst)) - live):
|
||||
if stale.endswith(".json"):
|
||||
os.remove(os.path.join(dst, stale))
|
||||
print(f" pruned _text/cards/{stale} — its PNG is gone")
|
||||
return n
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user