From 44742fa21f2c3286d7d03b2f1a8ac8638f3d6c7b Mon Sep 17 00:00:00 2001 From: Wyvest Date: Wed, 25 Feb 2026 23:23:27 -0500 Subject: [PATCH] port fixes from https://github.com/modrinth/code/pull/2369/ --- packages/core/src/api/game/rules.rs | 2 +- packages/core/src/utils/os_ext.rs | 25 +++++++++++++++++++------ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/packages/core/src/api/game/rules.rs b/packages/core/src/api/game/rules.rs index 9f3991ed..04aaa75a 100644 --- a/packages/core/src/api/game/rules.rs +++ b/packages/core/src/api/game/rules.rs @@ -68,7 +68,7 @@ pub fn validate_os_rule(rule: &OsRule, java_arch: &str, updated: bool) -> bool { if let Some(name) = &rule.name { if updated && (name != &Os::LinuxArm64 || name != &Os::LinuxArm32) { - rule_match &= &Os::native() == name || &Os::native_arch(java_arch) == name; + rule_match &= Os::native() == name.get_os() || &Os::native_arch(java_arch) == name; } else { rule_match &= &Os::native_arch(java_arch) == name; } diff --git a/packages/core/src/utils/os_ext.rs b/packages/core/src/utils/os_ext.rs index fdc65fab..641383bf 100644 --- a/packages/core/src/utils/os_ext.rs +++ b/packages/core/src/utils/os_ext.rs @@ -8,9 +8,22 @@ pub trait OsExt { /// Get the [`Os`] of the current system along with it's arch from the `java_arch`. fn native_arch(java_arch: &str) -> Self; + + /// Gets the OS from an OS + Arch + #[must_use] + fn get_os(&self) -> Self; } impl OsExt for Os { + fn native() -> Self { + match std::env::consts::OS { + "windows" => Self::Windows, + "macos" => Self::Osx, + "linux" => Self::Linux, + _ => Self::Unknown, + } + } + fn native_arch(java_arch: &str) -> Self { if std::env::consts::OS == "windows" { if java_arch == "aarch64" { @@ -37,12 +50,12 @@ impl OsExt for Os { } } - fn native() -> Self { - match std::env::consts::OS { - "windows" => Self::Windows, - "macos" => Self::Osx, - "linux" => Self::Linux, - _ => Self::Unknown, + fn get_os(&self) -> Self { + match self { + Self::OsxArm64 => Self::Osx, + Self::LinuxArm32 | Self::LinuxArm64 => Self::Linux, + Self::WindowsArm64 => Self::Windows, + _ => self.clone(), } } }