From fc375586b992a2a0a31da7e1af66bf40902a8abb Mon Sep 17 00:00:00 2001 From: Jeff Dickey <216188+jdx@users.noreply.github.com> Date: Mon, 28 Oct 2024 14:34:28 +0000 Subject: [PATCH] fix: assets ending in ".$OS.$ARCH" Fixes https://github.com/jdx/mise/issues/2854 --- ubi/src/extension.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/ubi/src/extension.rs b/ubi/src/extension.rs index cb7c2c6..3349ac0 100644 --- a/ubi/src/extension.rs +++ b/ubi/src/extension.rs @@ -1,8 +1,10 @@ +use crate::arch::all_arches_re; use crate::os::all_oses_re; use anyhow::Result; use itertools::Itertools; -use lazy_regex::regex; +use lazy_regex::{regex, Lazy}; use log::debug; +use regex::Regex; use std::{ffi::OsStr, path::Path}; use strum::{EnumIter, IntoEnumIterator}; use thiserror::Error; @@ -108,7 +110,17 @@ fn extension_is_part_of_version(path: &str, ext_str: &OsStr) -> bool { } fn extension_is_platform(ext_str: &OsStr) -> bool { - all_oses_re().is_match(ext_str.to_string_lossy().as_ref()) + static PLATFORM_RE: Lazy = Lazy::new(|| { + Regex::new( + &[all_oses_re(), all_arches_re()] + .iter() + .map(|r| format!("({})", r.as_str())) + .join("|"), + ) + .unwrap() + }); + + PLATFORM_RE.is_match(ext_str.to_string_lossy().as_ref()) } #[cfg(test)] @@ -129,6 +141,7 @@ mod test { #[test_case("foo.zip", Ok(Some(Extension::Zip)))] #[test_case("foo", Ok(None))] #[test_case("foo_3.2.1_linux_amd64", Ok(None))] + #[test_case("foo_3.9.1.linux.amd64", Ok(None))] #[test_case("foo.bar", Err(ExtensionError::UnknownExtension { path: "foo.bar".to_string(), ext: "bar".to_string() }.into()))] fn from_path(path: &str, expect: Result>) { let ext = Extension::from_path(path);