Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
joseivanlopez committed Jul 3, 2024
1 parent 9db079b commit 69aa0d1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
2 changes: 1 addition & 1 deletion rust/agama-lib/src/storage/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,8 @@ impl<'a> StorageClient<'a> {
Ok(Some(BlockDevice {
active: get_property(properties, "Active")?,
encrypted: get_property(properties, "Encrypted")?,
recoverable_size: get_property(properties, "RecoverableSize")?,
size: get_property(properties, "Size")?,
shrinking: get_property(properties, "Shrinking")?,
start: get_property(properties, "Start")?,
systems: get_property(properties, "Systems")?,
udev_ids: get_property(properties, "UdevIds")?,
Expand Down
33 changes: 32 additions & 1 deletion rust/agama-lib/src/storage/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -504,14 +504,45 @@ pub struct DeviceInfo {
pub struct BlockDevice {
pub active: bool,
pub encrypted: bool,
pub recoverable_size: DeviceSize,
pub size: DeviceSize,
pub shrinking: ShrinkingInfo,
pub start: u64,
pub systems: Vec<String>,
pub udev_ids: Vec<String>,
pub udev_paths: Vec<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize, utoipa::ToSchema)]
#[serde(rename_all = "camelCase")]
pub enum ShrinkingInfo {
Supported(DeviceSize),
Unsupported(Vec<String>),
}

impl TryFrom<zbus::zvariant::Value<'_>> for ShrinkingInfo {
type Error = zbus::zvariant::Error;

fn try_from(value: zbus::zvariant::Value) -> Result<Self, zbus::zvariant::Error> {
let hash: HashMap<String, OwnedValue> = value.clone().try_into()?;
let mut info: Option<Self> = None;

if let Some(size) = get_optional_property(&hash, "Supported")? {
info = Some(Self::Supported(size));
}
if let Some(reasons) = get_optional_property(&hash, "Unsupported")? {
info = Some(Self::Unsupported(reasons));
}

if let Some(info_value) = info {
Ok(info_value)
} else {
Err(Self::Error::Message(
format!("Wrong value for Shrinking: {}", value).to_string(),
))
}
}
}

#[derive(Debug, Clone, Serialize, Deserialize, utoipa::ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct Component {
Expand Down

0 comments on commit 69aa0d1

Please sign in to comment.