]> git.lizzy.rs Git - rust.git/commitdiff
bootstrap: our best to achieve atomic rename on Win32
authorNODA, Kai <nodakai@gmail.com>
Tue, 26 Jun 2018 19:23:14 +0000 (03:23 +0800)
committerNODA, Kai <nodakai@gmail.com>
Tue, 10 Jul 2018 14:50:20 +0000 (22:50 +0800)
This is a tricky operation to implement on Win32; see
https://ci.appveyor.com/project/nodakai/python-win-behavior

Signed-off-by: NODA, Kai <nodakai@gmail.com>
src/bootstrap/bootstrap.py

index d1aa32236aeeebde54e81b5a03d4ec40b3d917a3..71c1c61e3d97ebd51e9bd8cf5b9946cbcbe5ca5c 100644 (file)
@@ -308,7 +308,12 @@ def output(filepath):
     tmp = filepath + '.tmp'
     with open(tmp, 'w') as f:
         yield f
-    os.rename(tmp, filepath)
+    try:
+        os.remove(filepath)  # PermissionError/OSError on Win32 if in use
+        os.rename(tmp, filepath)
+    except OSError:
+        shutil.copy2(tmp, filepath)
+        os.remove(tmp)
 
 
 class RustBuild(object):