@@ -15,6 +15,8 @@ use std::{
15
15
env, fmt,
16
16
fs:: write,
17
17
path:: { Path , PathBuf } ,
18
+ thread,
19
+ time:: Duration ,
18
20
} ;
19
21
20
22
use clap:: { App , Arg , ArgMatches } ;
@@ -109,6 +111,22 @@ impl std::fmt::Display for ClippyWarning {
109
111
}
110
112
}
111
113
114
+ fn get ( path : & str ) -> Result < ureq:: Response , ureq:: Error > {
115
+ const MAX_RETRIES : u8 = 4 ;
116
+ let mut retries = 0 ;
117
+ loop {
118
+ match ureq:: get ( path) . call ( ) {
119
+ Ok ( res) => return Ok ( res) ,
120
+ Err ( e) if retries >= MAX_RETRIES => return Err ( e) ,
121
+ Err ( ureq:: Error :: Transport ( e) ) => eprintln ! ( "Error: {}" , e) ,
122
+ Err ( e) => return Err ( e) ,
123
+ }
124
+ eprintln ! ( "retrying in {} seconds..." , retries) ;
125
+ thread:: sleep ( Duration :: from_secs ( retries as u64 ) ) ;
126
+ retries += 1 ;
127
+ }
128
+ }
129
+
112
130
impl CrateSource {
113
131
/// Makes the sources available on the disk for clippy to check.
114
132
/// Clones a git repo and checks out the specified commit or downloads a crate from crates.io or
@@ -129,7 +147,7 @@ impl CrateSource {
129
147
if !krate_file_path. is_file ( ) {
130
148
// create a file path to download and write the crate data into
131
149
let mut krate_dest = std:: fs:: File :: create ( & krate_file_path) . unwrap ( ) ;
132
- let mut krate_req = ureq :: get ( & url) . call ( ) . unwrap ( ) . into_reader ( ) ;
150
+ let mut krate_req = get ( & url) . unwrap ( ) . into_reader ( ) ;
133
151
// copy the crate into the file
134
152
std:: io:: copy ( & mut krate_req, & mut krate_dest) . unwrap ( ) ;
135
153
0 commit comments