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

View File

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