@@ -34,6 +34,34 @@ pub struct DirectoryPackage<P> {
3434 copy : bool ,
3535}
3636
37+ impl DirectoryPackage < temp:: Dir > {
38+ pub ( crate ) fn compressed < R : Read > (
39+ stream : R ,
40+ kind : CompressionKind ,
41+ dl_cfg : & DownloadCfg < ' _ > ,
42+ ) -> Result < Self > {
43+ match kind {
44+ CompressionKind :: GZip => Self :: from_tar ( flate2:: read:: GzDecoder :: new ( stream) , dl_cfg) ,
45+ CompressionKind :: ZStd => {
46+ Self :: from_tar ( zstd:: stream:: read:: Decoder :: new ( stream) ?, dl_cfg)
47+ }
48+ CompressionKind :: XZ => Self :: from_tar ( xz2:: read:: XzDecoder :: new ( stream) , dl_cfg) ,
49+ }
50+ }
51+
52+ fn from_tar ( stream : impl Read , dl_cfg : & DownloadCfg < ' _ > ) -> Result < Self > {
53+ let temp_dir = dl_cfg. tmp_cx . new_directory ( ) ?;
54+ let mut archive = tar:: Archive :: new ( stream) ;
55+ // The rust-installer packages unpack to a directory called
56+ // $pkgname-$version-$target. Skip that directory when
57+ // unpacking.
58+ unpack_without_first_dir ( & mut archive, & temp_dir, dl_cfg)
59+ . context ( "failed to extract package" ) ?;
60+
61+ Self :: new ( temp_dir, false )
62+ }
63+ }
64+
3765impl < P : Deref < Target = Path > > DirectoryPackage < P > {
3866 pub fn new ( path : P , copy : bool ) -> Result < Self > {
3967 let file = utils:: read_file ( "installer version" , & path. join ( VERSION_FILE ) ) ?;
@@ -116,43 +144,6 @@ impl<P: Deref<Target = Path>> DirectoryPackage<P> {
116144 }
117145}
118146
119- #[ derive( Debug ) ]
120- pub ( crate ) struct TarPackage ( DirectoryPackage < temp:: Dir > ) ;
121-
122- impl TarPackage {
123- pub ( crate ) fn compressed < R : Read > (
124- stream : R ,
125- kind : CompressionKind ,
126- dl_cfg : & DownloadCfg < ' _ > ,
127- ) -> Result < Self > {
128- match kind {
129- CompressionKind :: GZip => Self :: new ( flate2:: read:: GzDecoder :: new ( stream) , dl_cfg) ,
130- CompressionKind :: ZStd => Self :: new ( zstd:: stream:: read:: Decoder :: new ( stream) ?, dl_cfg) ,
131- CompressionKind :: XZ => Self :: new ( xz2:: read:: XzDecoder :: new ( stream) , dl_cfg) ,
132- }
133- }
134-
135- fn new < R : Read > ( stream : R , dl_cfg : & DownloadCfg < ' _ > ) -> Result < Self > {
136- let temp_dir = dl_cfg. tmp_cx . new_directory ( ) ?;
137- let mut archive = tar:: Archive :: new ( stream) ;
138- // The rust-installer packages unpack to a directory called
139- // $pkgname-$version-$target. Skip that directory when
140- // unpacking.
141- unpack_without_first_dir ( & mut archive, & temp_dir, dl_cfg)
142- . context ( "failed to extract package" ) ?;
143-
144- Ok ( TarPackage ( DirectoryPackage :: new ( temp_dir, false ) ?) )
145- }
146- }
147-
148- impl Deref for TarPackage {
149- type Target = DirectoryPackage < temp:: Dir > ;
150-
151- fn deref ( & self ) -> & Self :: Target {
152- & self . 0
153- }
154- }
155-
156147// Probably this should live in diskio but ¯\_(ツ)_/¯
157148fn unpack_ram (
158149 io_chunk_size : usize ,
0 commit comments