Skip to content
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
18 changes: 18 additions & 0 deletions rust/agama-utils/src/arch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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() {
Expand Down
11 changes: 9 additions & 2 deletions rust/agama-utils/src/products.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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))
Expand Down
Loading