about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2024-07-02 17:47:47 +0200
committerGitHub <noreply@github.com>2024-07-02 17:47:47 +0200
commit836ce13ca9deae0d584aa42f5036ea6a07eb911f (patch)
treea92eb733f1a45a2b62060437308bb6da0bb58b0d
parent36da46ab985e73e9ae2b7719afae7a2784728f80 (diff)
parentb998cff5582b819910cc8e0f092c15151b930d02 (diff)
downloadrust-836ce13ca9deae0d584aa42f5036ea6a07eb911f.tar.gz
rust-836ce13ca9deae0d584aa42f5036ea6a07eb911f.zip
Rollup merge of #127152 - ChrisDenton:rename, r=onur-ozkan
Bootstrap: Try renaming the file if removing fails

Second attempt at working around https://github.com/rust-lang/rust/issues/127126

If we can't remove the file, then try renaming it. This will leave the destination path free to use.

try-job: x86_64-msvc-ext
-rw-r--r--src/bootstrap/src/lib.rs10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/bootstrap/src/lib.rs b/src/bootstrap/src/lib.rs
index 8d7e43a1bf1..c12449fdc4a 100644
--- a/src/bootstrap/src/lib.rs
+++ b/src/bootstrap/src/lib.rs
@@ -26,6 +26,7 @@ use std::path::{Path, PathBuf};
 use std::process::{Command, Stdio};
 use std::str;
 use std::sync::OnceLock;
+use std::time::SystemTime;
 
 use build_helper::ci::{gha, CiEnv};
 use build_helper::exit;
@@ -1647,7 +1648,14 @@ impl Build {
         if src == dst {
             return;
         }
-        let _ = fs::remove_file(dst);
+        if let Err(e) = fs::remove_file(dst) {
+            if cfg!(windows) && e.kind() != io::ErrorKind::NotFound {
+                // workaround for https://github.com/rust-lang/rust/issues/127126
+                // if removing the file fails, attempt to rename it instead.
+                let now = t!(SystemTime::now().duration_since(SystemTime::UNIX_EPOCH));
+                let _ = fs::rename(dst, format!("{}-{}", dst.display(), now.as_nanos()));
+            }
+        }
         let metadata = t!(src.symlink_metadata(), format!("src = {}", src.display()));
         let mut src = src.to_path_buf();
         if metadata.file_type().is_symlink() {