mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-21 04:58:42 +00:00
Use newer format! syntax
This commit is contained in:
parent
bd562924a2
commit
6333fb0bd3
3 changed files with 20 additions and 42 deletions
|
@ -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)
|
||||||
|
|
|
@ -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