1
1
use curl;
2
2
use git2;
3
+ use url:: Url ;
3
4
4
5
use failure:: Error ;
5
6
@@ -37,15 +38,17 @@ fn maybe_spurious(err: &Error) -> bool {
37
38
/// Suggest the user to update their windows 7 to support modern TLS versions.
38
39
/// See https://github.com/rust-lang/cargo/issues/5066 for details.
39
40
#[ cfg( windows) ]
40
- fn should_warn_about_old_tls_for_win7 ( err : & Error ) -> bool {
41
- err. causes ( )
41
+ fn should_warn_about_old_tls_for_win7 ( url : & Url , err : & Error ) -> bool {
42
+ let is_github = url. host_str ( ) == Some ( "github.com" ) ;
43
+ let is_cert_error = err. causes ( )
42
44
. filter_map ( |e| e. downcast_ref :: < git2:: Error > ( ) )
43
45
. find ( |e| e. class ( ) == git2:: ErrorClass :: Net && e. code ( ) == git2:: ErrorCode :: Certificate )
44
- . is_some ( )
46
+ . is_some ( ) ;
47
+ is_github && is_cert_error
45
48
}
46
49
47
50
#[ cfg( not( windows) ) ]
48
- fn should_warn_about_old_tls_for_win7 ( _err : & Error ) -> bool {
51
+ fn should_warn_about_old_tls_for_win7 ( _url : & Url , _err : & Error ) -> bool {
49
52
false
50
53
}
51
54
@@ -71,9 +74,9 @@ See https://github.com/rust-lang/cargo/issues/5066 for details.
71
74
///
72
75
/// ```ignore
73
76
/// use util::network;
74
- /// cargo_result = network. with_retry(&config, || something.download());
77
+ /// cargo_result = network:: with_retry(&config, || something.download());
75
78
/// ```
76
- pub fn with_retry < T , F > ( config : & Config , mut callback : F ) -> CargoResult < T >
79
+ pub fn with_retry < T , F > ( config : & Config , url : & Url , mut callback : F ) -> CargoResult < T >
77
80
where F : FnMut ( ) -> CargoResult < T >
78
81
{
79
82
let mut remaining = config. net_retry ( ) ?;
@@ -85,7 +88,7 @@ pub fn with_retry<T, F>(config: &Config, mut callback: F) -> CargoResult<T>
85
88
format ! ( "spurious network error ({} tries remaining): {}" , remaining, e)
86
89
) ?;
87
90
88
- if should_warn_about_old_tls_for_win7 ( e) {
91
+ if should_warn_about_old_tls_for_win7 ( url , e) {
89
92
config. shell ( ) . warn ( WIN7_TLS_WARNING ) ?;
90
93
}
91
94
@@ -103,7 +106,8 @@ fn with_retry_repeats_the_call_then_works() {
103
106
let error2 = HttpNot200 { code : 502 , url : "Uri" . to_string ( ) } . into ( ) ;
104
107
let mut results: Vec < CargoResult < ( ) > > = vec ! [ Ok ( ( ) ) , Err ( error1) , Err ( error2) ] ;
105
108
let config = Config :: default ( ) . unwrap ( ) ;
106
- let result = with_retry ( & config, || results. pop ( ) . unwrap ( ) ) ;
109
+ let url = "http://example.com" . parse ( ) . unwrap ( ) ;
110
+ let result = with_retry ( & config, & url, || results. pop ( ) . unwrap ( ) ) ;
107
111
assert_eq ! ( result. unwrap( ) , ( ) )
108
112
}
109
113
@@ -119,6 +123,7 @@ fn with_retry_finds_nested_spurious_errors() {
119
123
let error2 = CargoError :: from ( error2. context ( "A second chained error" ) ) ;
120
124
let mut results: Vec < CargoResult < ( ) > > = vec ! [ Ok ( ( ) ) , Err ( error1) , Err ( error2) ] ;
121
125
let config = Config :: default ( ) . unwrap ( ) ;
122
- let result = with_retry ( & config, || results. pop ( ) . unwrap ( ) ) ;
126
+ let url = "http://example.com" . parse ( ) . unwrap ( ) ;
127
+ let result = with_retry ( & config, & url, || results. pop ( ) . unwrap ( ) ) ;
123
128
assert_eq ! ( result. unwrap( ) , ( ) )
124
129
}
0 commit comments