@@ -187,16 +187,9 @@ impl Manifestation {
187187 let sem = semaphore. clone ( ) ;
188188 async move {
189189 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) )
190+ bin. download ( altered, tmp_cx, download_cfg, max_retries, new_manifest)
191+ . await
192+ . map ( |downloaded| ( bin, downloaded) )
200193 }
201194 } ) ;
202195 if components_len > 0 {
@@ -528,51 +521,6 @@ impl Manifestation {
528521
529522 Ok ( tx)
530523 }
531-
532- async fn download_component (
533- & self ,
534- component : & ComponentBinary < ' _ > ,
535- altered : bool ,
536- tmp_cx : & temp:: Context ,
537- download_cfg : & DownloadCfg < ' _ > ,
538- max_retries : usize ,
539- new_manifest : & Manifest ,
540- ) -> Result < File > {
541- use tokio_retry:: { RetryIf , strategy:: FixedInterval } ;
542-
543- let url = if altered {
544- component
545- . binary
546- . url
547- . replace ( DEFAULT_DIST_SERVER , tmp_cx. dist_server . as_str ( ) )
548- } else {
549- component. binary . url . clone ( )
550- } ;
551-
552- let url_url = utils:: parse_url ( & url) ?;
553-
554- let downloaded_file = RetryIf :: spawn (
555- FixedInterval :: from_millis ( 0 ) . take ( max_retries) ,
556- || download_cfg. download ( & url_url, & component. binary . hash ) ,
557- |e : & anyhow:: Error | {
558- // retry only known retriable cases
559- match e. downcast_ref :: < RustupError > ( ) {
560- Some ( RustupError :: BrokenPartialFile )
561- | Some ( RustupError :: DownloadingFile { .. } ) => {
562- ( download_cfg. notify_handler ) ( Notification :: RetryingDownload ( & url) ) ;
563- true
564- }
565- _ => false ,
566- }
567- } ,
568- )
569- . await
570- . with_context ( || {
571- RustupError :: ComponentDownloadFailed ( component. component . name ( new_manifest) )
572- } ) ?;
573-
574- Ok ( downloaded_file)
575- }
576524}
577525
578526#[ derive( Debug ) ]
@@ -793,3 +741,46 @@ struct ComponentBinary<'a> {
793741 component : & ' a Component ,
794742 binary : & ' a HashedBinary ,
795743}
744+
745+ impl < ' a > ComponentBinary < ' a > {
746+ async fn download (
747+ & self ,
748+ altered : bool ,
749+ tmp_cx : & temp:: Context ,
750+ download_cfg : & DownloadCfg < ' _ > ,
751+ max_retries : usize ,
752+ new_manifest : & Manifest ,
753+ ) -> Result < File > {
754+ use tokio_retry:: { RetryIf , strategy:: FixedInterval } ;
755+
756+ let url = if altered {
757+ self . binary
758+ . url
759+ . replace ( DEFAULT_DIST_SERVER , tmp_cx. dist_server . as_str ( ) )
760+ } else {
761+ self . binary . url . clone ( )
762+ } ;
763+
764+ let url_url = utils:: parse_url ( & url) ?;
765+
766+ let downloaded_file = RetryIf :: spawn (
767+ FixedInterval :: from_millis ( 0 ) . take ( max_retries) ,
768+ || download_cfg. download ( & url_url, & self . binary . hash ) ,
769+ |e : & anyhow:: Error | {
770+ // retry only known retriable cases
771+ match e. downcast_ref :: < RustupError > ( ) {
772+ Some ( RustupError :: BrokenPartialFile )
773+ | Some ( RustupError :: DownloadingFile { .. } ) => {
774+ ( download_cfg. notify_handler ) ( Notification :: RetryingDownload ( & url) ) ;
775+ true
776+ }
777+ _ => false ,
778+ }
779+ } ,
780+ )
781+ . await
782+ . with_context ( || RustupError :: ComponentDownloadFailed ( self . component . name ( new_manifest) ) ) ?;
783+
784+ Ok ( downloaded_file)
785+ }
786+ }
0 commit comments