Skip to content

Commit

Permalink
Don't give an error when creating a file for the first time
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jyn514 committed Dec 28, 2020
1 parent dc6121c commit 7ac02bd
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 7ac02bd

Please sign in to comment.