Skip to content

Commit

Permalink
fixes from review
Browse files Browse the repository at this point in the history
  • Loading branch information
jreidinger committed Apr 29, 2024
1 parent 785dae7 commit fedf5e9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
2 changes: 2 additions & 0 deletions rust/agama-lib/src/dbus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ where
T::try_from(value).map_err(|e| e.into())
}

/// It is similar helper like get_property with difference that name does not need to be in HashMap.
/// In such case `None``is returned, so type has to be enclosed in `Option`.`
pub fn get_optional_property<'a, T>(
properties: &'a HashMap<String, OwnedValue>,
name: &str,
Expand Down
2 changes: 2 additions & 0 deletions rust/agama-lib/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ pub enum ServiceError {
DBus(#[from] zbus::Error),
#[error("Could not connect to Agama bus at '{0}': {1}")]
DBusConnectionError(String, #[source] zbus::Error),
#[error("D-Bus protocol error: {0}")]
DBusProtocol(#[from] zbus::fdo::Error),
#[error("Unexpected type on D-Bus '{0}'")]
ZVariant(#[from] zvariant::Error),
// it's fine to say only "Error" because the original
Expand Down
27 changes: 12 additions & 15 deletions rust/agama-lib/src/storage/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pub struct Action {
}

/// Represents value for target key of Volume
/// It is snake cased when serializing to be compatible with yast2-storage-ng.
#[derive(Debug, Clone, Serialize, Deserialize, utoipa::ToSchema)]
#[serde(rename_all = "snake_case")]
pub enum VolumeTarget {
Expand Down Expand Up @@ -286,7 +287,7 @@ impl<'a> StorageClient<'a> {
) -> Result<Device, ServiceError> {
let interfaces = &object.1;
Ok(Device {
device_info: self.build_device_info(interfaces).await?,
device_info: self.build_device_info(object).await?,
component: None,
drive: None,
block_device: self.build_block_device(interfaces).await?,
Expand All @@ -302,11 +303,7 @@ impl<'a> StorageClient<'a> {
}

pub async fn system_devices(&self) -> Result<Vec<Device>, ServiceError> {
let objects = self
.object_manager_proxy
.get_managed_objects()
.await
.context("Failed to get managed objects")?;
let objects = self.object_manager_proxy.get_managed_objects().await?;
let mut result = vec![];
for object in objects {
let path = &object.0;
Expand All @@ -321,11 +318,7 @@ impl<'a> StorageClient<'a> {
}

pub async fn staging_devices(&self) -> Result<Vec<Device>, ServiceError> {
let objects = self
.object_manager_proxy
.get_managed_objects()
.await
.context("Failed to get managed objects")?;
let objects = self.object_manager_proxy.get_managed_objects().await?;
let mut result = vec![];
for object in objects {
let path = &object.0;
Expand All @@ -341,8 +334,12 @@ impl<'a> StorageClient<'a> {

async fn build_device_info(
&self,
interfaces: &HashMap<OwnedInterfaceName, HashMap<std::string::String, OwnedValue>>,
object: &(
OwnedObjectPath,
HashMap<OwnedInterfaceName, HashMap<std::string::String, OwnedValue>>,
),
) -> Result<DeviceInfo, ServiceError> {
let interfaces = &object.1;
let interface: OwnedInterfaceName =
InterfaceName::from_static_str_unchecked("org.opensuse.Agama.Storage1.Device").into();
let properties = interfaces.get(&interface);
Expand All @@ -354,9 +351,9 @@ impl<'a> StorageClient<'a> {
description: get_property(properties, "Description")?,
})
} else {
Err(ServiceError::Anyhow(anyhow!(
"Device does not implement device info"
)))
let message =
format!("storage device {} is missing Device interface", object.0).to_string();
Err(zbus::zvariant::Error::Message(message).into())
}
}

Expand Down

0 comments on commit fedf5e9

Please sign in to comment.