@@ -7,6 +7,7 @@ use std::fmt;
7
7
use std:: io:: { self , ErrorKind as IOErrorKind , Read } ;
8
8
use std:: mem;
9
9
use std:: path:: { Path , PathBuf } ;
10
+ use std:: sync:: Arc ;
10
11
11
12
use anyhow:: { Context , Result , anyhow, bail} ;
12
13
use tar:: EntryType ;
@@ -27,13 +28,13 @@ pub(crate) const VERSION_FILE: &str = "rust-installer-version";
27
28
28
29
pub trait Package : fmt:: Debug {
29
30
fn contains ( & self , component : & str , short_name : Option < & str > ) -> bool ;
30
- fn install < ' a > (
31
+ fn install (
31
32
& self ,
32
33
target : & Components ,
33
34
component : & str ,
34
35
short_name : Option < & str > ,
35
- tx : Transaction < ' a > ,
36
- ) -> Result < Transaction < ' a > > ;
36
+ tx : Transaction ,
37
+ ) -> Result < Transaction > ;
37
38
fn components ( & self ) -> Vec < String > ;
38
39
}
39
40
@@ -80,13 +81,13 @@ impl Package for DirectoryPackage {
80
81
false
81
82
}
82
83
}
83
- fn install < ' a > (
84
+ fn install (
84
85
& self ,
85
86
target : & Components ,
86
87
name : & str ,
87
88
short_name : Option < & str > ,
88
- tx : Transaction < ' a > ,
89
- ) -> Result < Transaction < ' a > > {
89
+ tx : Transaction ,
90
+ ) -> Result < Transaction > {
90
91
let actual_name = if self . components . contains ( name) {
91
92
name
92
93
} else if let Some ( n) = short_name {
@@ -138,11 +139,12 @@ impl Package for DirectoryPackage {
138
139
139
140
#[ derive( Debug ) ]
140
141
#[ allow( dead_code) ] // temp::Dir is held for drop.
141
- pub ( crate ) struct TarPackage < ' a > ( DirectoryPackage , temp:: Dir < ' a > ) ;
142
+ pub ( crate ) struct TarPackage ( DirectoryPackage , temp:: Dir ) ;
142
143
143
- impl < ' a > TarPackage < ' a > {
144
- pub ( crate ) fn new < R : Read > ( stream : R , cx : & PackageContext < ' a > ) -> Result < Self > {
145
- let temp_dir = cx. tmp_cx . new_directory ( ) ?;
144
+ impl TarPackage {
145
+ pub ( crate ) fn new < R : Read > ( stream : R , cx : & PackageContext ) -> Result < Self > {
146
+ let ctx = cx. tmp_cx . clone ( ) ;
147
+ let temp_dir = ctx. new_directory ( ) ?;
146
148
let mut archive = tar:: Archive :: new ( stream) ;
147
149
// The rust-installer packages unpack to a directory called
148
150
// $pkgname-$version-$target. Skip that directory when
@@ -161,7 +163,7 @@ impl<'a> TarPackage<'a> {
161
163
fn unpack_ram (
162
164
io_chunk_size : usize ,
163
165
effective_max_ram : Option < usize > ,
164
- cx : & PackageContext < ' _ > ,
166
+ cx : & PackageContext ,
165
167
) -> usize {
166
168
const RAM_ALLOWANCE_FOR_RUSTUP_AND_BUFFERS : usize = 200 * 1024 * 1024 ;
167
169
let minimum_ram = io_chunk_size * 2 ;
@@ -199,7 +201,7 @@ fn unpack_ram(
199
201
}
200
202
}
201
203
None => {
202
- if let Some ( h) = cx. notify_handler {
204
+ if let Some ( h) = & cx. notify_handler {
203
205
h ( Notification :: SetDefaultBufferSize ( default_max_unpack_ram) )
204
206
}
205
207
default_max_unpack_ram
@@ -285,21 +287,21 @@ enum DirStatus {
285
287
fn unpack_without_first_dir < R : Read > (
286
288
archive : & mut tar:: Archive < R > ,
287
289
path : & Path ,
288
- cx : & PackageContext < ' _ > ,
290
+ cx : & PackageContext ,
289
291
) -> Result < ( ) > {
290
292
let entries = archive. entries ( ) ?;
291
293
let effective_max_ram = match effective_limits:: memory_limit ( ) {
292
294
Ok ( ram) => Some ( ram as usize ) ,
293
295
Err ( e) => {
294
- if let Some ( h) = cx. notify_handler {
296
+ if let Some ( h) = & cx. notify_handler {
295
297
h ( Notification :: Error ( e. to_string ( ) ) )
296
298
}
297
299
None
298
300
}
299
301
} ;
300
302
let unpack_ram = unpack_ram ( IO_CHUNK_SIZE , effective_max_ram, cx) ;
301
- let mut io_executor : Box < dyn Executor > =
302
- get_executor ( cx . notify_handler , unpack_ram, cx. process ) ?;
303
+ let handler_ref = cx . notify_handler . as_ref ( ) . map ( |h| h . as_ref ( ) ) ;
304
+ let mut io_executor : Box < dyn Executor > = get_executor ( handler_ref , unpack_ram, & cx. process ) ?;
303
305
304
306
let mut directories: HashMap < PathBuf , DirStatus > = HashMap :: new ( ) ;
305
307
// Path is presumed to exist. Call it a precondition.
@@ -528,17 +530,17 @@ fn unpack_without_first_dir<R: Read>(
528
530
Ok ( ( ) )
529
531
}
530
532
531
- impl Package for TarPackage < ' _ > {
533
+ impl Package for TarPackage {
532
534
fn contains ( & self , component : & str , short_name : Option < & str > ) -> bool {
533
535
self . 0 . contains ( component, short_name)
534
536
}
535
- fn install < ' b > (
537
+ fn install (
536
538
& self ,
537
539
target : & Components ,
538
540
component : & str ,
539
541
short_name : Option < & str > ,
540
- tx : Transaction < ' b > ,
541
- ) -> Result < Transaction < ' b > > {
542
+ tx : Transaction ,
543
+ ) -> Result < Transaction > {
542
544
self . 0 . install ( target, component, short_name, tx)
543
545
}
544
546
fn components ( & self ) -> Vec < String > {
@@ -547,26 +549,26 @@ impl Package for TarPackage<'_> {
547
549
}
548
550
549
551
#[ derive( Debug ) ]
550
- pub ( crate ) struct TarGzPackage < ' a > ( TarPackage < ' a > ) ;
552
+ pub ( crate ) struct TarGzPackage ( TarPackage ) ;
551
553
552
- impl < ' a > TarGzPackage < ' a > {
553
- pub ( crate ) fn new < R : Read > ( stream : R , cx : & PackageContext < ' a > ) -> Result < Self > {
554
+ impl TarGzPackage {
555
+ pub ( crate ) fn new < R : Read > ( stream : R , cx : & PackageContext ) -> Result < Self > {
554
556
let stream = flate2:: read:: GzDecoder :: new ( stream) ;
555
557
Ok ( TarGzPackage ( TarPackage :: new ( stream, cx) ?) )
556
558
}
557
559
}
558
560
559
- impl Package for TarGzPackage < ' _ > {
561
+ impl Package for TarGzPackage {
560
562
fn contains ( & self , component : & str , short_name : Option < & str > ) -> bool {
561
563
self . 0 . contains ( component, short_name)
562
564
}
563
- fn install < ' b > (
565
+ fn install (
564
566
& self ,
565
567
target : & Components ,
566
568
component : & str ,
567
569
short_name : Option < & str > ,
568
- tx : Transaction < ' b > ,
569
- ) -> Result < Transaction < ' b > > {
570
+ tx : Transaction ,
571
+ ) -> Result < Transaction > {
570
572
self . 0 . install ( target, component, short_name, tx)
571
573
}
572
574
fn components ( & self ) -> Vec < String > {
@@ -575,26 +577,26 @@ impl Package for TarGzPackage<'_> {
575
577
}
576
578
577
579
#[ derive( Debug ) ]
578
- pub ( crate ) struct TarXzPackage < ' a > ( TarPackage < ' a > ) ;
580
+ pub ( crate ) struct TarXzPackage ( TarPackage ) ;
579
581
580
- impl < ' a > TarXzPackage < ' a > {
581
- pub ( crate ) fn new < R : Read > ( stream : R , cx : & PackageContext < ' a > ) -> Result < Self > {
582
+ impl TarXzPackage {
583
+ pub ( crate ) fn new < R : Read > ( stream : R , cx : & PackageContext ) -> Result < Self > {
582
584
let stream = xz2:: read:: XzDecoder :: new ( stream) ;
583
585
Ok ( TarXzPackage ( TarPackage :: new ( stream, cx) ?) )
584
586
}
585
587
}
586
588
587
- impl Package for TarXzPackage < ' _ > {
589
+ impl Package for TarXzPackage {
588
590
fn contains ( & self , component : & str , short_name : Option < & str > ) -> bool {
589
591
self . 0 . contains ( component, short_name)
590
592
}
591
- fn install < ' b > (
593
+ fn install (
592
594
& self ,
593
595
target : & Components ,
594
596
component : & str ,
595
597
short_name : Option < & str > ,
596
- tx : Transaction < ' b > ,
597
- ) -> Result < Transaction < ' b > > {
598
+ tx : Transaction ,
599
+ ) -> Result < Transaction > {
598
600
self . 0 . install ( target, component, short_name, tx)
599
601
}
600
602
fn components ( & self ) -> Vec < String > {
@@ -603,35 +605,35 @@ impl Package for TarXzPackage<'_> {
603
605
}
604
606
605
607
#[ derive( Debug ) ]
606
- pub ( crate ) struct TarZStdPackage < ' a > ( TarPackage < ' a > ) ;
608
+ pub ( crate ) struct TarZStdPackage ( TarPackage ) ;
607
609
608
- impl < ' a > TarZStdPackage < ' a > {
609
- pub ( crate ) fn new < R : Read > ( stream : R , cx : & PackageContext < ' a > ) -> Result < Self > {
610
+ impl TarZStdPackage {
611
+ pub ( crate ) fn new < R : Read > ( stream : R , cx : & PackageContext ) -> Result < Self > {
610
612
let stream = zstd:: stream:: read:: Decoder :: new ( stream) ?;
611
613
Ok ( TarZStdPackage ( TarPackage :: new ( stream, cx) ?) )
612
614
}
613
615
}
614
616
615
- impl Package for TarZStdPackage < ' _ > {
617
+ impl Package for TarZStdPackage {
616
618
fn contains ( & self , component : & str , short_name : Option < & str > ) -> bool {
617
619
self . 0 . contains ( component, short_name)
618
620
}
619
- fn install < ' b > (
621
+ fn install (
620
622
& self ,
621
623
target : & Components ,
622
624
component : & str ,
623
625
short_name : Option < & str > ,
624
- tx : Transaction < ' b > ,
625
- ) -> Result < Transaction < ' b > > {
626
+ tx : Transaction ,
627
+ ) -> Result < Transaction > {
626
628
self . 0 . install ( target, component, short_name, tx)
627
629
}
628
630
fn components ( & self ) -> Vec < String > {
629
631
self . 0 . components ( )
630
632
}
631
633
}
632
634
633
- pub ( crate ) struct PackageContext < ' a > {
634
- pub ( crate ) tmp_cx : & ' a temp:: Context ,
635
- pub ( crate ) notify_handler : Option < & ' a dyn Fn ( Notification < ' _ > ) > ,
636
- pub ( crate ) process : & ' a Process ,
635
+ pub ( crate ) struct PackageContext {
636
+ pub ( crate ) tmp_cx : Arc < temp:: Context > ,
637
+ pub ( crate ) notify_handler : Option < Arc < dyn Fn ( Notification < ' _ > ) > > ,
638
+ pub ( crate ) process : Arc < Process > ,
637
639
}
0 commit comments