mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-23 05:58:42 +00:00
Merge pull request #154 from passcod/ed-2021
This commit is contained in:
commit
bd6aec9abb
6 changed files with 43 additions and 85 deletions
42
Cargo.lock
generated
42
Cargo.lock
generated
|
@ -91,9 +91,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bumpalo"
|
name = "bumpalo"
|
||||||
version = "3.9.1"
|
version = "3.10.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a4a45a46ab1f2412e53d3a0ade76ffad2025804294569aae387231a0cd6e0899"
|
checksum = "37ccbd214614c6783386c1af30caf03192f17891059cecc394b4fb119e363de3"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "byteorder"
|
name = "byteorder"
|
||||||
|
@ -624,9 +624,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "http"
|
name = "http"
|
||||||
version = "0.2.7"
|
version = "0.2.8"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ff8670570af52249509a86f5e3e18a08c60b177071826898fde8997cf5f6bfbb"
|
checksum = "75f43d41e26995c17e71ee126451dd3941010b0514a81a9d11f3b341debc2399"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bytes",
|
"bytes",
|
||||||
"fnv",
|
"fnv",
|
||||||
|
@ -814,9 +814,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lzma-sys"
|
name = "lzma-sys"
|
||||||
version = "0.1.17"
|
version = "0.1.19"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "bdb4b7c3eddad11d3af9e86c487607d2d2442d185d848575365c4856ba96d619"
|
checksum = "e06754c4acf47d49c727d5665ca9fb828851cda315ed3bd51edd148ef78a8772"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cc",
|
"cc",
|
||||||
"libc",
|
"libc",
|
||||||
|
@ -1489,9 +1489,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tokio"
|
name = "tokio"
|
||||||
version = "1.19.1"
|
version = "1.19.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "95eec79ea28c00a365f539f1961e9278fbcaf81c0ff6aaf0e93c181352446948"
|
checksum = "c51a52ed6686dd62c320f9b89299e9dfb46f730c7a48e635c19f21d116cb1439"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bytes",
|
"bytes",
|
||||||
"libc",
|
"libc",
|
||||||
|
@ -1518,9 +1518,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tokio-util"
|
name = "tokio-util"
|
||||||
version = "0.7.2"
|
version = "0.7.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f988a1a1adc2fb21f9c12aa96441da33a1728193ae0b95d2be22dbd17fcb4e5c"
|
checksum = "cc463cd8deddc3770d20f9852143d50bf6094e640b485cb2e189a2099085ff45"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bytes",
|
"bytes",
|
||||||
"futures-core",
|
"futures-core",
|
||||||
|
@ -1553,28 +1553,16 @@ checksum = "5d0ecdcb44a79f0fe9844f0c4f33a342cbcbb5117de8001e6ba0dc2351327d09"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"pin-project-lite",
|
"pin-project-lite",
|
||||||
"tracing-attributes",
|
|
||||||
"tracing-core",
|
"tracing-core",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "tracing-attributes"
|
|
||||||
version = "0.1.21"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "cc6b8ad3567499f98a1db7a752b07a7c8c7c7c34c332ec00effb2b0027974b7c"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tracing-core"
|
name = "tracing-core"
|
||||||
version = "0.1.26"
|
version = "0.1.27"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f54c8ca710e81886d498c2fd3331b56c93aa248d49de2222ad2742247c60072f"
|
checksum = "7709595b8878a4965ce5e87ebf880a7d39c9afc6837721b21a5a816a8117d921"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"lazy_static",
|
"once_cell",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -1871,9 +1859,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "xz2"
|
name = "xz2"
|
||||||
version = "0.1.6"
|
version = "0.1.7"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c179869f34fc7c01830d3ce7ea2086bc3a07e0d35289b667d0a8bf910258926c"
|
checksum = "388c44dc09d76f1536602ead6d325eb532f5c122f17782bd57fb47baeeb767e2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"lzma-sys",
|
"lzma-sys",
|
||||||
]
|
]
|
||||||
|
|
10
Cargo.toml
10
Cargo.toml
|
@ -4,11 +4,11 @@ description = "Rust binary package installer for CI integration"
|
||||||
repository = "https://github.com/ryankurte/cargo-binstall"
|
repository = "https://github.com/ryankurte/cargo-binstall"
|
||||||
documentation = "https://docs.rs/cargo-binstall"
|
documentation = "https://docs.rs/cargo-binstall"
|
||||||
version = "0.8.0"
|
version = "0.8.0"
|
||||||
|
rust-version = "1.61.0"
|
||||||
authors = ["ryan <ryan@kurte.nz>"]
|
authors = ["ryan <ryan@kurte.nz>"]
|
||||||
edition = "2018"
|
edition = "2021"
|
||||||
license = "GPL-3.0"
|
license = "GPL-3.0"
|
||||||
|
|
||||||
|
|
||||||
[package.metadata.binstall]
|
[package.metadata.binstall]
|
||||||
pkg-url = "{ repo }/releases/download/v{ version }/{ name }-{ target }.{ format }"
|
pkg-url = "{ repo }/releases/download/v{ version }/{ name }-{ target }.{ format }"
|
||||||
bin-dir = "{ bin }{ format }"
|
bin-dir = "{ bin }{ format }"
|
||||||
|
@ -38,16 +38,12 @@ tar = "0.4.38"
|
||||||
tempfile = "3.3.0"
|
tempfile = "3.3.0"
|
||||||
thiserror = "1.0.31"
|
thiserror = "1.0.31"
|
||||||
tinytemplate = "1.2.1"
|
tinytemplate = "1.2.1"
|
||||||
|
|
||||||
# This crate uses features rt-multi-thread and macros in `#[tokio::main]` and
|
|
||||||
# uses feature process to create process.
|
|
||||||
tokio = { version = "1.19.1", features = [ "rt-multi-thread", "process" ], default-features = false }
|
tokio = { version = "1.19.1", features = [ "rt-multi-thread", "process" ], default-features = false }
|
||||||
|
|
||||||
url = "2.2.2"
|
url = "2.2.2"
|
||||||
xz2 = "0.1.6"
|
xz2 = "0.1.6"
|
||||||
|
|
||||||
# Disable all features of zip except for features of compression algorithms:
|
# Disable all features of zip except for features of compression algorithms:
|
||||||
# Disable features include:
|
# Disabled features include:
|
||||||
# - aes-crypto: Enables decryption of files which were encrypted with AES, absolutely zero use for
|
# - aes-crypto: Enables decryption of files which were encrypted with AES, absolutely zero use for
|
||||||
# this crate.
|
# this crate.
|
||||||
# - time: Enables features using the [time](https://github.com/time-rs/time) crate,
|
# - time: Enables features using the [time](https://github.com/time-rs/time) crate,
|
||||||
|
|
|
@ -98,9 +98,9 @@ pub async fn fetch_crate_cratesio(
|
||||||
|
|
||||||
// Download crate to temporary dir (crates.io or git?)
|
// Download crate to temporary dir (crates.io or git?)
|
||||||
let crate_url = format!("https://crates.io/{}", version.dl_path);
|
let crate_url = format!("https://crates.io/{}", version.dl_path);
|
||||||
let tgz_path = temp_dir.join(format!("{}.tgz", name));
|
let tgz_path = temp_dir.join(format!("{name}.tgz"));
|
||||||
|
|
||||||
debug!("Fetching crate from: {}", crate_url);
|
debug!("Fetching crate from: {crate_url}");
|
||||||
|
|
||||||
// Download crate
|
// Download crate
|
||||||
download(&crate_url, &tgz_path).await?;
|
download(&crate_url, &tgz_path).await?;
|
||||||
|
@ -108,7 +108,7 @@ pub async fn fetch_crate_cratesio(
|
||||||
// Decompress downloaded tgz
|
// Decompress downloaded tgz
|
||||||
debug!("Decompressing crate archive");
|
debug!("Decompressing crate archive");
|
||||||
extract(&tgz_path, PkgFmt::Tgz, &temp_dir)?;
|
extract(&tgz_path, PkgFmt::Tgz, &temp_dir)?;
|
||||||
let crate_path = temp_dir.join(format!("{}-{}", name, version_name));
|
let crate_path = temp_dir.join(format!("{name}-{version_name}"));
|
||||||
|
|
||||||
// Return crate directory
|
// Return crate directory
|
||||||
Ok(crate_path)
|
Ok(crate_path)
|
||||||
|
|
|
@ -62,17 +62,13 @@ impl MultiFetcher {
|
||||||
.fetchers
|
.fetchers
|
||||||
.iter()
|
.iter()
|
||||||
.cloned()
|
.cloned()
|
||||||
.map(|fetcher| {
|
.map(|fetcher| (
|
||||||
let fetcher_cloned = fetcher.clone();
|
fetcher.clone(),
|
||||||
|
|
||||||
(
|
|
||||||
AutoAbortJoinHandle(tokio::spawn(async move { fetcher.check().await })),
|
AutoAbortJoinHandle(tokio::spawn(async move { fetcher.check().await })),
|
||||||
fetcher_cloned,
|
))
|
||||||
)
|
|
||||||
})
|
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
for (mut handle, fetcher) in handles {
|
for (fetcher, mut handle) in handles {
|
||||||
match (&mut handle.0).await {
|
match (&mut handle.0).await {
|
||||||
Ok(Ok(true)) => return Some(fetcher),
|
Ok(Ok(true)) => return Some(fetcher),
|
||||||
Ok(Ok(false)) => (),
|
Ok(Ok(false)) => (),
|
||||||
|
|
|
@ -4,10 +4,9 @@ use std::{
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
};
|
};
|
||||||
|
|
||||||
use log::{debug, info};
|
|
||||||
|
|
||||||
use cargo_toml::Manifest;
|
use cargo_toml::Manifest;
|
||||||
use flate2::read::GzDecoder;
|
use flate2::read::GzDecoder;
|
||||||
|
use log::{debug, info};
|
||||||
use reqwest::Method;
|
use reqwest::Method;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use tar::Archive;
|
use tar::Archive;
|
||||||
|
@ -44,7 +43,7 @@ pub async fn remote_exists(url: Url, method: Method) -> Result<bool, BinstallErr
|
||||||
/// Download a file from the provided URL to the provided path
|
/// Download a file from the provided URL to the provided path
|
||||||
pub async fn download<P: AsRef<Path>>(url: &str, path: P) -> Result<(), BinstallError> {
|
pub async fn download<P: AsRef<Path>>(url: &str, path: P) -> Result<(), BinstallError> {
|
||||||
let url = Url::parse(url)?;
|
let url = Url::parse(url)?;
|
||||||
debug!("Downloading from: '{}'", url);
|
debug!("Downloading from: '{url}'");
|
||||||
|
|
||||||
let resp = reqwest::get(url.clone())
|
let resp = reqwest::get(url.clone())
|
||||||
.await
|
.await
|
||||||
|
@ -72,14 +71,13 @@ pub fn extract<S: AsRef<Path>, P: AsRef<Path>>(
|
||||||
fmt: PkgFmt,
|
fmt: PkgFmt,
|
||||||
path: P,
|
path: P,
|
||||||
) -> Result<(), BinstallError> {
|
) -> Result<(), BinstallError> {
|
||||||
|
let source = source.as_ref();
|
||||||
|
let path = path.as_ref();
|
||||||
|
|
||||||
match fmt {
|
match fmt {
|
||||||
PkgFmt::Tar => {
|
PkgFmt::Tar => {
|
||||||
// Extract to install dir
|
// Extract to install dir
|
||||||
debug!(
|
debug!("Extracting from tar archive '{source:?}' to `{path:?}`");
|
||||||
"Extracting from tar archive '{:?}' to `{:?}`",
|
|
||||||
source.as_ref(),
|
|
||||||
path.as_ref()
|
|
||||||
);
|
|
||||||
|
|
||||||
let dat = fs::File::open(source)?;
|
let dat = fs::File::open(source)?;
|
||||||
let mut tar = Archive::new(dat);
|
let mut tar = Archive::new(dat);
|
||||||
|
@ -88,11 +86,7 @@ pub fn extract<S: AsRef<Path>, P: AsRef<Path>>(
|
||||||
}
|
}
|
||||||
PkgFmt::Tgz => {
|
PkgFmt::Tgz => {
|
||||||
// Extract to install dir
|
// Extract to install dir
|
||||||
debug!(
|
debug!("Decompressing from tgz archive '{source:?}' to `{path:?}`");
|
||||||
"Decompressing from tgz archive '{:?}' to `{:?}`",
|
|
||||||
source.as_ref(),
|
|
||||||
path.as_ref()
|
|
||||||
);
|
|
||||||
|
|
||||||
let dat = fs::File::open(source)?;
|
let dat = fs::File::open(source)?;
|
||||||
let tar = GzDecoder::new(dat);
|
let tar = GzDecoder::new(dat);
|
||||||
|
@ -102,11 +96,7 @@ pub fn extract<S: AsRef<Path>, P: AsRef<Path>>(
|
||||||
}
|
}
|
||||||
PkgFmt::Txz => {
|
PkgFmt::Txz => {
|
||||||
// Extract to install dir
|
// Extract to install dir
|
||||||
debug!(
|
debug!("Decompressing from txz archive '{source:?}' to `{path:?}`");
|
||||||
"Decompressing from txz archive '{:?}' to `{:?}`",
|
|
||||||
source.as_ref(),
|
|
||||||
path.as_ref()
|
|
||||||
);
|
|
||||||
|
|
||||||
let dat = fs::File::open(source)?;
|
let dat = fs::File::open(source)?;
|
||||||
let tar = XzDecoder::new(dat);
|
let tar = XzDecoder::new(dat);
|
||||||
|
@ -116,11 +106,7 @@ pub fn extract<S: AsRef<Path>, P: AsRef<Path>>(
|
||||||
}
|
}
|
||||||
PkgFmt::Tzstd => {
|
PkgFmt::Tzstd => {
|
||||||
// Extract to install dir
|
// Extract to install dir
|
||||||
debug!(
|
debug!("Decompressing from tzstd archive '{source:?}' to `{path:?}`");
|
||||||
"Decompressing from tzstd archive '{:?}' to `{:?}`",
|
|
||||||
source.as_ref(),
|
|
||||||
path.as_ref()
|
|
||||||
);
|
|
||||||
|
|
||||||
let dat = std::fs::File::open(source)?;
|
let dat = std::fs::File::open(source)?;
|
||||||
|
|
||||||
|
@ -135,11 +121,7 @@ pub fn extract<S: AsRef<Path>, P: AsRef<Path>>(
|
||||||
}
|
}
|
||||||
PkgFmt::Zip => {
|
PkgFmt::Zip => {
|
||||||
// Extract to install dir
|
// Extract to install dir
|
||||||
debug!(
|
debug!("Decompressing from zip archive '{source:?}' to `{path:?}`");
|
||||||
"Decompressing from zip archive '{:?}' to `{:?}`",
|
|
||||||
source.as_ref(),
|
|
||||||
path.as_ref()
|
|
||||||
);
|
|
||||||
|
|
||||||
let dat = fs::File::open(source)?;
|
let dat = fs::File::open(source)?;
|
||||||
let mut zip = ZipArchive::new(dat)?;
|
let mut zip = ZipArchive::new(dat)?;
|
||||||
|
@ -147,11 +129,7 @@ pub fn extract<S: AsRef<Path>, P: AsRef<Path>>(
|
||||||
zip.extract(path)?;
|
zip.extract(path)?;
|
||||||
}
|
}
|
||||||
PkgFmt::Bin => {
|
PkgFmt::Bin => {
|
||||||
debug!(
|
debug!("Copying binary '{source:?}' to `{path:?}`");
|
||||||
"Copying binary '{:?}' to `{:?}`",
|
|
||||||
source.as_ref(),
|
|
||||||
path.as_ref()
|
|
||||||
);
|
|
||||||
// Copy to install dir
|
// Copy to install dir
|
||||||
fs::copy(source, path)?;
|
fs::copy(source, path)?;
|
||||||
}
|
}
|
||||||
|
@ -170,12 +148,12 @@ pub fn get_install_path<P: AsRef<Path>>(install_path: Option<P>) -> Option<PathB
|
||||||
|
|
||||||
// Environmental variables
|
// Environmental variables
|
||||||
if let Ok(p) = std::env::var("CARGO_INSTALL_ROOT") {
|
if let Ok(p) = std::env::var("CARGO_INSTALL_ROOT") {
|
||||||
debug!("using CARGO_INSTALL_ROOT ({})", p);
|
debug!("using CARGO_INSTALL_ROOT ({p})");
|
||||||
let b = PathBuf::from(p);
|
let b = PathBuf::from(p);
|
||||||
return Some(b.join("bin"));
|
return Some(b.join("bin"));
|
||||||
}
|
}
|
||||||
if let Ok(p) = std::env::var("CARGO_HOME") {
|
if let Ok(p) = std::env::var("CARGO_HOME") {
|
||||||
debug!("using CARGO_HOME ({})", p);
|
debug!("using CARGO_HOME ({p})");
|
||||||
let b = PathBuf::from(p);
|
let b = PathBuf::from(p);
|
||||||
return Some(b.join("bin"));
|
return Some(b.join("bin"));
|
||||||
}
|
}
|
||||||
|
|
|
@ -372,17 +372,17 @@ async fn install_from_package(
|
||||||
{
|
{
|
||||||
// Fetch and check package signature if available
|
// Fetch and check package signature if available
|
||||||
if let Some(pub_key) = meta.as_ref().map(|m| m.pub_key.clone()).flatten() {
|
if let Some(pub_key) = meta.as_ref().map(|m| m.pub_key.clone()).flatten() {
|
||||||
debug!("Found public key: {}", pub_key);
|
debug!("Found public key: {pub_key}");
|
||||||
|
|
||||||
// Generate signature file URL
|
// Generate signature file URL
|
||||||
let mut sig_ctx = ctx.clone();
|
let mut sig_ctx = ctx.clone();
|
||||||
sig_ctx.format = "sig".to_string();
|
sig_ctx.format = "sig".to_string();
|
||||||
let sig_url = sig_ctx.render(&pkg_url)?;
|
let sig_url = sig_ctx.render(&pkg_url)?;
|
||||||
|
|
||||||
debug!("Fetching signature file: {}", sig_url);
|
debug!("Fetching signature file: {sig_url}");
|
||||||
|
|
||||||
// Download signature file
|
// Download signature file
|
||||||
let sig_path = temp_dir.path().join(format!("{}.sig", pkg_name));
|
let sig_path = temp_dir.path().join(format!("{pkg_name}.sig"));
|
||||||
download(&sig_url, &sig_path).await?;
|
download(&sig_url, &sig_path).await?;
|
||||||
|
|
||||||
// TODO: do the signature check
|
// TODO: do the signature check
|
||||||
|
@ -508,7 +508,7 @@ async fn install_from_source(opts: Options, package: Package<Meta>, target: &str
|
||||||
info!("Cargo finished successfully");
|
info!("Cargo finished successfully");
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
error!("Cargo errored! {:?}", status);
|
error!("Cargo errored! {status:?}");
|
||||||
Err(miette!("Cargo install error"))
|
Err(miette!("Cargo install error"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue