diff --git a/src/helpers.rs b/src/helpers.rs index b0451295..6d84bb3c 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -1,22 +1,16 @@ use std::{ borrow::Cow, - fs, io::{stderr, stdin, Write}, path::{Path, PathBuf}, }; use cargo_toml::Manifest; -use flate2::read::GzDecoder; use futures_util::stream::StreamExt; use log::{debug, info}; use reqwest::Method; use serde::Serialize; -use tar::Archive; use tinytemplate::TinyTemplate; use url::Url; -use xz2::read::XzDecoder; -use zip::read::ZipArchive; -use zstd::stream::Decoder as ZstdDecoder; use crate::{BinstallError, Meta, PkgFmt}; @@ -90,79 +84,6 @@ pub async fn download_and_extract, const N: usize>( Ok(()) } -/// Extract files from the specified source onto the specified path -pub fn extract, P: AsRef>( - source: S, - fmt: PkgFmt, - path: P, -) -> Result<(), BinstallError> { - let source = source.as_ref(); - let path = path.as_ref(); - - match fmt { - PkgFmt::Tar => { - // Extract to install dir - debug!("Extracting from tar archive '{source:?}' to `{path:?}`"); - - let dat = fs::File::open(source)?; - let mut tar = Archive::new(dat); - - tar.unpack(path)?; - } - PkgFmt::Tgz => { - // Extract to install dir - debug!("Decompressing from tgz archive '{source:?}' to `{path:?}`"); - - let dat = fs::File::open(source)?; - let tar = GzDecoder::new(dat); - let mut tgz = Archive::new(tar); - - tgz.unpack(path)?; - } - PkgFmt::Txz => { - // Extract to install dir - debug!("Decompressing from txz archive '{source:?}' to `{path:?}`"); - - let dat = fs::File::open(source)?; - let tar = XzDecoder::new(dat); - let mut txz = Archive::new(tar); - - txz.unpack(path)?; - } - PkgFmt::Tzstd => { - // Extract to install dir - debug!("Decompressing from tzstd archive '{source:?}' to `{path:?}`"); - - let dat = std::fs::File::open(source)?; - - // The error can only come from raw::Decoder::with_dictionary - // as of zstd 0.10.2 and 0.11.2, which is specified - // as &[] by ZstdDecoder::new, thus ZstdDecoder::new - // should not return any error. - let tar = ZstdDecoder::new(dat)?; - let mut txz = Archive::new(tar); - - txz.unpack(path)?; - } - PkgFmt::Zip => { - // Extract to install dir - debug!("Decompressing from zip archive '{source:?}' to `{path:?}`"); - - let dat = fs::File::open(source)?; - let mut zip = ZipArchive::new(dat)?; - - zip.extract(path)?; - } - PkgFmt::Bin => { - debug!("Copying binary '{source:?}' to `{path:?}`"); - // Copy to install dir - fs::copy(source, path)?; - } - }; - - Ok(()) -} - /// Fetch install path from environment /// roughly follows pub fn get_install_path>(install_path: Option

) -> Option {