diff options
| author | Chris Denton <chris@chrisdenton.dev> | 2024-06-30 08:21:20 +0000 |
|---|---|---|
| committer | Chris Denton <chris@chrisdenton.dev> | 2024-06-30 08:35:39 +0000 |
| commit | 3d6cc605356f0919ae0bd024aba6cec5a9981ea7 (patch) | |
| tree | e013b1999f45c16e89fe611c1cb2f49124920e10 /src/bootstrap | |
| parent | 716752ebe6974b5c6ab9b34b894e075f3e4a4b1e (diff) | |
| download | rust-3d6cc605356f0919ae0bd024aba6cec5a9981ea7.tar.gz rust-3d6cc605356f0919ae0bd024aba6cec5a9981ea7.zip | |
Try renaming the file if removing fails
Diffstat (limited to 'src/bootstrap')
| -rw-r--r-- | src/bootstrap/src/lib.rs | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/bootstrap/src/lib.rs b/src/bootstrap/src/lib.rs index 730d0ae5f3d..6d00ff9982d 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; @@ -1676,7 +1677,14 @@ impl Build { if src == dst { return; } - let _ = fs::remove_file(dst); + if let Err(e) = fs::remove_file(dst) { + if 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() { |
