Atomic transcript output file rewrites
Overview
@dolio recently had an "idemptotent" transcript file get wiped out because of a ctrl-c at a non-opportune moment. This makes output-writing atomic on unix systems, and it should be slightly less likely to cause trouble on windows as well.
Implementation notes
- Add helper to the prelude for atomically replacing a file, which writes to a temp file then does a rename over the destination
- Uses this new helper in the transcript output writer
Test coverage
Existing transcripts should serve as proof this is working.
I also tried making some transcript changes to ensure they took effect.
Ugh, yeah looks like Windows problems
What if instead of a temp file, you temporarily created the output.md, then renamed it over the original .md? Not as general purpose, but might work for this case.
What if instead of a temp file, you temporarily created the
output.md, then renamed it over the original.md? Not as general purpose, but might work for this case.
Yeah at least it should be on the same device, which seems to be what's causing the trouble in this case. move/rename from $TEMP could always cause this. a "copy from temp"+delete could also be the fix alternatively