@@ -104,9 +104,9 @@ pub async fn unzip<R: tokio::io::AsyncRead + Unpin>(
104
104
/// Unpack the given tar archive into the destination directory.
105
105
///
106
106
/// This is equivalent to `archive.unpack_in(dst)`, but it also preserves the executable bit.
107
- async fn untar_in < R : tokio :: io :: AsyncRead + Unpin , P : AsRef < Path > > (
108
- archive : & mut tokio_tar:: Archive < R > ,
109
- dst : P ,
107
+ async fn untar_in < ' a > (
108
+ mut archive : tokio_tar:: Archive < & ' a mut ( dyn tokio :: io :: AsyncRead + Unpin ) > ,
109
+ dst : & Path ,
110
110
) -> std:: io:: Result < ( ) > {
111
111
let mut entries = archive. entries ( ) ?;
112
112
let mut pinned = Pin :: new ( & mut entries) ;
@@ -124,7 +124,7 @@ async fn untar_in<R: tokio::io::AsyncRead + Unpin, P: AsRef<Path>>(
124
124
continue ;
125
125
}
126
126
127
- file. unpack_in ( dst. as_ref ( ) ) . await ?;
127
+ file. unpack_in ( dst) . await ?;
128
128
129
129
// Preserve the executable bit.
130
130
#[ cfg( unix) ]
@@ -137,7 +137,7 @@ async fn untar_in<R: tokio::io::AsyncRead + Unpin, P: AsRef<Path>>(
137
137
let mode = file. header ( ) . mode ( ) ?;
138
138
let has_any_executable_bit = mode & 0o111 ;
139
139
if has_any_executable_bit != 0 {
140
- if let Some ( path) = crate :: tar:: unpacked_at ( dst. as_ref ( ) , & file. path ( ) ?) {
140
+ if let Some ( path) = crate :: tar:: unpacked_at ( dst, & file. path ( ) ?) {
141
141
let permissions = fs_err:: tokio:: metadata ( & path) . await ?. permissions ( ) ;
142
142
if permissions. mode ( ) & 0o111 != 0o111 {
143
143
fs_err:: tokio:: set_permissions (
@@ -162,13 +162,14 @@ pub async fn untar_gz<R: tokio::io::AsyncRead + Unpin>(
162
162
target : impl AsRef < Path > ,
163
163
) -> Result < ( ) , Error > {
164
164
let reader = tokio:: io:: BufReader :: with_capacity ( DEFAULT_BUF_SIZE , reader) ;
165
- let decompressed_bytes = async_compression:: tokio:: bufread:: GzipDecoder :: new ( reader) ;
166
-
167
- let mut archive = tokio_tar:: ArchiveBuilder :: new ( decompressed_bytes)
168
- . set_preserve_mtime ( false )
169
- . build ( ) ;
170
- untar_in ( & mut archive, target. as_ref ( ) ) . await ?;
171
- Ok ( ( ) )
165
+ let mut decompressed_bytes = async_compression:: tokio:: bufread:: GzipDecoder :: new ( reader) ;
166
+
167
+ let archive = tokio_tar:: ArchiveBuilder :: new (
168
+ & mut decompressed_bytes as & mut ( dyn tokio:: io:: AsyncRead + Unpin ) ,
169
+ )
170
+ . set_preserve_mtime ( false )
171
+ . build ( ) ;
172
+ Ok ( untar_in ( archive, target. as_ref ( ) ) . await ?)
172
173
}
173
174
174
175
/// Unzip a `.tar.bz2` archive into the target directory, without requiring `Seek`.
@@ -179,13 +180,14 @@ pub async fn untar_bz2<R: tokio::io::AsyncRead + Unpin>(
179
180
target : impl AsRef < Path > ,
180
181
) -> Result < ( ) , Error > {
181
182
let reader = tokio:: io:: BufReader :: with_capacity ( DEFAULT_BUF_SIZE , reader) ;
182
- let decompressed_bytes = async_compression:: tokio:: bufread:: BzDecoder :: new ( reader) ;
183
-
184
- let mut archive = tokio_tar:: ArchiveBuilder :: new ( decompressed_bytes)
185
- . set_preserve_mtime ( false )
186
- . build ( ) ;
187
- untar_in ( & mut archive, target. as_ref ( ) ) . await ?;
188
- Ok ( ( ) )
183
+ let mut decompressed_bytes = async_compression:: tokio:: bufread:: BzDecoder :: new ( reader) ;
184
+
185
+ let archive = tokio_tar:: ArchiveBuilder :: new (
186
+ & mut decompressed_bytes as & mut ( dyn tokio:: io:: AsyncRead + Unpin ) ,
187
+ )
188
+ . set_preserve_mtime ( false )
189
+ . build ( ) ;
190
+ Ok ( untar_in ( archive, target. as_ref ( ) ) . await ?)
189
191
}
190
192
191
193
/// Unzip a `.tar.zst` archive into the target directory, without requiring `Seek`.
@@ -196,12 +198,14 @@ pub async fn untar_zst<R: tokio::io::AsyncRead + Unpin>(
196
198
target : impl AsRef < Path > ,
197
199
) -> Result < ( ) , Error > {
198
200
let reader = tokio:: io:: BufReader :: with_capacity ( DEFAULT_BUF_SIZE , reader) ;
199
- let decompressed_bytes = async_compression:: tokio:: bufread:: ZstdDecoder :: new ( reader) ;
200
-
201
- let mut archive = tokio_tar:: ArchiveBuilder :: new ( decompressed_bytes)
202
- . set_preserve_mtime ( false )
203
- . build ( ) ;
204
- Ok ( untar_in ( & mut archive, target. as_ref ( ) ) . await ?)
201
+ let mut decompressed_bytes = async_compression:: tokio:: bufread:: ZstdDecoder :: new ( reader) ;
202
+
203
+ let archive = tokio_tar:: ArchiveBuilder :: new (
204
+ & mut decompressed_bytes as & mut ( dyn tokio:: io:: AsyncRead + Unpin ) ,
205
+ )
206
+ . set_preserve_mtime ( false )
207
+ . build ( ) ;
208
+ Ok ( untar_in ( archive, target. as_ref ( ) ) . await ?)
205
209
}
206
210
207
211
/// Unzip a `.tar.xz` archive into the target directory, without requiring `Seek`.
@@ -212,12 +216,14 @@ pub async fn untar_xz<R: tokio::io::AsyncRead + Unpin>(
212
216
target : impl AsRef < Path > ,
213
217
) -> Result < ( ) , Error > {
214
218
let reader = tokio:: io:: BufReader :: with_capacity ( DEFAULT_BUF_SIZE , reader) ;
215
- let decompressed_bytes = async_compression:: tokio:: bufread:: XzDecoder :: new ( reader) ;
216
-
217
- let mut archive = tokio_tar:: ArchiveBuilder :: new ( decompressed_bytes)
218
- . set_preserve_mtime ( false )
219
- . build ( ) ;
220
- untar_in ( & mut archive, target. as_ref ( ) ) . await ?;
219
+ let mut decompressed_bytes = async_compression:: tokio:: bufread:: XzDecoder :: new ( reader) ;
220
+
221
+ let archive = tokio_tar:: ArchiveBuilder :: new (
222
+ & mut decompressed_bytes as & mut ( dyn tokio:: io:: AsyncRead + Unpin ) ,
223
+ )
224
+ . set_preserve_mtime ( false )
225
+ . build ( ) ;
226
+ untar_in ( archive, target. as_ref ( ) ) . await ?;
221
227
Ok ( ( ) )
222
228
}
223
229
0 commit comments