1
- use anyhow:: Error ;
1
+ use anyhow:: { Context , Error } ;
2
2
use curl:: easy:: Easy ;
3
3
use indexmap:: IndexMap ;
4
4
use std:: collections:: HashMap ;
@@ -13,12 +13,13 @@ struct Tool {
13
13
comments : Vec < String > ,
14
14
15
15
channel : Channel ,
16
+ date : Option < String > ,
16
17
version : [ u16 ; 3 ] ,
17
18
checksums : IndexMap < String , String > ,
18
19
}
19
20
20
21
impl Tool {
21
- fn new ( ) -> Result < Self , Error > {
22
+ fn new ( date : Option < String > ) -> Result < Self , Error > {
22
23
let channel = match std:: fs:: read_to_string ( "src/ci/channel" ) ?. trim ( ) {
23
24
"stable" => Channel :: Stable ,
24
25
"beta" => Channel :: Beta ,
@@ -40,6 +41,7 @@ impl Tool {
40
41
Ok ( Self {
41
42
channel,
42
43
version,
44
+ date,
43
45
config : existing. config ,
44
46
comments : existing. comments ,
45
47
checksums : IndexMap :: new ( ) ,
@@ -84,7 +86,7 @@ impl Tool {
84
86
Channel :: Nightly => "beta" . to_string ( ) ,
85
87
} ;
86
88
87
- let manifest = fetch_manifest ( & self . config , & channel) ?;
89
+ let manifest = fetch_manifest ( & self . config , & channel, self . date . as_deref ( ) ) ?;
88
90
self . collect_checksums ( & manifest, COMPILER_COMPONENTS ) ?;
89
91
Ok ( Stage0Toolchain {
90
92
date : manifest. date ,
@@ -110,7 +112,7 @@ impl Tool {
110
112
return Ok ( None ) ;
111
113
}
112
114
113
- let manifest = fetch_manifest ( & self . config , "nightly" ) ?;
115
+ let manifest = fetch_manifest ( & self . config , "nightly" , self . date . as_deref ( ) ) ?;
114
116
self . collect_checksums ( & manifest, RUSTFMT_COMPONENTS ) ?;
115
117
Ok ( Some ( Stage0Toolchain { date : manifest. date , version : "nightly" . into ( ) } ) )
116
118
}
@@ -141,16 +143,19 @@ impl Tool {
141
143
}
142
144
143
145
fn main ( ) -> Result < ( ) , Error > {
144
- let tool = Tool :: new ( ) ?;
146
+ let tool = Tool :: new ( std :: env :: args ( ) . nth ( 1 ) ) ?;
145
147
tool. update_json ( ) ?;
146
148
Ok ( ( ) )
147
149
}
148
150
149
- fn fetch_manifest ( config : & Config , channel : & str ) -> Result < Manifest , Error > {
150
- Ok ( toml:: from_slice ( & http_get ( & format ! (
151
- "{}/dist/channel-rust-{}.toml" ,
152
- config. dist_server, channel
153
- ) ) ?) ?)
151
+ fn fetch_manifest ( config : & Config , channel : & str , date : Option < & str > ) -> Result < Manifest , Error > {
152
+ let url = if let Some ( date) = date {
153
+ format ! ( "{}/dist/{}/channel-rust-{}.toml" , config. dist_server, date, channel)
154
+ } else {
155
+ format ! ( "{}/dist/channel-rust-{}.toml" , config. dist_server, channel)
156
+ } ;
157
+
158
+ Ok ( toml:: from_slice ( & http_get ( & url) ?) ?)
154
159
}
155
160
156
161
fn http_get ( url : & str ) -> Result < Vec < u8 > , Error > {
@@ -164,7 +169,7 @@ fn http_get(url: &str) -> Result<Vec<u8>, Error> {
164
169
data. extend_from_slice ( new_data) ;
165
170
Ok ( new_data. len ( ) )
166
171
} ) ?;
167
- transfer. perform ( ) ?;
172
+ transfer. perform ( ) . context ( format ! ( "failed to fetch {url}" ) ) ?;
168
173
}
169
174
Ok ( data)
170
175
}
0 commit comments