@@ -6,9 +6,8 @@ mod tests;
66
77use std:: path:: Path ;
88
9- use anyhow:: { Context , Error , Result , anyhow, bail} ;
9+ use anyhow:: { Context , Result , anyhow, bail} ;
1010use futures_util:: stream:: StreamExt ;
11- use tokio_retry:: { RetryIf , strategy:: FixedInterval } ;
1211use tracing:: info;
1312
1413use crate :: dist:: component:: {
@@ -177,38 +176,17 @@ impl Manifestation {
177176
178177 let component_stream =
179178 tokio_stream:: iter ( components. into_iter ( ) ) . map ( |( component, format, url, hash) | {
180- async move {
181- let url = if altered {
182- url. replace ( DEFAULT_DIST_SERVER , tmp_cx. dist_server . as_str ( ) )
183- } else {
184- url
185- } ;
186-
187- let url_url = utils:: parse_url ( & url) ?;
188-
189- let downloaded_file = RetryIf :: spawn (
190- FixedInterval :: from_millis ( 0 ) . take ( max_retries) ,
191- || download_cfg. download ( & url_url, & hash) ,
192- |e : & anyhow:: Error | {
193- // retry only known retriable cases
194- match e. downcast_ref :: < RustupError > ( ) {
195- Some ( RustupError :: BrokenPartialFile )
196- | Some ( RustupError :: DownloadingFile { .. } ) => {
197- ( download_cfg. notify_handler ) ( Notification :: RetryingDownload (
198- & url,
199- ) ) ;
200- true
201- }
202- _ => false ,
203- }
204- } ,
205- )
206- . await
207- . with_context ( || {
208- RustupError :: ComponentDownloadFailed ( component. name ( new_manifest) )
209- } ) ?;
210- Ok :: < _ , Error > ( ( component, format, downloaded_file, hash) )
211- }
179+ self . download_component (
180+ component,
181+ format,
182+ url,
183+ hash,
184+ altered,
185+ tmp_cx,
186+ download_cfg,
187+ max_retries,
188+ new_manifest,
189+ )
212190 } ) ;
213191 if components_len > 0 {
214192 let results = component_stream
@@ -555,6 +533,50 @@ impl Manifestation {
555533
556534 Ok ( tx)
557535 }
536+
537+ #[ allow( clippy:: too_many_arguments) ]
538+ async fn download_component (
539+ & self ,
540+ component : Component ,
541+ format : CompressionKind ,
542+ url : String ,
543+ hash : String ,
544+ altered : bool ,
545+ tmp_cx : & temp:: Context ,
546+ download_cfg : & DownloadCfg < ' _ > ,
547+ max_retries : usize ,
548+ new_manifest : & Manifest ,
549+ ) -> Result < ( Component , CompressionKind , File , String ) > {
550+ use tokio_retry:: { RetryIf , strategy:: FixedInterval } ;
551+
552+ let url = if altered {
553+ url. replace ( DEFAULT_DIST_SERVER , tmp_cx. dist_server . as_str ( ) )
554+ } else {
555+ url
556+ } ;
557+
558+ let url_url = utils:: parse_url ( & url) ?;
559+
560+ let downloaded_file = RetryIf :: spawn (
561+ FixedInterval :: from_millis ( 0 ) . take ( max_retries) ,
562+ || download_cfg. download ( & url_url, & hash) ,
563+ |e : & anyhow:: Error | {
564+ // retry only known retriable cases
565+ match e. downcast_ref :: < RustupError > ( ) {
566+ Some ( RustupError :: BrokenPartialFile )
567+ | Some ( RustupError :: DownloadingFile { .. } ) => {
568+ ( download_cfg. notify_handler ) ( Notification :: RetryingDownload ( & url) ) ;
569+ true
570+ }
571+ _ => false ,
572+ }
573+ } ,
574+ )
575+ . await
576+ . with_context ( || RustupError :: ComponentDownloadFailed ( component. name ( new_manifest) ) ) ?;
577+
578+ Ok ( ( component, format, downloaded_file, hash) )
579+ }
558580}
559581
560582#[ derive( Debug ) ]
0 commit comments