Skip to content

Commit 732189e

Browse files
committed
Auto merge of #127152 - ChrisDenton:rename, r=<try>
Bootstrap: Try renaming the file if removing fails Second attempt at working around #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
2 parents 716752e + 17a169c commit 732189e

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/bootstrap/src/lib.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use std::path::{Path, PathBuf};
2626
use std::process::{Command, Stdio};
2727
use std::str;
2828
use std::sync::OnceLock;
29+
use std::time::SystemTime;
2930

3031
use build_helper::ci::{gha, CiEnv};
3132
use build_helper::exit;
@@ -1676,7 +1677,14 @@ impl Build {
16761677
if src == dst {
16771678
return;
16781679
}
1679-
let _ = fs::remove_file(dst);
1680+
if fs::remove_file(dst).is_err() {
1681+
// workaround for https://github.com/rust-lang/rust/issues/127126
1682+
// if removing the file fails, attempt to rename it instead.
1683+
let now = SystemTime::now()
1684+
.duration_since(SystemTime::UNIX_EPOCH)
1685+
.expect("couldn't get system time");
1686+
let _ = fs::rename(dst, format!("{}-{}", dst.display(), now.as_nanos()));
1687+
}
16801688
let metadata = t!(src.symlink_metadata(), format!("src = {}", src.display()));
16811689
let mut src = src.to_path_buf();
16821690
if metadata.file_type().is_symlink() {

0 commit comments

Comments
 (0)