From 97d0bc3f044a2f105ec760f78da800a1e44c8f05 Mon Sep 17 00:00:00 2001 From: "NODA, Kai" Date: Wed, 27 Jun 2018 03:23:14 +0800 Subject: [PATCH] bootstrap: our best to achieve atomic rename on Win32 This is a tricky operation to implement on Win32; see https://ci.appveyor.com/project/nodakai/python-win-behavior Signed-off-by: NODA, Kai --- src/bootstrap/bootstrap.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/bootstrap/bootstrap.py b/src/bootstrap/bootstrap.py index d1aa32236ae..71c1c61e3d9 100644 --- a/src/bootstrap/bootstrap.py +++ b/src/bootstrap/bootstrap.py @@ -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):