mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-22 13:38:43 +00:00
Impl new fn helpers::extracter::untar
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
cc13a23b07
commit
be5e8616a2
1 changed files with 26 additions and 0 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
use std::borrow::Cow;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
@ -11,6 +12,31 @@ use zstd::stream::Decoder as ZstdDecoder;
|
||||||
|
|
||||||
use crate::{BinstallError, PkgFmt};
|
use crate::{BinstallError, PkgFmt};
|
||||||
|
|
||||||
|
fn untar(
|
||||||
|
dat: impl Read,
|
||||||
|
path: &Path,
|
||||||
|
desired_outputs: Option<&[Cow<'_, Path>]>,
|
||||||
|
) -> Result<(), BinstallError> {
|
||||||
|
let mut tar = Archive::new(dat);
|
||||||
|
|
||||||
|
if let Some(desired_outputs) = desired_outputs {
|
||||||
|
for res in tar.entries()? {
|
||||||
|
let mut entry = res?;
|
||||||
|
let entry_path = entry.path()?;
|
||||||
|
|
||||||
|
if desired_outputs.contains(&entry_path) {
|
||||||
|
let dst = path.join(entry_path);
|
||||||
|
|
||||||
|
entry.unpack(dst)?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
tar.unpack(path)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
/// Extract files from the specified source onto the specified path.
|
/// Extract files from the specified source onto the specified path.
|
||||||
///
|
///
|
||||||
/// * `fmt` - must not be `PkgFmt::Bin` or `PkgFmt::Zip`.
|
/// * `fmt` - must not be `PkgFmt::Bin` or `PkgFmt::Zip`.
|
||||||
|
|
Loading…
Add table
Reference in a new issue