Skip to content

Commit

Permalink
wrap StorageSettings in Option to allow for null from D-Bus, fixes #2057
Browse files Browse the repository at this point in the history
  • Loading branch information
mvidner committed Feb 25, 2025
1 parent 2943d1d commit ee7da75
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 7 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 @@ -158,7 +158,7 @@ impl<'a> StorageClient<'a> {
}

/// Get the storage config according to the JSON schema
pub async fn get_config(&self) -> Result<StorageSettings, ServiceError> {
pub async fn get_config(&self) -> Result<Option<StorageSettings>, ServiceError> {
let serialized_settings = self.storage_proxy.get_config().await?;
let settings = serde_json::from_str(serialized_settings.as_str())?;
Ok(settings)
Expand Down
2 changes: 1 addition & 1 deletion rust/agama-lib/src/storage/http_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl StorageHTTPClient {
Self { client: base }
}

pub async fn get_config(&self) -> Result<StorageSettings, ServiceError> {
pub async fn get_config(&self) -> Result<Option<StorageSettings>, ServiceError> {
self.client.get("/storage/config").await
}

Expand Down
2 changes: 1 addition & 1 deletion rust/agama-lib/src/storage/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl StorageStore {
})
}

pub async fn load(&self) -> Result<StorageSettings, ServiceError> {
pub async fn load(&self) -> Result<Option<StorageSettings>, ServiceError> {
self.storage_client.get_config().await
}

Expand Down
7 changes: 4 additions & 3 deletions rust/agama-lib/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,10 @@ impl Store {
..Default::default()
};

let storage_settings = self.storage.load().await?;
settings.storage = storage_settings.storage;
settings.storage_autoyast = storage_settings.storage_autoyast;
if let Some(storage_settings) = self.storage.load().await? {
settings.storage = storage_settings.storage;
settings.storage_autoyast = storage_settings.storage_autoyast;
}

// TODO: use try_join here
Ok(settings)
Expand Down
4 changes: 3 additions & 1 deletion rust/agama-server/src/storage/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ pub async fn storage_service(dbus: zbus::Connection) -> Result<Router, ServiceEr
(status = 400, description = "The D-Bus service could not perform the action")
)
)]
async fn get_config(State(state): State<StorageState<'_>>) -> Result<Json<StorageSettings>, Error> {
async fn get_config(
State(state): State<StorageState<'_>>,
) -> Result<Json<Option<StorageSettings>>, Error> {
// StorageSettings is just a wrapper over serde_json::value::RawValue
let settings = state.client.get_config().await.map_err(Error::Service)?;
Ok(Json(settings))
Expand Down

0 comments on commit ee7da75

Please sign in to comment.