Skip to content

Commit

Permalink
[rust] Adapt to Software D-Bus changes
Browse files Browse the repository at this point in the history
  • Loading branch information
joseivanlopez committed Oct 18, 2023
1 parent cc4ba95 commit f6dc77e
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 17 deletions.
2 changes: 2 additions & 0 deletions rust/agama-lib/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ pub enum ServiceError {
Anyhow(#[from] anyhow::Error),
#[error("Wrong user parameters: '{0:?}'")]
WrongUser(Vec<String>),
#[error("Result error ({0}): {1}")]
Result(u32, String),
}

#[derive(Error, Debug)]
Expand Down
17 changes: 14 additions & 3 deletions rust/agama-lib/src/software/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl<'a> SoftwareClient<'a> {
pub async fn products(&self) -> Result<Vec<Product>, ServiceError> {
let products: Vec<Product> = self
.software_proxy
.available_base_products()
.available_products()
.await?
.into_iter()
.map(|(id, name, data)| {
Expand All @@ -50,11 +50,22 @@ impl<'a> SoftwareClient<'a> {

/// Returns the selected product to install
pub async fn product(&self) -> Result<String, ServiceError> {
Ok(self.software_proxy.selected_base_product().await?)
Ok(self.software_proxy.selected_product().await?)
}

/// Selects the product to install
pub async fn select_product(&self, product_id: &str) -> Result<(), ServiceError> {
Ok(self.software_proxy.select_product(product_id).await?)
let result = self.software_proxy.select_product(product_id).await?;

match result {
(0, _) => Ok(()),
(3, description) => {
let products = self.products().await?;
let ids: Vec<String> = products.into_iter().map(|p| p.id).collect();
let error = format!("{0}. Available products: '{1:?}'", description, ids);
Err(ServiceError::Result(3, error))
},
(code, description) => Err(ServiceError::Result(code, description)),
}
}
}
31 changes: 25 additions & 6 deletions rust/agama-lib/src/software/proxies.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! D-Bus interface proxies for: `org.opensuse.Agama.Software1.*`
//!
//! This code was generated by `zbus-xmlgen` `3.1.0` from DBus introspection data.`.
//! This code was generated by `zbus-xmlgen` `3.1.1` from DBus introspection data.
use zbus::dbus_proxy;

#[dbus_proxy(
Expand All @@ -9,6 +9,9 @@ use zbus::dbus_proxy;
default_path = "/org/opensuse/Agama/Software1"
)]
trait Software1 {
/// AddPattern method
fn add_pattern(&self, id: &str) -> zbus::Result<()>;

/// Finish method
fn finish(&self) -> zbus::Result<()>;

Expand All @@ -18,6 +21,12 @@ trait Software1 {
/// IsPackageInstalled method
fn is_package_installed(&self, name: &str) -> zbus::Result<bool>;

/// ListPatterns method
fn list_patterns(
&self,
filtered: bool,
) -> zbus::Result<std::collections::HashMap<String, (String, String, String, String, String)>>;

/// Probe method
fn probe(&self) -> zbus::Result<()>;

Expand All @@ -27,15 +36,21 @@ trait Software1 {
/// ProvisionsSelected method
fn provisions_selected(&self, provisions: &[&str]) -> zbus::Result<Vec<bool>>;

/// RemovePattern method
fn remove_pattern(&self, id: &str) -> zbus::Result<()>;

/// SelectProduct method
fn select_product(&self, product_id: &str) -> zbus::Result<()>;
fn select_product(&self, id: &str) -> zbus::Result<(u32, String)>;

/// SetUserPatterns method
fn set_user_patterns(&self, ids: &[&str]) -> zbus::Result<()>;

/// UsedDiskSpace method
fn used_disk_space(&self) -> zbus::Result<String>;

/// AvailableBaseProducts property
/// AvailableProducts property
#[dbus_proxy(property)]
fn available_base_products(
fn available_products(
&self,
) -> zbus::Result<
Vec<(
Expand All @@ -45,9 +60,13 @@ trait Software1 {
)>,
>;

/// SelectedBaseProduct property
/// SelectedPatterns property
#[dbus_proxy(property)]
fn selected_patterns(&self) -> zbus::Result<std::collections::HashMap<String, u8>>;

/// SelectedProduct property
#[dbus_proxy(property)]
fn selected_base_product(&self) -> zbus::Result<String>;
fn selected_product(&self) -> zbus::Result<String>;
}

#[dbus_proxy(
Expand Down
11 changes: 3 additions & 8 deletions rust/agama-lib/src/software/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,10 @@ impl<'a> SoftwareStore<'a> {

pub async fn store(&self, settings: &SoftwareSettings) -> Result<(), ServiceError> {
if let Some(product) = &settings.product {
let products = self.software_client.products().await?;
let ids: Vec<String> = products.into_iter().map(|p| p.id).collect();
if ids.contains(product) {
self.software_client.select_product(product).await?;
self.manager_client.probe().await?;
} else {
return Err(ServiceError::UnknownProduct(product.clone(), ids));
}
self.software_client.select_product(product).await?;
self.manager_client.probe().await?;
}

Ok(())
}
}

0 comments on commit f6dc77e

Please sign in to comment.