Skip to content

Commit

Permalink
🚑 fix broken macos installation
Browse files Browse the repository at this point in the history
  • Loading branch information
salamaashoush committed Sep 10, 2024
1 parent 16423af commit b440066
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 85 deletions.
5 changes: 5 additions & 0 deletions .changeset/rich-goats-own.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"pactup": patch
---

fix macos installation
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,20 @@ cargo test
- The Pact binaries are problematic; they are not consistent in each release, and often, releases are missing binaries. For example, the latest release, 4.12, does not have any Mac binaries on GitHub. Expect some issues with this.
- Some older versions might require older system libs (eg. libncurses5).

## Troubleshooting

**Error: "Can't download the requested binary: Permission denied (os error 13)"**

This error occurs when installing the `development-latest` nightly version, and then attempting to force install or remove it. The issue stems from permission problems in older versions of `pactup`.

To resolve this, update to the latest `pactup` version (>=0.2.18), and run:

```
sudo pactup uninstall development-latest
```

After this, you should be able to run install/uninstall commands without using `sudo`.

## Credit

Pact version manager is ported from the amazing [fnm](https://github.com/Schniz/fnm) codebase.
13 changes: 12 additions & 1 deletion src/commands/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,15 @@ impl Command for Install {
format!("Pact {}", &version).cyan(),
config.arch.to_string()
);
let Some(download_url) = release.download_url() else {
return Err(Error::CantFindReleaseAsset {
requested_version: current_version,
});
};

match install_pact_dist(
version,
&release.download_url(),
&download_url,
config.installations_dir(),
&config.arch,
show_progress,
Expand Down Expand Up @@ -207,6 +213,11 @@ pub enum Error {
requested_version
)]
CantFindPactVersion { requested_version: UserVersion },
#[error(
"Can't find a release asset for the requested version: {}",
requested_version
)]
CantFindReleaseAsset { requested_version: UserVersion },
#[error("Can't find nightly version named {}", nightly_tag)]
CantFindNightly { nightly_tag: String },
#[error("Can't find any versions in the upstream version index.")]
Expand Down
6 changes: 3 additions & 3 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::log_level::LogLevel;
use crate::path_ext::PathExt;
use crate::version_file_strategy::VersionFileStrategy;
use crate::{directories::Directories, system_info::Arch};
use crate::{directories::Directories, system_info::PlatformArch};

#[derive(clap::Parser, Debug)]
pub struct PactupConfig {
Expand Down Expand Up @@ -65,7 +65,7 @@ pub struct PactupConfig {
hide_env_values = true,
hide_default_value = true
)]
pub arch: Arch,
pub arch: PlatformArch,

/// A strategy for how to resolve the Pact version. Used whenever `pactup use` or `pactup install` is
/// called without a version, or when `--use-on-cd` is configured on evaluation.
Expand Down Expand Up @@ -102,7 +102,7 @@ impl Default for PactupConfig {
base_dir: None,
multishell_path: None,
log_level: LogLevel::Info,
arch: Arch::default(),
arch: PlatformArch::default(),
version_file_strategy: VersionFileStrategy::default(),
directories: Directories::default(),
resolve_engines: false,
Expand Down
13 changes: 8 additions & 5 deletions src/downloader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::archive::extract::ArchiveType;
use crate::archive::{Error as ExtractError, Extract};
use crate::directory_portal::DirectoryPortal;
use crate::progress::ResponseProgress;
use crate::system_info::Arch;
use crate::system_info::PlatformArch;
use crate::version::Version;
use indicatif::ProgressDrawTarget;
use log::debug;
Expand Down Expand Up @@ -33,7 +33,10 @@ pub enum Error {
// #[error("The downloaded archive is empty")]
// TarIsEmpty,
#[error("{} for {} not found upstream.\nYou can `pactup ls-remote` to see available versions or try a different `--arch`.", version, arch)]
VersionNotFound { version: Version, arch: Arch },
VersionNotFound {
version: Version,
arch: PlatformArch,
},
#[error("Version already installed at {:?}", path)]
VersionAlreadyInstalled { path: PathBuf },
}
Expand All @@ -55,7 +58,7 @@ pub fn install_pact_dist<P: AsRef<Path>>(
version: &Version,
download_url: &Url,
installations_dir: P,
arch: &Arch,
arch: &PlatformArch,
show_progress: bool,
force: bool,
) -> Result<(), Error> {
Expand Down Expand Up @@ -149,9 +152,9 @@ mod tests {
fn install_in(path: &Path) -> PathBuf {
let version = Version::parse("4.11.0").unwrap();
#[cfg(target_arch = "x86_64")]
let arch = Arch::X64;
let arch = PlatformArch::X64;
#[cfg(target_arch = "aarch64")]
let arch = Arch::Arm64;
let arch = PlatformArch::Arm64;
// github release asset url
let pact_dist_mirror = Url::parse(
"https://github.com/kadena-io/pact/releases/download/v4.11.0/pact-4.11.0-linux-20.04.zip",
Expand Down
27 changes: 11 additions & 16 deletions src/remote_pact_index.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
system_info::{get_platform, Arch, Platform},
system_info::{get_platform, Platform, PlatformArch, PlatformOS},
version::Version,
};
use chrono::{DateTime, Utc};
Expand Down Expand Up @@ -35,10 +35,7 @@ impl Release {
let version = &self.tag_name;
let platform = get_platform();
match platform {
Platform {
os: "linux",
arch: Arch::X64,
} => {
Platform(PlatformOS::Linux, PlatformArch::X64) => {
let regex = if version.is_nightly() {
// match the nightly version format for linux pact-binary-bundle.ubuntu-*.<tar.gz | zip>
r"pact-binary-bundle\.(ubuntu-latest)\.(tar\.gz|zip)$"
Expand All @@ -48,10 +45,7 @@ impl Release {
};
Regex::new(regex).map_err(|e| format!("Regex creation error: {e}"))
}
Platform {
os: "macos",
arch: Arch::X64,
} => {
Platform(PlatformOS::MacOS, PlatformArch::X64) => {
let regex = if version.is_nightly() {
// match the nightly version format for mac pact-binary-bundle.macos-latest.<tar.gz|zip>
r"pact-binary-bundle\.macos-latest\.(tar\.gz|zip)$"
Expand All @@ -61,10 +55,7 @@ impl Release {
};
Regex::new(regex).map_err(|e| format!("Regex creation error: {e}"))
}
Platform {
os: "macos",
arch: Arch::Arm64,
} => {
Platform(PlatformOS::MacOS, PlatformArch::Arm64) => {
let regex = if version.is_nightly() {
// match the nightly version format for mac pact-binary-bundle.macos-m1.<tar.gz|zip>
r"pact-binary-bundle\.macos-m1\.(tar\.gz|zip)$"
Expand All @@ -86,12 +77,16 @@ impl Release {

/// Checks if the release has a supported asset for the current platform.
pub fn has_supported_asset(&self) -> bool {
println!(
"Checking if release has supported asset {:?}",
self.asset_for_current_platform()
);
self.asset_for_current_platform().is_some()
}

pub fn download_url(&self) -> Url {
let asset = self.asset_for_current_platform().expect("Can't find asset");
asset.browser_download_url.clone()
pub fn download_url(&self) -> Option<Url> {
let asset = self.asset_for_current_platform();
asset.map(|asset| asset.browser_download_url.clone())
}
}

Expand Down
Loading

0 comments on commit b440066

Please sign in to comment.