From 5ba8b07bcba69cbb7285f4969cdb070872b9da3e Mon Sep 17 00:00:00 2001 From: Jiahao XU <Jiahao_XU@outlook.com> Date: Thu, 9 Jun 2022 14:52:14 +1000 Subject: [PATCH] Rm `helpers::extract` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> --- src/helpers.rs | 79 -------------------------------------------------- 1 file changed, 79 deletions(-) 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<P: AsRef<Path>, const N: usize>( Ok(()) } -/// Extract files from the specified source onto the specified path -pub fn extract<S: AsRef<Path>, P: AsRef<Path>>( - 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 <https://doc.rust-lang.org/cargo/commands/cargo-install.html#description> pub fn get_install_path<P: AsRef<Path>>(install_path: Option<P>) -> Option<PathBuf> {