@@ -140,18 +140,13 @@ impl Package for DirectoryPackage {
140140pub ( crate ) struct TarPackage < ' a > ( DirectoryPackage , temp:: Dir < ' a > ) ;
141141
142142impl < ' a > TarPackage < ' a > {
143- pub ( crate ) fn new < R : Read > (
144- stream : R ,
145- tmp_cx : & ' a temp:: Context ,
146- notify_handler : Option < & ' a dyn Fn ( Notification < ' _ > ) > ,
147- process : & Process ,
148- ) -> Result < Self > {
149- let temp_dir = tmp_cx. new_directory ( ) ?;
143+ pub ( crate ) fn new < R : Read > ( stream : R , cx : & PackageContext < ' a > ) -> Result < Self > {
144+ let temp_dir = cx. tmp_cx . new_directory ( ) ?;
150145 let mut archive = tar:: Archive :: new ( stream) ;
151146 // The rust-installer packages unpack to a directory called
152147 // $pkgname-$version-$target. Skip that directory when
153148 // unpacking.
154- unpack_without_first_dir ( & mut archive, & temp_dir, notify_handler , process )
149+ unpack_without_first_dir ( & mut archive, & temp_dir, cx )
155150 . context ( "failed to extract package" ) ?;
156151
157152 Ok ( TarPackage (
@@ -165,8 +160,7 @@ impl<'a> TarPackage<'a> {
165160fn unpack_ram (
166161 io_chunk_size : usize ,
167162 effective_max_ram : Option < usize > ,
168- notify_handler : Option < & dyn Fn ( Notification < ' _ > ) > ,
169- process : & Process ,
163+ cx : & PackageContext < ' _ > ,
170164) -> usize {
171165 const RAM_ALLOWANCE_FOR_RUSTUP_AND_BUFFERS : usize = 200 * 1024 * 1024 ;
172166 let minimum_ram = io_chunk_size * 2 ;
@@ -180,7 +174,8 @@ fn unpack_ram(
180174 // Rustup does not know how much RAM the machine has: use the minimum
181175 minimum_ram
182176 } ;
183- let unpack_ram = match process
177+ let unpack_ram = match cx
178+ . process
184179 . var ( "RUSTUP_UNPACK_RAM" )
185180 . ok ( )
186181 . and_then ( |budget_str| budget_str. parse :: < usize > ( ) . ok ( ) )
@@ -203,7 +198,7 @@ fn unpack_ram(
203198 }
204199 }
205200 None => {
206- if let Some ( h) = notify_handler {
201+ if let Some ( h) = cx . notify_handler {
207202 h ( Notification :: SetDefaultBufferSize ( default_max_unpack_ram) )
208203 }
209204 default_max_unpack_ram
@@ -289,21 +284,21 @@ enum DirStatus {
289284fn unpack_without_first_dir < R : Read > (
290285 archive : & mut tar:: Archive < R > ,
291286 path : & Path ,
292- notify_handler : Option < & dyn Fn ( Notification < ' _ > ) > ,
293- process : & Process ,
287+ cx : & PackageContext < ' _ > ,
294288) -> Result < ( ) > {
295289 let entries = archive. entries ( ) ?;
296290 let effective_max_ram = match effective_limits:: memory_limit ( ) {
297291 Ok ( ram) => Some ( ram as usize ) ,
298292 Err ( e) => {
299- if let Some ( h) = notify_handler {
293+ if let Some ( h) = cx . notify_handler {
300294 h ( Notification :: Error ( e. to_string ( ) ) )
301295 }
302296 None
303297 }
304298 } ;
305- let unpack_ram = unpack_ram ( IO_CHUNK_SIZE , effective_max_ram, notify_handler, process) ;
306- let mut io_executor: Box < dyn Executor > = get_executor ( notify_handler, unpack_ram, process) ?;
299+ let unpack_ram = unpack_ram ( IO_CHUNK_SIZE , effective_max_ram, cx) ;
300+ let mut io_executor: Box < dyn Executor > =
301+ get_executor ( cx. notify_handler , unpack_ram, cx. process ) ?;
307302
308303 let mut directories: HashMap < PathBuf , DirStatus > = HashMap :: new ( ) ;
309304 // Path is presumed to exist. Call it a precondition.
@@ -463,7 +458,7 @@ fn unpack_without_first_dir<R: Read>(
463458 // Tar has item before containing directory
464459 // Complain about this so we can see if these exist.
465460 writeln ! (
466- process. stderr( ) . lock( ) ,
461+ cx . process. stderr( ) . lock( ) ,
467462 "Unexpected: missing parent '{}' for '{}'" ,
468463 parent. display( ) ,
469464 entry. path( ) ?. display( )
@@ -554,19 +549,9 @@ impl Package for TarPackage<'_> {
554549pub ( crate ) struct TarGzPackage < ' a > ( TarPackage < ' a > ) ;
555550
556551impl < ' a > TarGzPackage < ' a > {
557- pub ( crate ) fn new < R : Read > (
558- stream : R ,
559- tmp_cx : & ' a temp:: Context ,
560- notify_handler : Option < & ' a dyn Fn ( Notification < ' _ > ) > ,
561- process : & Process ,
562- ) -> Result < Self > {
552+ pub ( crate ) fn new < R : Read > ( stream : R , cx : & PackageContext < ' a > ) -> Result < Self > {
563553 let stream = flate2:: read:: GzDecoder :: new ( stream) ;
564- Ok ( TarGzPackage ( TarPackage :: new (
565- stream,
566- tmp_cx,
567- notify_handler,
568- process,
569- ) ?) )
554+ Ok ( TarGzPackage ( TarPackage :: new ( stream, cx) ?) )
570555 }
571556}
572557
@@ -592,19 +577,9 @@ impl Package for TarGzPackage<'_> {
592577pub ( crate ) struct TarXzPackage < ' a > ( TarPackage < ' a > ) ;
593578
594579impl < ' a > TarXzPackage < ' a > {
595- pub ( crate ) fn new < R : Read > (
596- stream : R ,
597- tmp_cx : & ' a temp:: Context ,
598- notify_handler : Option < & ' a dyn Fn ( Notification < ' _ > ) > ,
599- process : & Process ,
600- ) -> Result < Self > {
580+ pub ( crate ) fn new < R : Read > ( stream : R , cx : & PackageContext < ' a > ) -> Result < Self > {
601581 let stream = xz2:: read:: XzDecoder :: new ( stream) ;
602- Ok ( TarXzPackage ( TarPackage :: new (
603- stream,
604- tmp_cx,
605- notify_handler,
606- process,
607- ) ?) )
582+ Ok ( TarXzPackage ( TarPackage :: new ( stream, cx) ?) )
608583 }
609584}
610585
@@ -630,19 +605,9 @@ impl Package for TarXzPackage<'_> {
630605pub ( crate ) struct TarZStdPackage < ' a > ( TarPackage < ' a > ) ;
631606
632607impl < ' a > TarZStdPackage < ' a > {
633- pub ( crate ) fn new < R : Read > (
634- stream : R ,
635- tmp_cx : & ' a temp:: Context ,
636- notify_handler : Option < & ' a dyn Fn ( Notification < ' _ > ) > ,
637- process : & Process ,
638- ) -> Result < Self > {
608+ pub ( crate ) fn new < R : Read > ( stream : R , cx : & PackageContext < ' a > ) -> Result < Self > {
639609 let stream = zstd:: stream:: read:: Decoder :: new ( stream) ?;
640- Ok ( TarZStdPackage ( TarPackage :: new (
641- stream,
642- tmp_cx,
643- notify_handler,
644- process,
645- ) ?) )
610+ Ok ( TarZStdPackage ( TarPackage :: new ( stream, cx) ?) )
646611 }
647612}
648613
@@ -663,3 +628,9 @@ impl Package for TarZStdPackage<'_> {
663628 self . 0 . components ( )
664629 }
665630}
631+
632+ pub ( crate ) struct PackageContext < ' a > {
633+ pub ( crate ) tmp_cx : & ' a temp:: Context ,
634+ pub ( crate ) notify_handler : Option < & ' a dyn Fn ( Notification < ' _ > ) > ,
635+ pub ( crate ) process : & ' a Process ,
636+ }
0 commit comments