@@ -17,7 +17,7 @@ use crate::dist::component::{
17
17
} ;
18
18
use crate :: dist:: config:: Config ;
19
19
use crate :: dist:: download:: { DownloadCfg , File } ;
20
- use crate :: dist:: manifest:: { Component , CompressionKind , Manifest , TargetedPackage } ;
20
+ use crate :: dist:: manifest:: { Component , CompressionKind , HashedBinary , Manifest , TargetedPackage } ;
21
21
use crate :: dist:: notifications:: * ;
22
22
use crate :: dist:: prefix:: InstallPrefix ;
23
23
use crate :: dist:: temp;
@@ -173,44 +173,41 @@ impl Manifestation {
173
173
. unwrap_or ( DEFAULT_MAX_RETRIES ) ;
174
174
175
175
info ! ( "downloading component(s)" ) ;
176
- for ( component , _ , url , _ ) in & components {
176
+ for bin in & components {
177
177
( download_cfg. notify_handler ) ( Notification :: DownloadingComponent (
178
- & component. short_name ( new_manifest) ,
178
+ & bin . component . short_name ( new_manifest) ,
179
179
& self . target_triple ,
180
- component. target . as_ref ( ) ,
181
- & url,
180
+ bin . component . target . as_ref ( ) ,
181
+ & bin . binary . url ,
182
182
) ) ;
183
183
}
184
184
185
185
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
+ } ) ;
205
202
if components_len > 0 {
206
203
let results = component_stream
207
204
. buffered ( components_len)
208
205
. collect :: < Vec < _ > > ( )
209
206
. await ;
210
207
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) ) ;
214
211
}
215
212
}
216
213
@@ -532,12 +529,9 @@ impl Manifestation {
532
529
Ok ( tx)
533
530
}
534
531
535
- #[ allow( clippy:: too_many_arguments) ]
536
532
async fn download_component (
537
533
& self ,
538
- component : & Component ,
539
- url : & str ,
540
- hash : & str ,
534
+ component : & ComponentBinary < ' _ > ,
541
535
altered : bool ,
542
536
tmp_cx : & temp:: Context ,
543
537
download_cfg : & DownloadCfg < ' _ > ,
@@ -547,16 +541,19 @@ impl Manifestation {
547
541
use tokio_retry:: { RetryIf , strategy:: FixedInterval } ;
548
542
549
543
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 ( ) )
551
548
} else {
552
- url. to_owned ( )
549
+ component . binary . url . clone ( )
553
550
} ;
554
551
555
552
let url_url = utils:: parse_url ( & url) ?;
556
553
557
554
let downloaded_file = RetryIf :: spawn (
558
555
FixedInterval :: from_millis ( 0 ) . take ( max_retries) ,
559
- || download_cfg. download ( & url_url, & hash) ,
556
+ || download_cfg. download ( & url_url, & component . binary . hash ) ,
560
557
|e : & anyhow:: Error | {
561
558
// retry only known retriable cases
562
559
match e. downcast_ref :: < RustupError > ( ) {
@@ -570,7 +567,9 @@ impl Manifestation {
570
567
} ,
571
568
)
572
569
. await
573
- . with_context ( || RustupError :: ComponentDownloadFailed ( component. name ( new_manifest) ) ) ?;
570
+ . with_context ( || {
571
+ RustupError :: ComponentDownloadFailed ( component. component . name ( new_manifest) )
572
+ } ) ?;
574
573
575
574
Ok ( downloaded_file)
576
575
}
@@ -765,10 +764,10 @@ impl Update {
765
764
}
766
765
767
766
/// 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 > > > {
772
771
let mut components_urls_and_hashes = Vec :: new ( ) ;
773
772
for component in & self . components_to_install {
774
773
let package = new_manifest. get_package ( component. short_name_in_manifest ( ) ) ?;
@@ -780,14 +779,17 @@ impl Update {
780
779
}
781
780
// We prefer the first format in the list, since the parsing of the
782
781
// 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
+ } ) ;
789
786
}
790
787
791
788
Ok ( components_urls_and_hashes)
792
789
}
793
790
}
791
+
792
+ struct ComponentBinary < ' a > {
793
+ component : & ' a Component ,
794
+ binary : & ' a HashedBinary ,
795
+ }
0 commit comments