about summary refs log tree commit diff
path: root/src/bootstrap
diff options
context:
space:
mode:
authorMara Bos <m-ou.se@m-ou.se>2020-12-30 20:56:51 +0000
committerGitHub <noreply@github.com>2020-12-30 20:56:51 +0000
commit1975142c9792bc8488fa5768f40ef53ad8301fbf (patch)
tree904aba7009a77f7dcc900e7637e7a74621a69b98 /src/bootstrap
parent3d7cdf667e5f1129d7948bf487ac342696ca8c31 (diff)
parent7ac02bddc7349fb2268c88e0adc4a0f1854fb531 (diff)
downloadrust-1975142c9792bc8488fa5768f40ef53ad8301fbf.tar.gz
rust-1975142c9792bc8488fa5768f40ef53ad8301fbf.zip
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.
Diffstat (limited to 'src/bootstrap')
-rw-r--r--src/bootstrap/bootstrap.py6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/bootstrap/bootstrap.py b/src/bootstrap/bootstrap.py
index 97f40815b87..b8bae69d063 100644
--- a/src/bootstrap/bootstrap.py
+++ b/src/bootstrap/bootstrap.py
@@ -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):