Writes to a uniquely-named temporary file in the same directory first, then
renames it to the final path. The temp filename includes the PID and a random
UUID so that concurrent callers targeting the same destination never collide
on the intermediate file. If the rename fails the temp file is cleaned up in
a finally block. On platforms where renameSync does not overwrite an
existing destination (e.g. Windows), the error is caught and the target is
removed before retrying the rename.
Write content to a file atomically.
Writes to a uniquely-named temporary file in the same directory first, then renames it to the final path. The temp filename includes the PID and a random UUID so that concurrent callers targeting the same destination never collide on the intermediate file. If the rename fails the temp file is cleaned up in a
finallyblock. On platforms whererenameSyncdoes not overwrite an existing destination (e.g. Windows), the error is caught and the target is removed before retrying the rename.