From b5d6d68d6d528848d35a27ffede50025108af70e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fe=CC=81lix=20Saparelli?= Date: Wed, 16 Feb 2022 22:42:37 +1300 Subject: [PATCH] Fix quickinstall failing when packages are not wrapped in a folder --- src/bins.rs | 13 +++++++++++++ src/fetchers/quickinstall.rs | 3 ++- src/helpers.rs | 4 +++- src/main.rs | 5 +++++ 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/bins.rs b/src/bins.rs index e91d09bb..c5ded440 100644 --- a/src/bins.rs +++ b/src/bins.rs @@ -1,6 +1,7 @@ use std::path::PathBuf; use cargo_toml::Product; +use log::debug; use serde::Serialize; use crate::{PkgFmt, PkgMeta, Template}; @@ -76,11 +77,17 @@ impl BinFile { pub fn install_bin(&self) -> Result<(), anyhow::Error> { // TODO: check if file already exists + debug!( + "Copy file from '{}' to '{}'", + self.source.display(), + self.dest.display() + ); std::fs::copy(&self.source, &self.dest)?; #[cfg(target_family = "unix")] { 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))?; } @@ -91,9 +98,15 @@ impl BinFile { // Remove existing symlink // TODO: check if existing symlink is correct if self.link.exists() { + debug!("Remove link '{}'", self.link.display()); std::fs::remove_file(&self.link)?; } + debug!( + "Create link '{}' pointing to '{}'", + self.link.display(), + self.dest.display() + ); #[cfg(target_family = "unix")] std::os::unix::fs::symlink(&self.dest, &self.link)?; #[cfg(target_family = "windows")] diff --git a/src/fetchers/quickinstall.rs b/src/fetchers/quickinstall.rs index cbea5f9d..ab26424f 100644 --- a/src/fetchers/quickinstall.rs +++ b/src/fetchers/quickinstall.rs @@ -35,7 +35,7 @@ impl super::Fetcher for QuickInstall { async fn fetch(&self, dst: &Path) -> Result<(), anyhow::Error> { let url = self.package_url(); info!("Downloading package from: '{url}'"); - download(&url, dst).await + download(&url, &dst).await } fn pkg_fmt(&self) -> PkgFmt { @@ -45,6 +45,7 @@ impl super::Fetcher for QuickInstall { fn source_name(&self) -> String { String::from("QuickInstall") } + fn is_third_party(&self) -> bool { true } diff --git a/src/helpers.rs b/src/helpers.rs index a94437a6..3b6c7505 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -45,8 +45,10 @@ pub async fn download>(url: &str, path: P) -> Result<(), anyhow:: 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)?; Ok(()) diff --git a/src/main.rs b/src/main.rs index dbc482b5..fdbd0bdf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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 if opts.dry_run { info!("Dry run, not downloading package");