Write text to location so that the file is always either its old or its new content, never half of one: the
text goes to a temporary file next to it, which then replaces it (a rename is atomic within one folder). That holds
when the process stops part way (a crash, a kill); there's no fsync, so after a power cut the file system may still
lose a recent write. When the write or rename fails, the temporary file is removed and the original error thrown.
Write
texttolocationso that the file is always either its old or its new content, never half of one: the text goes to a temporary file next to it, which then replaces it (a rename is atomic within one folder). That holds when the process stops part way (a crash, a kill); there's no fsync, so after a power cut the file system may still lose a recent write. When the write or rename fails, the temporary file is removed and the original error thrown.