Skip to content

Commit 1975142

Browse files
authored
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 #79540.
2 parents 3d7cdf6 + 7ac02bd commit 1975142

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/bootstrap/bootstrap.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -351,11 +351,13 @@ def output(filepath):
351351
with open(tmp, 'w') as f:
352352
yield f
353353
try:
354-
os.remove(filepath) # PermissionError/OSError on Win32 if in use
355-
os.rename(tmp, filepath)
354+
if os.path.exists(filepath):
355+
os.remove(filepath) # PermissionError/OSError on Win32 if in use
356356
except OSError:
357357
shutil.copy2(tmp, filepath)
358358
os.remove(tmp)
359+
return
360+
os.rename(tmp, filepath)
359361

360362

361363
class RustBuild(object):

0 commit comments

Comments
 (0)