Skip to content

Commit 2afa4a6

Browse files
committed
Retry deleting dst a number of times
1 parent 716752e commit 2afa4a6

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/bootstrap/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use filetime::FileTime;
3434
use sha2::digest::Digest;
3535
use termcolor::{ColorChoice, StandardStream, WriteColor};
3636
use utils::channel::GitInfo;
37-
use utils::helpers::hex_encode;
37+
use utils::helpers::{hex_encode, retry};
3838

3939
use crate::core::builder;
4040
use crate::core::builder::Kind;
@@ -1676,7 +1676,7 @@ impl Build {
16761676
if src == dst {
16771677
return;
16781678
}
1679-
let _ = fs::remove_file(dst);
1679+
let _ = retry(60, || fs::remove_file(dst));
16801680
let metadata = t!(src.symlink_metadata(), format!("src = {}", src.display()));
16811681
let mut src = src.to_path_buf();
16821682
if metadata.file_type().is_symlink() {

src/bootstrap/src/utils/helpers.rs

+16
Original file line numberDiff line numberDiff line change
@@ -517,3 +517,19 @@ pub fn git(source_dir: Option<&Path>) -> Command {
517517

518518
git
519519
}
520+
521+
/// Retry a function up to n times, returning the last call to fun.
522+
/// Stops early if the function returns `Ok`.
523+
pub fn retry<T, E>(n: usize, mut fun: impl FnMut() -> Result<T, E>) -> Result<T, E> {
524+
let mut retries = 0;
525+
loop {
526+
retries += 1;
527+
528+
let result = fun();
529+
if result.is_ok() || retries == n {
530+
return result;
531+
}
532+
// wait an arbitrary length of time.
533+
std::thread::sleep(std::time::Duration::from_secs(1));
534+
}
535+
}

0 commit comments

Comments
 (0)