For the purpose of safely updating a file, I am writing an updated version to a temporary file and then try to overwrite the original file with it. In a shell unix script I would use mv FROM TO
for this.
With python on Linux, the functions os.rename and shutil.move perform an atomic replace operation when the target filename exists. On Windows, they fail.
The behavior can be approximated by a sequence of copy, rename and remove operations, but it cannot be guaranteed, that such a self-written replace operation is performed either finished or completely reverted.
Is it possible to get a reliable “rename and overwrite” operation on Windows?