unison icon indicating copy to clipboard operation
unison copied to clipboard

Atomic transcript output file rewrites

Open ChrisPenner opened this issue 1 month ago • 3 comments

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.

ChrisPenner avatar Nov 04 '25 23:11 ChrisPenner

Ugh, yeah looks like Windows problems

ChrisPenner avatar Nov 05 '25 22:11 ChrisPenner

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.

dolio avatar Nov 06 '25 19:11 dolio

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

aryairani avatar Nov 14 '25 23:11 aryairani