diff --git a/rust/agama-utils/src/arch.rs b/rust/agama-utils/src/arch.rs index b955c3a12a..6277657382 100644 --- a/rust/agama-utils/src/arch.rs +++ b/rust/agama-utils/src/arch.rs @@ -49,6 +49,16 @@ impl Arch { .try_into() .map_err(|_| Error::Unknown(arch_str)) } + + /// Returns the identifier used in the products definition. + pub fn to_yast_id(&self) -> String { + match &self { + Arch::AARCH64 => "aarch64".to_string(), + Arch::PPC64LE => "ppc".to_string(), + Arch::S390X => "s390".to_string(), + Arch::X86_64 => "x86_64".to_string(), + } + } } #[cfg(test)] @@ -71,6 +81,14 @@ mod tests { assert_eq!(Arch::X86_64.to_string(), "x86_64".to_string()); } + #[test] + fn test_to_product_string() { + assert_eq!(Arch::AARCH64.to_yast_id(), "aarch64".to_string()); + assert_eq!(Arch::PPC64LE.to_yast_id(), "ppc".to_string()); + assert_eq!(Arch::S390X.to_yast_id(), "s390".to_string()); + assert_eq!(Arch::X86_64.to_yast_id(), "x86_64".to_string()); + } + #[cfg(target_arch = "aarch64")] #[test] fn test_current_arch_aarch64() { diff --git a/rust/agama-utils/src/products.rs b/rust/agama-utils/src/products.rs index 80fc25eb0f..3c591b232c 100644 --- a/rust/agama-utils/src/products.rs +++ b/rust/agama-utils/src/products.rs @@ -24,7 +24,10 @@ //! It reads the list of products from the `products.d` directory (usually, //! `/usr/share/agama/products.d`). -use crate::api::{l10n::Translations, manager::Product}; +use crate::{ + api::{l10n::Translations, manager::Product}, + arch::Arch, +}; use serde::{Deserialize, Deserializer, Serialize}; use serde_with::{formats::CommaSeparator, serde_as, StringWithSeparator}; use std::path::{Path, PathBuf}; @@ -177,7 +180,11 @@ pub struct SoftwareSpec { impl SoftwareSpec { // NOTE: perhaps implementing our own iterator would be more efficient. pub fn repositories(&self) -> Vec<&RepositorySpec> { - let arch = std::env::consts::ARCH.to_string(); + let Ok(arch) = Arch::current() else { + tracing::error!("Failed to determine the architecture"); + return vec![]; + }; + let arch = arch.to_yast_id(); self.installation_repositories .iter() .filter(|r| r.archs.is_empty() || r.archs.contains(&arch))