mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-20 20:48:43 +00:00
Fix quickinstall failing when packages are not wrapped in a folder
This commit is contained in:
parent
49f3489398
commit
b5d6d68d6d
4 changed files with 23 additions and 2 deletions
13
src/bins.rs
13
src/bins.rs
|
@ -1,6 +1,7 @@
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use cargo_toml::Product;
|
use cargo_toml::Product;
|
||||||
|
use log::debug;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
use crate::{PkgFmt, PkgMeta, Template};
|
use crate::{PkgFmt, PkgMeta, Template};
|
||||||
|
@ -76,11 +77,17 @@ impl BinFile {
|
||||||
|
|
||||||
pub fn install_bin(&self) -> Result<(), anyhow::Error> {
|
pub fn install_bin(&self) -> Result<(), anyhow::Error> {
|
||||||
// TODO: check if file already exists
|
// TODO: check if file already exists
|
||||||
|
debug!(
|
||||||
|
"Copy file from '{}' to '{}'",
|
||||||
|
self.source.display(),
|
||||||
|
self.dest.display()
|
||||||
|
);
|
||||||
std::fs::copy(&self.source, &self.dest)?;
|
std::fs::copy(&self.source, &self.dest)?;
|
||||||
|
|
||||||
#[cfg(target_family = "unix")]
|
#[cfg(target_family = "unix")]
|
||||||
{
|
{
|
||||||
use std::os::unix::fs::PermissionsExt;
|
use std::os::unix::fs::PermissionsExt;
|
||||||
|
debug!("Set permissions 755 on '{}'", self.dest.display());
|
||||||
std::fs::set_permissions(&self.dest, std::fs::Permissions::from_mode(0o755))?;
|
std::fs::set_permissions(&self.dest, std::fs::Permissions::from_mode(0o755))?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,9 +98,15 @@ impl BinFile {
|
||||||
// Remove existing symlink
|
// Remove existing symlink
|
||||||
// TODO: check if existing symlink is correct
|
// TODO: check if existing symlink is correct
|
||||||
if self.link.exists() {
|
if self.link.exists() {
|
||||||
|
debug!("Remove link '{}'", self.link.display());
|
||||||
std::fs::remove_file(&self.link)?;
|
std::fs::remove_file(&self.link)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
debug!(
|
||||||
|
"Create link '{}' pointing to '{}'",
|
||||||
|
self.link.display(),
|
||||||
|
self.dest.display()
|
||||||
|
);
|
||||||
#[cfg(target_family = "unix")]
|
#[cfg(target_family = "unix")]
|
||||||
std::os::unix::fs::symlink(&self.dest, &self.link)?;
|
std::os::unix::fs::symlink(&self.dest, &self.link)?;
|
||||||
#[cfg(target_family = "windows")]
|
#[cfg(target_family = "windows")]
|
||||||
|
|
|
@ -35,7 +35,7 @@ impl super::Fetcher for QuickInstall {
|
||||||
async fn fetch(&self, dst: &Path) -> Result<(), anyhow::Error> {
|
async fn fetch(&self, dst: &Path) -> Result<(), anyhow::Error> {
|
||||||
let url = self.package_url();
|
let url = self.package_url();
|
||||||
info!("Downloading package from: '{url}'");
|
info!("Downloading package from: '{url}'");
|
||||||
download(&url, dst).await
|
download(&url, &dst).await
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pkg_fmt(&self) -> PkgFmt {
|
fn pkg_fmt(&self) -> PkgFmt {
|
||||||
|
@ -45,6 +45,7 @@ impl super::Fetcher for QuickInstall {
|
||||||
fn source_name(&self) -> String {
|
fn source_name(&self) -> String {
|
||||||
String::from("QuickInstall")
|
String::from("QuickInstall")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_third_party(&self) -> bool {
|
fn is_third_party(&self) -> bool {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,8 +45,10 @@ pub async fn download<P: AsRef<Path>>(url: &str, path: P) -> Result<(), anyhow::
|
||||||
|
|
||||||
let bytes = resp.bytes().await?;
|
let bytes = resp.bytes().await?;
|
||||||
|
|
||||||
debug!("Download OK, writing to file: '{:?}'", path.as_ref());
|
let path = path.as_ref();
|
||||||
|
debug!("Download OK, writing to file: '{}'", path.display());
|
||||||
|
|
||||||
|
std::fs::create_dir_all(path.parent().unwrap())?;
|
||||||
std::fs::write(&path, bytes)?;
|
std::fs::write(&path, bytes)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -168,6 +168,11 @@ async fn main() -> Result<(), anyhow::Error> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if fetcher.source_name() == "QuickInstall" {
|
||||||
|
// TODO: less of a hack?
|
||||||
|
meta.bin_dir = "{ bin }{ binary-ext }".to_string();
|
||||||
|
}
|
||||||
|
|
||||||
// Download package
|
// Download package
|
||||||
if opts.dry_run {
|
if opts.dry_run {
|
||||||
info!("Dry run, not downloading package");
|
info!("Dry run, not downloading package");
|
||||||
|
|
Loading…
Add table
Reference in a new issue