Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: assets ending in ".$OS.$ARCH" #71

Merged
merged 1 commit into from
Nov 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Changes.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
## 0.2.2

- Added a `is_musl` method to the `UbiBuilder` struct to allow setting this manually.
- Fix handling of file "extensions" that just contain the OS and architecture, like ".linux.amd64".
Implemented by @jdx (Jeff Dickey). GH #71.

## 0.2.1 - 2024-10-27

Expand Down
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.as_str(), ALL_ARCHES_RE.as_str()]
.iter()
.map(|r| format!("(?:{r})"))
.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