about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJoshua Nelson <jyn514@gmail.com>2020-12-26 23:07:11 -0500
committerJoshua Nelson <jyn514@gmail.com>2020-12-27 19:55:02 -0500
commit7ac02bddc7349fb2268c88e0adc4a0f1854fb531 (patch)
treec1a947d046ff4ab81400291f825860e5030521d7
parentdc6121ca681e3aef09b93afb13637632dcdc0e9a (diff)
downloadrust-7ac02bddc7349fb2268c88e0adc4a0f1854fb531.tar.gz
rust-7ac02bddc7349fb2268c88e0adc4a0f1854fb531.zip
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.
-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):