mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-05-06 04:00:02 +00:00
Add support for Txz archives
This commit is contained in:
parent
e5705171a7
commit
9c06ca94cb
5 changed files with 43 additions and 7 deletions
|
@ -6,6 +6,7 @@ use log::{debug, info, error};
|
|||
use cargo_toml::{Manifest};
|
||||
use flate2::read::GzDecoder;
|
||||
use tar::Archive;
|
||||
use xz2::read::XzDecoder;
|
||||
|
||||
|
||||
use crate::{Meta};
|
||||
|
@ -66,6 +67,16 @@ pub fn extract<S: AsRef<Path>, P: AsRef<Path>>(source: S, fmt: PkgFmt, path: P)
|
|||
|
||||
tgz.unpack(path)?;
|
||||
},
|
||||
PkgFmt::Txz => {
|
||||
// Extract to install dir
|
||||
debug!("Decompressing from archive '{:?}' to `{:?}`", source.as_ref(), path.as_ref());
|
||||
|
||||
let dat = std::fs::File::open(source)?;
|
||||
let tar = XzDecoder::new(dat);
|
||||
let mut txz = Archive::new(tar);
|
||||
|
||||
txz.unpack(path)?;
|
||||
},
|
||||
PkgFmt::Bin => {
|
||||
debug!("Copying data from archive '{:?}' to `{:?}`", source.as_ref(), path.as_ref());
|
||||
// Copy to install dir
|
||||
|
@ -117,10 +128,10 @@ pub fn get_install_path<P: AsRef<Path>>(install_path: Option<P>) -> Option<PathB
|
|||
|
||||
pub fn confirm() -> Result<bool, anyhow::Error> {
|
||||
info!("Do you wish to continue? yes/no");
|
||||
|
||||
|
||||
let mut input = String::new();
|
||||
std::io::stdin().read_line(&mut input)?;
|
||||
|
||||
|
||||
match input.as_str().trim() {
|
||||
"yes" => Ok(true),
|
||||
"no" => Ok(false),
|
||||
|
|
|
@ -30,6 +30,8 @@ pub enum PkgFmt {
|
|||
Tar,
|
||||
/// Download format is TGZ (TAR + GZip)
|
||||
Tgz,
|
||||
/// Download format is TAR + XZ
|
||||
Txz,
|
||||
/// Download format is raw / binary
|
||||
Bin,
|
||||
}
|
||||
|
@ -50,7 +52,7 @@ pub struct Meta {
|
|||
}
|
||||
|
||||
/// Metadata for binary installation use.
|
||||
///
|
||||
///
|
||||
/// Exposed via `[package.metadata]` in `Cargo.toml`
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "kebab-case", default)]
|
||||
|
@ -146,7 +148,7 @@ mod test {
|
|||
assert_eq!(
|
||||
manifest.bin.as_slice(),
|
||||
&[
|
||||
Product{
|
||||
Product{
|
||||
name: Some("cargo-binstall".to_string()),
|
||||
path: Some("src/main.rs".to_string()),
|
||||
edition: Some(cargo_toml::Edition::E2018),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue