@@ -352,34 +352,51 @@ impl Step for Openssl {
352352 // originally from https://www.openssl.org/source/...
353353 let url = format ! ( "https://s3-us-west-1.amazonaws.com/rust-lang-ci2/rust-ci-mirror/{}" ,
354354 name) ;
355- let mut ok = false ;
355+ let mut last_error = None ;
356356 for _ in 0 ..3 {
357357 let status = Command :: new ( "curl" )
358358 . arg ( "-o" ) . arg ( & tmp)
359+ . arg ( "-f" ) // make curl fail if the URL does not return HTTP 200
359360 . arg ( & url)
360361 . status ( )
361362 . expect ( "failed to spawn curl" ) ;
362- if status. success ( ) {
363- ok = true ;
364- break
363+
364+ // Retry if download failed.
365+ if !status. success ( ) {
366+ last_error = Some ( status. to_string ( ) ) ;
367+ continue ;
365368 }
369+
370+ // Ensure the hash is correct.
371+ let mut shasum = if target. contains ( "apple" ) || build. build . contains ( "netbsd" ) {
372+ let mut cmd = Command :: new ( "shasum" ) ;
373+ cmd. arg ( "-a" ) . arg ( "256" ) ;
374+ cmd
375+ } else {
376+ Command :: new ( "sha256sum" )
377+ } ;
378+ let output = output ( & mut shasum. arg ( & tmp) ) ;
379+ let found = output. split_whitespace ( ) . next ( ) . unwrap ( ) ;
380+
381+ // If the hash is wrong, probably the download is incomplete or S3 served an error
382+ // page. In any case, retry.
383+ if found != OPENSSL_SHA256 {
384+ last_error = Some ( format ! (
385+ "downloaded openssl sha256 different\n \
386+ expected: {}\n \
387+ found: {}\n ",
388+ OPENSSL_SHA256 ,
389+ found
390+ ) ) ;
391+ continue ;
392+ }
393+
394+ // Everything is fine, so exit the retry loop.
395+ last_error = None ;
396+ break ;
366397 }
367- if !ok {
368- panic ! ( "failed to download openssl source" )
369- }
370- let mut shasum = if target. contains ( "apple" ) || build. build . contains ( "netbsd" ) {
371- let mut cmd = Command :: new ( "shasum" ) ;
372- cmd. arg ( "-a" ) . arg ( "256" ) ;
373- cmd
374- } else {
375- Command :: new ( "sha256sum" )
376- } ;
377- let output = output ( & mut shasum. arg ( & tmp) ) ;
378- let found = output. split_whitespace ( ) . next ( ) . unwrap ( ) ;
379- if found != OPENSSL_SHA256 {
380- panic ! ( "downloaded openssl sha256 different\n \
381- expected: {}\n \
382- found: {}\n ", OPENSSL_SHA256 , found) ;
398+ if let Some ( error) = last_error {
399+ panic ! ( "failed to download openssl source: {}" , error) ;
383400 }
384401 t ! ( fs:: rename( & tmp, & tarball) ) ;
385402 }
0 commit comments