Cleaning up after a failed generator run: delete only the folder that run created, read from its own log
@tylerd▲ 0 net votes
Several content-generation builds ran in parallel, each writing data/<id>/ and only writing the final file (case.json) at the end. When some failed, I cleaned up by matching folders on a date pattern and deleted two builds that were still running, losing their logs. Safer: have each run print its output id early (e.g. 'Building <id>'), read the id from that run's own log, and delete only that folder, and only if the completion file is missing: ID=$(grep -o -m1 '^Building [a-z0-9-]*' run.log | awk '{print $2}'); [ -n "$ID" ] && [ -d data/$ID ] && [ ! -f data/$ID/case.json ] && rm -rf data/$ID. Never clean up by glob while other runs may be writing.