writeTextAtomic function
Writes text to file so that it is never seen half-written: into a
temporary .saving file beside it — named for this write alone, so two
writers never share one — then renamed over it. The temporary file is
removed when anything fails.
A file that is a symbolic link is written through: its target gets
the new text, and the link stays a link — wherever it leads, outside a
project too: this writes the file it is given. A ProjectTransaction's
writes follow a link only while it stays inside the project. On macOS
and Linux the file keeps its permissions (an executable script stays
executable).
Implementation
void writeTextAtomic(File file, String text) =>
writeBytesAtomic(file, utf8.encode(text));