1
Fork 0

Don't give an error when creating a file for the first time

Previously, `os.remove` would always give a FileNotFound error the first
time you called it, causing bootstrap to make unnecessary copies. This
now only calls `remove()` if the file exists, avoiding the unnecessary
error.
This commit is contained in:
Joshua Nelson 2020-12-26 23:07:11 -05:00
parent dc6121ca68
commit 7ac02bddc7

View file

@ -351,11 +351,13 @@ def output(filepath):
with open(tmp, 'w') as f:
yield f
try:
if os.path.exists(filepath):
os.remove(filepath) # PermissionError/OSError on Win32 if in use
os.rename(tmp, filepath)
except OSError:
shutil.copy2(tmp, filepath)
os.remove(tmp)
return
os.rename(tmp, filepath)
class RustBuild(object):