diff options
| author | bors <bors@rust-lang.org> | 2021-09-21 16:59:48 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-09-21 16:59:48 +0000 |
| commit | 848e5518d66ff2084c10a4c1cfcf5da5e0534033 (patch) | |
| tree | 396f3788d463fd37be4013a1b1f9fe862c8e683d | |
| parent | 871ad80bb02af6d8fbf3f5c7291916b817c75168 (diff) | |
| parent | 41fe5461f432266afe75c7cd183aae27306c7c08 (diff) | |
| download | rust-848e5518d66ff2084c10a4c1cfcf5da5e0534033.tar.gz rust-848e5518d66ff2084c10a4c1cfcf5da5e0534033.zip | |
Auto merge of #7694 - Jarcho:lintcheck_retry, r=matthiaskrgr
Retry on some download errors in lintcheck I'm currently on spotty wifi right now. It is shocking the number of things that break when you lose connection for a few seconds. Some 500 errors should probably also be retried, but this fixes my issue. changelog: None
| -rw-r--r-- | lintcheck/src/main.rs | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/lintcheck/src/main.rs b/lintcheck/src/main.rs index f1e03ba4296..97d3794fb84 100644 --- a/lintcheck/src/main.rs +++ b/lintcheck/src/main.rs @@ -15,6 +15,8 @@ use std::{ env, fmt, fs::write, path::{Path, PathBuf}, + thread, + time::Duration, }; use clap::{App, Arg, ArgMatches}; @@ -109,6 +111,22 @@ impl std::fmt::Display for ClippyWarning { } } +fn get(path: &str) -> Result<ureq::Response, ureq::Error> { + const MAX_RETRIES: u8 = 4; + let mut retries = 0; + loop { + match ureq::get(path).call() { + Ok(res) => return Ok(res), + Err(e) if retries >= MAX_RETRIES => return Err(e), + Err(ureq::Error::Transport(e)) => eprintln!("Error: {}", e), + Err(e) => return Err(e), + } + eprintln!("retrying in {} seconds...", retries); + thread::sleep(Duration::from_secs(retries as u64)); + retries += 1; + } +} + impl CrateSource { /// Makes the sources available on the disk for clippy to check. /// Clones a git repo and checks out the specified commit or downloads a crate from crates.io or @@ -129,7 +147,7 @@ impl CrateSource { if !krate_file_path.is_file() { // create a file path to download and write the crate data into let mut krate_dest = std::fs::File::create(&krate_file_path).unwrap(); - let mut krate_req = ureq::get(&url).call().unwrap().into_reader(); + let mut krate_req = get(&url).unwrap().into_reader(); // copy the crate into the file std::io::copy(&mut krate_req, &mut krate_dest).unwrap(); |
