Skip to content

Commit ac8a698

Browse files
committed
bootstrap: improve error recovery flags to curl
alternative to #128459 fixes #110178
1 parent 899eb03 commit ac8a698

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/bootstrap/bootstrap.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ def get(base, url, path, checksums, verbose=False):
7979
eprint("removing", temp_path)
8080
os.unlink(temp_path)
8181

82+
def curl_version():
83+
return re.match("^curl ([0-9]+\\.[0-9]+)", run(["curl", "-V"]))[1]
8284

8385
def download(path, url, probably_big, verbose):
8486
for _ in range(4):
@@ -107,11 +109,15 @@ def _download(path, url, probably_big, verbose, exception):
107109
# If curl is not present on Win32, we should not sys.exit
108110
# but raise `CalledProcessError` or `OSError` instead
109111
require(["curl", "--version"], exception=platform_is_win32())
110-
run(["curl", option,
112+
extra_flags = []
113+
if curl_version() > 7.70:
114+
extra_flags = [ "--retry-all-errors" ]
115+
run(["curl", option] + extra_flags + [
111116
"-L", # Follow redirect.
112117
"-y", "30", "-Y", "10", # timeout if speed is < 10 bytes/sec for > 30 seconds
113118
"--connect-timeout", "30", # timeout if cannot connect within 30 seconds
114119
"-o", path,
120+
"--continue-at", "-",
115121
"--retry", "3", "-SRf", url],
116122
verbose=verbose,
117123
exception=True, # Will raise RuntimeError on failure

src/bootstrap/src/core/download.rs

+15
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ fn try_run(config: &Config, cmd: &mut Command) -> Result<(), ()> {
2121
config.try_run(cmd)
2222
}
2323

24+
fn curl_version() -> f32 {
25+
let mut curl = Command::new("curl");
26+
curl.arg("-V");
27+
let Ok(out) = curl.output() else { return 0.0 };
28+
let out = out.stdout;
29+
let Some(i) = out[5..].iter().position(|&x| x == b' ') else { return 0.0 };
30+
std::str::from_utf8(&out[5..i + 5]).unwrap().parse().unwrap_or(0.0)
31+
}
32+
2433
/// Generic helpers that are useful anywhere in bootstrap.
2534
impl Config {
2635
pub fn is_verbose(&self) -> bool {
@@ -219,6 +228,8 @@ impl Config {
219228
"30", // timeout if cannot connect within 30 seconds
220229
"-o",
221230
tempfile.to_str().unwrap(),
231+
"--continue-at",
232+
"-",
222233
"--retry",
223234
"3",
224235
"-SRf",
@@ -229,6 +240,10 @@ impl Config {
229240
} else {
230241
curl.arg("--progress-bar");
231242
}
243+
// --retry-all-errors was added in 7.71.0, don't use it if curl is old.
244+
if curl_version() > 7.70 {
245+
curl.arg("--retry-all-errors");
246+
}
232247
curl.arg(url);
233248
if !self.check_run(&mut curl) {
234249
if self.build.contains("windows-msvc") {

0 commit comments

Comments
 (0)