Skip to content

Commit

Permalink
Auto merge of rust-lang#127152 - ChrisDenton:rename, r=<try>
Browse files Browse the repository at this point in the history
Bootstrap: Try renaming the file if removing fails

Second attempt at working around rust-lang#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
  • Loading branch information
bors committed Jun 30, 2024
2 parents 716752e + 17a169c commit 732189e
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/bootstrap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1676,7 +1677,14 @@ impl Build {
if src == dst {
return;
}
let _ = fs::remove_file(dst);
if fs::remove_file(dst).is_err() {
// workaround for https://github.com/rust-lang/rust/issues/127126
// if removing the file fails, attempt to rename it instead.
let now = SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
.expect("couldn't get system time");
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() {
Expand Down

0 comments on commit 732189e

Please sign in to comment.