mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-20 20:48:43 +00:00
Rm helpers::extract
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
728d1fd6dd
commit
5ba8b07bcb
1 changed files with 0 additions and 79 deletions
|
@ -1,22 +1,16 @@
|
||||||
use std::{
|
use std::{
|
||||||
borrow::Cow,
|
borrow::Cow,
|
||||||
fs,
|
|
||||||
io::{stderr, stdin, Write},
|
io::{stderr, stdin, Write},
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
};
|
};
|
||||||
|
|
||||||
use cargo_toml::Manifest;
|
use cargo_toml::Manifest;
|
||||||
use flate2::read::GzDecoder;
|
|
||||||
use futures_util::stream::StreamExt;
|
use futures_util::stream::StreamExt;
|
||||||
use log::{debug, info};
|
use log::{debug, info};
|
||||||
use reqwest::Method;
|
use reqwest::Method;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use tar::Archive;
|
|
||||||
use tinytemplate::TinyTemplate;
|
use tinytemplate::TinyTemplate;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
use xz2::read::XzDecoder;
|
|
||||||
use zip::read::ZipArchive;
|
|
||||||
use zstd::stream::Decoder as ZstdDecoder;
|
|
||||||
|
|
||||||
use crate::{BinstallError, Meta, PkgFmt};
|
use crate::{BinstallError, Meta, PkgFmt};
|
||||||
|
|
||||||
|
@ -90,79 +84,6 @@ pub async fn download_and_extract<P: AsRef<Path>, const N: usize>(
|
||||||
Ok(())
|
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
|
/// Fetch install path from environment
|
||||||
/// roughly follows <https://doc.rust-lang.org/cargo/commands/cargo-install.html#description>
|
/// 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> {
|
pub fn get_install_path<P: AsRef<Path>>(install_path: Option<P>) -> Option<PathBuf> {
|
||||||
|
|
Loading…
Add table
Reference in a new issue