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 <nodakai@gmail.com>
This commit is contained in:
NODA, Kai 2018-06-27 03:23:14 +08:00
parent bcb8a06ef7
commit 97d0bc3f04
No known key found for this signature in database
GPG Key ID: 44244F38D93C6B7E
1 changed files with 6 additions and 1 deletions

View 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):