Rollup merge of #80424 - jyn514:bootstrap-cleanup, r=Mark-Simulacrum

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 is a pretty small cleanup but I think it's useful. Taken from https://github.com/rust-lang/rust/pull/79540.
This commit is contained in:
Mara Bos 2020-12-30 20:56:51 +00:00 committed by GitHub
commit 1975142c97
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

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