diff --git a/rust/agama-lib/src/error.rs b/rust/agama-lib/src/error.rs index e9a9f205ca..5ecde908ca 100644 --- a/rust/agama-lib/src/error.rs +++ b/rust/agama-lib/src/error.rs @@ -18,6 +18,8 @@ pub enum ServiceError { Anyhow(#[from] anyhow::Error), #[error("Wrong user parameters: '{0:?}'")] WrongUser(Vec), + #[error("Result error ({0}): {1}")] + Result(u32, String), } #[derive(Error, Debug)] diff --git a/rust/agama-lib/src/software/client.rs b/rust/agama-lib/src/software/client.rs index 1a56faf9da..cd3c01b684 100644 --- a/rust/agama-lib/src/software/client.rs +++ b/rust/agama-lib/src/software/client.rs @@ -30,7 +30,7 @@ impl<'a> SoftwareClient<'a> { pub async fn products(&self) -> Result, ServiceError> { let products: Vec = self .software_proxy - .available_base_products() + .available_products() .await? .into_iter() .map(|(id, name, data)| { @@ -50,11 +50,22 @@ impl<'a> SoftwareClient<'a> { /// Returns the selected product to install pub async fn product(&self) -> Result { - 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 = 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)), + } } } diff --git a/rust/agama-lib/src/software/proxies.rs b/rust/agama-lib/src/software/proxies.rs index 8803fce495..b9721bbf4a 100644 --- a/rust/agama-lib/src/software/proxies.rs +++ b/rust/agama-lib/src/software/proxies.rs @@ -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( @@ -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<()>; @@ -18,6 +21,12 @@ trait Software1 { /// IsPackageInstalled method fn is_package_installed(&self, name: &str) -> zbus::Result; + /// ListPatterns method + fn list_patterns( + &self, + filtered: bool, + ) -> zbus::Result>; + /// Probe method fn probe(&self) -> zbus::Result<()>; @@ -27,15 +36,21 @@ trait Software1 { /// ProvisionsSelected method fn provisions_selected(&self, provisions: &[&str]) -> zbus::Result>; + /// 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; - /// AvailableBaseProducts property + /// AvailableProducts property #[dbus_proxy(property)] - fn available_base_products( + fn available_products( &self, ) -> zbus::Result< Vec<( @@ -45,9 +60,13 @@ trait Software1 { )>, >; - /// SelectedBaseProduct property + /// SelectedPatterns property + #[dbus_proxy(property)] + fn selected_patterns(&self) -> zbus::Result>; + + /// SelectedProduct property #[dbus_proxy(property)] - fn selected_base_product(&self) -> zbus::Result; + fn selected_product(&self) -> zbus::Result; } #[dbus_proxy( diff --git a/rust/agama-lib/src/software/store.rs b/rust/agama-lib/src/software/store.rs index 45706ed531..9a8a5fb365 100644 --- a/rust/agama-lib/src/software/store.rs +++ b/rust/agama-lib/src/software/store.rs @@ -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 = 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(()) } }