Skip to content

Commit

Permalink
Fix handling of file "extensions" that just contain the OS and archit…
Browse files Browse the repository at this point in the history
…ecture, like ".linux.amd64"

Fixes jdx/mise#2854
  • Loading branch information
jdx authored and autarch committed Nov 10, 2024
1 parent ef65682 commit f5101e1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
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

0 comments on commit f5101e1

Please sign in to comment.