Skip to content

Commit 49ff390

Browse files
committed
Auto merge of #127152 - ChrisDenton:rename, r=onur-ozkan
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 bcf38b5 + b998cff commit 49ff390

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;
@@ -1647,7 +1648,14 @@ impl Build {
16471648
if src == dst {
16481649
return;
16491650
}
1650-
let _ = fs::remove_file(dst);
1651+
if let Err(e) = fs::remove_file(dst) {
1652+
if cfg!(windows) && e.kind() != io::ErrorKind::NotFound {
1653+
// workaround for https://github.com/rust-lang/rust/issues/127126
1654+
// if removing the file fails, attempt to rename it instead.
1655+
let now = t!(SystemTime::now().duration_since(SystemTime::UNIX_EPOCH));
1656+
let _ = fs::rename(dst, format!("{}-{}", dst.display(), now.as_nanos()));
1657+
}
1658+
}
16511659
let metadata = t!(src.symlink_metadata(), format!("src = {}", src.display()));
16521660
let mut src = src.to_path_buf();
16531661
if metadata.file_type().is_symlink() {

0 commit comments

Comments
 (0)