@@ -140,18 +140,13 @@ impl Package for DirectoryPackage {
140
140
pub ( crate ) struct TarPackage < ' a > ( DirectoryPackage , temp:: Dir < ' a > ) ;
141
141
142
142
impl < ' 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 ( ) ?;
150
145
let mut archive = tar:: Archive :: new ( stream) ;
151
146
// The rust-installer packages unpack to a directory called
152
147
// $pkgname-$version-$target. Skip that directory when
153
148
// unpacking.
154
- unpack_without_first_dir ( & mut archive, & temp_dir, notify_handler , process )
149
+ unpack_without_first_dir ( & mut archive, & temp_dir, cx )
155
150
. context ( "failed to extract package" ) ?;
156
151
157
152
Ok ( TarPackage (
@@ -165,8 +160,7 @@ impl<'a> TarPackage<'a> {
165
160
fn unpack_ram (
166
161
io_chunk_size : usize ,
167
162
effective_max_ram : Option < usize > ,
168
- notify_handler : Option < & dyn Fn ( Notification < ' _ > ) > ,
169
- process : & Process ,
163
+ cx : & PackageContext < ' _ > ,
170
164
) -> usize {
171
165
const RAM_ALLOWANCE_FOR_RUSTUP_AND_BUFFERS : usize = 200 * 1024 * 1024 ;
172
166
let minimum_ram = io_chunk_size * 2 ;
@@ -180,7 +174,8 @@ fn unpack_ram(
180
174
// Rustup does not know how much RAM the machine has: use the minimum
181
175
minimum_ram
182
176
} ;
183
- let unpack_ram = match process
177
+ let unpack_ram = match cx
178
+ . process
184
179
. var ( "RUSTUP_UNPACK_RAM" )
185
180
. ok ( )
186
181
. and_then ( |budget_str| budget_str. parse :: < usize > ( ) . ok ( ) )
@@ -203,7 +198,7 @@ fn unpack_ram(
203
198
}
204
199
}
205
200
None => {
206
- if let Some ( h) = notify_handler {
201
+ if let Some ( h) = cx . notify_handler {
207
202
h ( Notification :: SetDefaultBufferSize ( default_max_unpack_ram) )
208
203
}
209
204
default_max_unpack_ram
@@ -289,21 +284,21 @@ enum DirStatus {
289
284
fn unpack_without_first_dir < R : Read > (
290
285
archive : & mut tar:: Archive < R > ,
291
286
path : & Path ,
292
- notify_handler : Option < & dyn Fn ( Notification < ' _ > ) > ,
293
- process : & Process ,
287
+ cx : & PackageContext < ' _ > ,
294
288
) -> Result < ( ) > {
295
289
let entries = archive. entries ( ) ?;
296
290
let effective_max_ram = match effective_limits:: memory_limit ( ) {
297
291
Ok ( ram) => Some ( ram as usize ) ,
298
292
Err ( e) => {
299
- if let Some ( h) = notify_handler {
293
+ if let Some ( h) = cx . notify_handler {
300
294
h ( Notification :: Error ( e. to_string ( ) ) )
301
295
}
302
296
None
303
297
}
304
298
} ;
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 ) ?;
307
302
308
303
let mut directories: HashMap < PathBuf , DirStatus > = HashMap :: new ( ) ;
309
304
// Path is presumed to exist. Call it a precondition.
@@ -463,7 +458,7 @@ fn unpack_without_first_dir<R: Read>(
463
458
// Tar has item before containing directory
464
459
// Complain about this so we can see if these exist.
465
460
writeln ! (
466
- process. stderr( ) . lock( ) ,
461
+ cx . process. stderr( ) . lock( ) ,
467
462
"Unexpected: missing parent '{}' for '{}'" ,
468
463
parent. display( ) ,
469
464
entry. path( ) ?. display( )
@@ -554,19 +549,9 @@ impl Package for TarPackage<'_> {
554
549
pub ( crate ) struct TarGzPackage < ' a > ( TarPackage < ' a > ) ;
555
550
556
551
impl < ' 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 > {
563
553
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) ?) )
570
555
}
571
556
}
572
557
@@ -592,19 +577,9 @@ impl Package for TarGzPackage<'_> {
592
577
pub ( crate ) struct TarXzPackage < ' a > ( TarPackage < ' a > ) ;
593
578
594
579
impl < ' 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 > {
601
581
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) ?) )
608
583
}
609
584
}
610
585
@@ -630,19 +605,9 @@ impl Package for TarXzPackage<'_> {
630
605
pub ( crate ) struct TarZStdPackage < ' a > ( TarPackage < ' a > ) ;
631
606
632
607
impl < ' 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 > {
639
609
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) ?) )
646
611
}
647
612
}
648
613
@@ -663,3 +628,9 @@ impl Package for TarZStdPackage<'_> {
663
628
self . 0 . components ( )
664
629
}
665
630
}
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