Skip to content

Bootstrap: Retry copying/linking #127147

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/bootstrap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use filetime::FileTime;
use sha2::digest::Digest;
use termcolor::{ColorChoice, StandardStream, WriteColor};
use utils::channel::GitInfo;
use utils::helpers::hex_encode;
use utils::helpers::{hex_encode, retry};

use crate::core::builder;
use crate::core::builder::Kind;
Expand Down Expand Up @@ -1676,7 +1676,7 @@ impl Build {
if src == dst {
return;
}
let _ = fs::remove_file(dst);
let _ = retry(60, || fs::remove_file(dst));
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
16 changes: 16 additions & 0 deletions src/bootstrap/src/utils/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,3 +517,19 @@ pub fn git(source_dir: Option<&Path>) -> Command {

git
}

/// Retry a function up to n times, returning the last call to fun.
/// Stops early if the function returns `Ok`.
pub fn retry<T, E>(n: usize, mut fun: impl FnMut() -> Result<T, E>) -> Result<T, E> {
let mut retries = 0;
loop {
retries += 1;

let result = fun();
if result.is_ok() || retries == n {
return result;
}
// wait an arbitrary length of time.
std::thread::sleep(std::time::Duration::from_secs(1));
}
}
Loading