Skip to content

Commit 97d0bc3

Browse files
committed
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 <[email protected]>
1 parent bcb8a06 commit 97d0bc3

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/bootstrap/bootstrap.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,12 @@ def output(filepath):
308308
tmp = filepath + '.tmp'
309309
with open(tmp, 'w') as f:
310310
yield f
311-
os.rename(tmp, filepath)
311+
try:
312+
os.remove(filepath) # PermissionError/OSError on Win32 if in use
313+
os.rename(tmp, filepath)
314+
except OSError:
315+
shutil.copy2(tmp, filepath)
316+
os.remove(tmp)
312317

313318

314319
class RustBuild(object):

0 commit comments

Comments
 (0)