@@ -17,7 +17,7 @@ use crate::dist::component::{
1717} ;
1818use crate :: dist:: config:: Config ;
1919use crate :: dist:: download:: { DownloadCfg , File } ;
20- use crate :: dist:: manifest:: { Component , CompressionKind , Manifest , TargetedPackage } ;
20+ use crate :: dist:: manifest:: { Component , CompressionKind , HashedBinary , Manifest , TargetedPackage } ;
2121use crate :: dist:: notifications:: * ;
2222use crate :: dist:: prefix:: InstallPrefix ;
2323use crate :: dist:: temp;
@@ -173,44 +173,41 @@ impl Manifestation {
173173 . unwrap_or ( DEFAULT_MAX_RETRIES ) ;
174174
175175 info ! ( "downloading component(s)" ) ;
176- for ( component , _ , url , _ ) in & components {
176+ for bin in & components {
177177 ( download_cfg. notify_handler ) ( Notification :: DownloadingComponent (
178- & component. short_name ( new_manifest) ,
178+ & bin . component . short_name ( new_manifest) ,
179179 & self . target_triple ,
180- component. target . as_ref ( ) ,
181- & url,
180+ bin . component . target . as_ref ( ) ,
181+ & bin . binary . url ,
182182 ) ) ;
183183 }
184184
185185 let semaphore = Arc :: new ( Semaphore :: new ( concurrent_downloads) ) ;
186- let component_stream =
187- tokio_stream:: iter ( components. into_iter ( ) ) . map ( |( component, format, url, hash) | {
188- let sem = semaphore. clone ( ) ;
189- async move {
190- let _permit = sem. acquire ( ) . await . unwrap ( ) ;
191- self . download_component (
192- & component,
193- & url,
194- & hash,
195- altered,
196- tmp_cx,
197- download_cfg,
198- max_retries,
199- new_manifest,
200- )
201- . await
202- . map ( |downloaded| ( component, format, downloaded, hash) )
203- }
204- } ) ;
186+ let component_stream = tokio_stream:: iter ( components. into_iter ( ) ) . map ( |bin| {
187+ let sem = semaphore. clone ( ) ;
188+ async move {
189+ let _permit = sem. acquire ( ) . await . unwrap ( ) ;
190+ self . download_component (
191+ & bin,
192+ altered,
193+ tmp_cx,
194+ download_cfg,
195+ max_retries,
196+ new_manifest,
197+ )
198+ . await
199+ . map ( |downloaded| ( bin, downloaded) )
200+ }
201+ } ) ;
205202 if components_len > 0 {
206203 let results = component_stream
207204 . buffered ( components_len)
208205 . collect :: < Vec < _ > > ( )
209206 . await ;
210207 for result in results {
211- let ( component , format , downloaded_file, hash ) = result?;
212- things_downloaded. push ( hash) ;
213- things_to_install. push ( ( component, format , downloaded_file) ) ;
208+ let ( bin , downloaded_file) = result?;
209+ things_downloaded. push ( bin . binary . hash . clone ( ) ) ;
210+ things_to_install. push ( ( bin . component , bin . binary . compression , downloaded_file) ) ;
214211 }
215212 }
216213
@@ -532,12 +529,9 @@ impl Manifestation {
532529 Ok ( tx)
533530 }
534531
535- #[ allow( clippy:: too_many_arguments) ]
536532 async fn download_component (
537533 & self ,
538- component : & Component ,
539- url : & str ,
540- hash : & str ,
534+ component : & ComponentBinary < ' _ > ,
541535 altered : bool ,
542536 tmp_cx : & temp:: Context ,
543537 download_cfg : & DownloadCfg < ' _ > ,
@@ -547,16 +541,19 @@ impl Manifestation {
547541 use tokio_retry:: { RetryIf , strategy:: FixedInterval } ;
548542
549543 let url = if altered {
550- url. replace ( DEFAULT_DIST_SERVER , tmp_cx. dist_server . as_str ( ) )
544+ component
545+ . binary
546+ . url
547+ . replace ( DEFAULT_DIST_SERVER , tmp_cx. dist_server . as_str ( ) )
551548 } else {
552- url. to_owned ( )
549+ component . binary . url . clone ( )
553550 } ;
554551
555552 let url_url = utils:: parse_url ( & url) ?;
556553
557554 let downloaded_file = RetryIf :: spawn (
558555 FixedInterval :: from_millis ( 0 ) . take ( max_retries) ,
559- || download_cfg. download ( & url_url, & hash) ,
556+ || download_cfg. download ( & url_url, & component . binary . hash ) ,
560557 |e : & anyhow:: Error | {
561558 // retry only known retriable cases
562559 match e. downcast_ref :: < RustupError > ( ) {
@@ -570,7 +567,9 @@ impl Manifestation {
570567 } ,
571568 )
572569 . await
573- . with_context ( || RustupError :: ComponentDownloadFailed ( component. name ( new_manifest) ) ) ?;
570+ . with_context ( || {
571+ RustupError :: ComponentDownloadFailed ( component. component . name ( new_manifest) )
572+ } ) ?;
574573
575574 Ok ( downloaded_file)
576575 }
@@ -765,10 +764,10 @@ impl Update {
765764 }
766765
767766 /// Map components to urls and hashes
768- fn components_urls_and_hashes (
769- & self ,
770- new_manifest : & Manifest ,
771- ) -> Result < Vec < ( Component , CompressionKind , String , String ) > > {
767+ fn components_urls_and_hashes < ' a > (
768+ & ' a self ,
769+ new_manifest : & ' a Manifest ,
770+ ) -> Result < Vec < ComponentBinary < ' a > > > {
772771 let mut components_urls_and_hashes = Vec :: new ( ) ;
773772 for component in & self . components_to_install {
774773 let package = new_manifest. get_package ( component. short_name_in_manifest ( ) ) ?;
@@ -780,14 +779,17 @@ impl Update {
780779 }
781780 // We prefer the first format in the list, since the parsing of the
782781 // manifest leaves us with the files/hash pairs in preference order.
783- components_urls_and_hashes. push ( (
784- component. clone ( ) ,
785- target_package. bins [ 0 ] . compression ,
786- target_package. bins [ 0 ] . url . clone ( ) ,
787- target_package. bins [ 0 ] . hash . clone ( ) ,
788- ) ) ;
782+ components_urls_and_hashes. push ( ComponentBinary {
783+ component,
784+ binary : & target_package. bins [ 0 ] ,
785+ } ) ;
789786 }
790787
791788 Ok ( components_urls_and_hashes)
792789 }
793790}
791+
792+ struct ComponentBinary < ' a > {
793+ component : & ' a Component ,
794+ binary : & ' a HashedBinary ,
795+ }
0 commit comments