1- use  anyhow:: Error ; 
1+ use  anyhow:: { Context ,   Error } ; 
22use  curl:: easy:: Easy ; 
33use  indexmap:: IndexMap ; 
44use  std:: collections:: HashMap ; 
@@ -13,12 +13,13 @@ struct Tool {
1313    comments :  Vec < String > , 
1414
1515    channel :  Channel , 
16+     date :  Option < String > , 
1617    version :  [ u16 ;  3 ] , 
1718    checksums :  IndexMap < String ,  String > , 
1819} 
1920
2021impl  Tool  { 
21-     fn  new ( )  -> Result < Self ,  Error >  { 
22+     fn  new ( date :   Option < String > )  -> Result < Self ,  Error >  { 
2223        let  channel = match  std:: fs:: read_to_string ( "src/ci/channel" ) ?. trim ( )  { 
2324            "stable"  => Channel :: Stable , 
2425            "beta"  => Channel :: Beta , 
@@ -40,6 +41,7 @@ impl Tool {
4041        Ok ( Self  { 
4142            channel, 
4243            version, 
44+             date, 
4345            config :  existing. config , 
4446            comments :  existing. comments , 
4547            checksums :  IndexMap :: new ( ) , 
@@ -84,7 +86,7 @@ impl Tool {
8486            Channel :: Nightly  => "beta" . to_string ( ) , 
8587        } ; 
8688
87-         let  manifest = fetch_manifest ( & self . config ,  & channel) ?; 
89+         let  manifest = fetch_manifest ( & self . config ,  & channel,   self . date . as_deref ( ) ) ?; 
8890        self . collect_checksums ( & manifest,  COMPILER_COMPONENTS ) ?; 
8991        Ok ( Stage0Toolchain  { 
9092            date :  manifest. date , 
@@ -110,7 +112,7 @@ impl Tool {
110112            return  Ok ( None ) ; 
111113        } 
112114
113-         let  manifest = fetch_manifest ( & self . config ,  "nightly" ) ?; 
115+         let  manifest = fetch_manifest ( & self . config ,  "nightly" ,   self . date . as_deref ( ) ) ?; 
114116        self . collect_checksums ( & manifest,  RUSTFMT_COMPONENTS ) ?; 
115117        Ok ( Some ( Stage0Toolchain  {  date :  manifest. date ,  version :  "nightly" . into ( )  } ) ) 
116118    } 
@@ -141,16 +143,19 @@ impl Tool {
141143} 
142144
143145fn  main ( )  -> Result < ( ) ,  Error >  { 
144-     let  tool = Tool :: new ( ) ?; 
146+     let  tool = Tool :: new ( std :: env :: args ( ) . nth ( 1 ) ) ?; 
145147    tool. update_json ( ) ?; 
146148    Ok ( ( ) ) 
147149} 
148150
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) ?) ?) 
154159} 
155160
156161fn  http_get ( url :  & str )  -> Result < Vec < u8 > ,  Error >  { 
@@ -164,7 +169,7 @@ fn http_get(url: &str) -> Result<Vec<u8>, Error> {
164169            data. extend_from_slice ( new_data) ; 
165170            Ok ( new_data. len ( ) ) 
166171        } ) ?; 
167-         transfer. perform ( ) ?; 
172+         transfer. perform ( ) . context ( format ! ( "failed to fetch {url}" ) ) ?; 
168173    } 
169174    Ok ( data) 
170175} 
0 commit comments