Skip to content

Commit

Permalink
fix: assets ending in ".$OS.$ARCH"
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Nov 4, 2024
1 parent 17343a5 commit fc37558
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions ubi/src/extension.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<Regex> = 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)]
Expand All @@ -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<Option<Extension>>) {
let ext = Extension::from_path(path);
Expand Down

0 comments on commit fc37558

Please sign in to comment.