55mod tests;
66
77use std:: path:: Path ;
8- #[ cfg( test) ]
98use std:: sync:: Arc ;
109
1110use anyhow:: { Context , Result , anyhow, bail} ;
1211use futures_util:: stream:: { FuturesUnordered , StreamExt } ;
1312use tracing:: { info, warn} ;
1413
15- use crate :: diskio:: { IO_CHUNK_SIZE , get_executor, unpack_ram} ;
14+ use crate :: diskio:: { Executor , IO_CHUNK_SIZE , get_executor, unpack_ram} ;
1615use crate :: dist:: component:: { Components , DirectoryPackage , Transaction } ;
1716use crate :: dist:: config:: Config ;
1817use crate :: dist:: download:: { DownloadCfg , DownloadStatus , File } ;
1918use crate :: dist:: manifest:: { Component , CompressionKind , HashedBinary , Manifest } ;
2019use crate :: dist:: prefix:: InstallPrefix ;
21- #[ cfg( test) ]
2220use crate :: dist:: temp;
2321use crate :: dist:: { DEFAULT_DIST_SERVER , Profile , TargetTriple } ;
2422use crate :: errors:: RustupError ;
@@ -216,6 +214,7 @@ impl Manifestation {
216214 let mut downloads = FuturesUnordered :: new ( ) ;
217215 let mut component_iter = components. into_iter ( ) ;
218216 let mut cleanup_downloads = vec ! [ ] ;
217+ let manifestation = Arc :: new ( self ) ;
219218 loop {
220219 if downloads. is_empty ( ) && component_iter. len ( ) == 0 {
221220 break ;
@@ -228,9 +227,9 @@ impl Manifestation {
228227 }
229228 }
230229
231- if let Some ( ( bin , downloaded ) ) = installable {
232- cleanup_downloads. push ( & bin . binary . hash ) ;
233- tx = bin . install ( downloaded , tx, & self ) ?;
230+ if let Some ( ( installable , hash ) ) = installable {
231+ cleanup_downloads. push ( hash) ;
232+ tx = installable . install ( tx, manifestation . clone ( ) ) ?;
234233 }
235234 }
236235
@@ -646,11 +645,11 @@ impl<'a> ComponentBinary<'a> {
646645 } ) )
647646 }
648647
649- async fn download ( self , max_retries : usize ) -> Result < ( Self , File ) > {
648+ async fn download ( self , max_retries : usize ) -> Result < ( ComponentInstall , & ' a str ) > {
650649 use tokio_retry:: { RetryIf , strategy:: FixedInterval } ;
651650
652651 let url = self . download_cfg . url ( & self . binary . url ) ?;
653- let downloaded_file = RetryIf :: spawn (
652+ let installer = RetryIf :: spawn (
654653 FixedInterval :: from_millis ( 0 ) . take ( max_retries) ,
655654 || {
656655 self . download_cfg
@@ -673,36 +672,53 @@ impl<'a> ComponentBinary<'a> {
673672 RustupError :: ComponentDownloadFailed ( self . manifest . name ( & self . component ) )
674673 } ) ?;
675674
676- Ok ( ( self , downloaded_file) )
675+ let install = ComponentInstall {
676+ status : self . status ,
677+ compression : self . binary . compression ,
678+ installer,
679+ short_name : self . manifest . short_name ( & self . component ) . to_owned ( ) ,
680+ component : self . component ,
681+ temp_dir : self . download_cfg . tmp_cx . new_directory ( ) ?,
682+ io_executor : get_executor (
683+ unpack_ram ( IO_CHUNK_SIZE , self . download_cfg . process . unpack_ram ( ) ?) ,
684+ self . download_cfg . process . io_thread_count ( ) ?,
685+ ) ,
686+ } ;
687+
688+ Ok ( ( install, & self . binary . hash ) )
677689 }
690+ }
678691
679- fn install (
680- self ,
681- installer_file : File ,
682- tx : Transaction ,
683- manifestation : & Manifestation ,
684- ) -> Result < Transaction > {
692+ struct ComponentInstall {
693+ component : Component ,
694+ status : DownloadStatus ,
695+ compression : CompressionKind ,
696+ installer : File ,
697+ short_name : String ,
698+ temp_dir : temp:: Dir ,
699+ io_executor : Box < dyn Executor > ,
700+ }
701+
702+ impl ComponentInstall {
703+ fn install ( self , tx : Transaction , manifestation : Arc < Manifestation > ) -> Result < Transaction > {
685704 // For historical reasons, the rust-installer component
686705 // names are not the same as the dist manifest component
687706 // names. Some are just the component name some are the
688707 // component name plus the target triple.
689708 let pkg_name = self . component . name_in_manifest ( ) ;
690709 let short_pkg_name = self . component . short_name_in_manifest ( ) ;
691- let short_name = self . manifest . short_name ( & self . component ) ;
692-
693- let temp_dir = self . download_cfg . tmp_cx . new_directory ( ) ?;
694- let io_executor = get_executor (
695- unpack_ram ( IO_CHUNK_SIZE , self . download_cfg . process . unpack_ram ( ) ?) ,
696- self . download_cfg . process . io_thread_count ( ) ?,
697- ) ;
698- let reader = self . status . unpack ( utils:: buffered ( & installer_file) ?) ;
699- let package =
700- DirectoryPackage :: compressed ( reader, self . binary . compression , temp_dir, io_executor) ?;
710+ let reader = self . status . unpack ( utils:: buffered ( & self . installer ) ?) ;
711+ let package = DirectoryPackage :: compressed (
712+ reader,
713+ self . compression ,
714+ self . temp_dir ,
715+ self . io_executor ,
716+ ) ?;
701717
702718 // If the package doesn't contain the component that the
703719 // manifest says it does then somebody must be playing a joke on us.
704720 if !package. contains ( & pkg_name, Some ( short_pkg_name) ) {
705- return Err ( RustupError :: CorruptComponent ( short_name . to_owned ( ) ) . into ( ) ) ;
721+ return Err ( RustupError :: CorruptComponent ( self . short_name ) . into ( ) ) ;
706722 }
707723
708724 self . status . installing ( ) ;
0 commit comments