Skip to content

Commit

Permalink
Rollup merge of rust-lang#80424 - jyn514:bootstrap-cleanup, r=Mark-Si…
Browse files Browse the repository at this point in the history
…mulacrum

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 rust-lang#79540.
  • Loading branch information
Dylan-DPC authored Dec 30, 2020
2 parents 9b5cdd8 + 7ac02bd commit b432edb
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/bootstrap/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit b432edb

Please sign in to comment.