Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions rust/agama-software/examples/write_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,11 @@
use agama_security as security;
use agama_software::state::SoftwareStateBuilder;
use agama_software::zypp_server::{SoftwareAction, ZyppServer, ZyppServerResult};
use agama_software::WriteIssues;
use agama_utils::api::question::{Answer, AnswerRule, Config};
use agama_utils::api::software::SoftwareConfig;
use agama_utils::products::Registry;
use agama_utils::{
actor,
api::{event::Event, Issue},
progress, question,
};
use agama_utils::{actor, api::event::Event, progress, question};
use camino::{Utf8Path, Utf8PathBuf};
use glob::glob;
use std::fs;
Expand Down Expand Up @@ -135,7 +132,7 @@ async fn main() {
})
.expect("Failed to send SoftwareAction::Write");

let result: ZyppServerResult<Vec<Issue>> =
let result: ZyppServerResult<WriteIssues> =
rx.await.expect("Failed to receive response from server");
if let Err(err) = result {
panic!("SoftwareAction::Write failed: {:?}", err);
Expand Down Expand Up @@ -173,7 +170,7 @@ async fn main() {
})
.expect("Failed to send SoftwareAction::Write");

let result: ZyppServerResult<Vec<Issue>> =
let result: ZyppServerResult<WriteIssues> =
rx.await.expect("Failed to receive response from server");
if let Err(err) = result {
panic!("SoftwareAction::Write failed: {:?}", err);
Expand All @@ -197,7 +194,7 @@ async fn main() {
})
.expect("Failed to send SoftwareAction::Write");

let result: ZyppServerResult<Vec<Issue>> =
let result: ZyppServerResult<WriteIssues> =
rx.await.expect("Failed to receive response from server");
if let Err(err) = result {
panic!("SoftwareAction::Write failed: {:?}", err);
Expand Down
4 changes: 3 additions & 1 deletion rust/agama-software/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ pub mod service;
pub use service::Service;

mod model;
pub use model::{state, Model, ModelAdapter, Registration, Resolvable, ResolvableType};
pub use model::{
state, Model, ModelAdapter, Registration, Resolvable, ResolvableType, WriteIssues,
};

mod callbacks;
pub mod message;
Expand Down
17 changes: 15 additions & 2 deletions rust/agama-software/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,19 @@ pub mod state;
pub use packages::{Resolvable, ResolvableType};
pub use registration::Registration;

/// Issues found when applying the software configuration.
#[derive(Debug, Default)]
pub struct WriteIssues {
pub product: Vec<Issue>,
pub software: Vec<Issue>,
}

impl WriteIssues {
pub fn is_empty(&self) -> bool {
self.product.is_empty() && self.software.is_empty()
}
}

/// Abstract the software-related configuration from the underlying system.
///
/// It offers an API to query and set different software and product elements of a
Expand Down Expand Up @@ -73,7 +86,7 @@ pub trait ModelAdapter: Send + Sync + 'static {
&mut self,
software: SoftwareState,
progress: Handler<progress::Service>,
) -> Result<Vec<Issue>, service::Error>;
) -> Result<WriteIssues, service::Error>;
}

/// [ModelAdapter] implementation for libzypp systems.
Expand Down Expand Up @@ -119,7 +132,7 @@ impl ModelAdapter for Model {
&mut self,
software: SoftwareState,
progress: Handler<progress::Service>,
) -> Result<Vec<Issue>, service::Error> {
) -> Result<WriteIssues, service::Error> {
let (tx, rx) = oneshot::channel();
self.zypp_sender.send(SoftwareAction::Write {
state: software,
Expand Down
27 changes: 14 additions & 13 deletions rust/agama-software/src/model/packages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
// To contact SUSE LLC about this file by physical or electronic mail, you may
// find current contact information at www.suse.com.

use gettextrs::gettext;
use serde::{Deserialize, Serialize};
use std::fmt;

/// Represents a software resolvable.
#[derive(Clone, Debug, Deserialize, PartialEq, utoipa::ToSchema)]
Expand All @@ -38,26 +40,25 @@ impl Resolvable {
}

/// Software resolvable type (package or pattern).
#[derive(
Clone,
Copy,
Debug,
Deserialize,
Serialize,
strum::Display,
utoipa::ToSchema,
PartialEq,
Eq,
Hash,
)]
#[strum(serialize_all = "camelCase")]
#[derive(Clone, Copy, Debug, Deserialize, Serialize, utoipa::ToSchema, PartialEq, Eq, Hash)]
#[serde(rename_all = "camelCase")]
pub enum ResolvableType {
Package = 0,
Pattern = 1,
Product = 2,
}

impl fmt::Display for ResolvableType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let label = match self {
ResolvableType::Package => gettext("package"),
ResolvableType::Pattern => gettext("pattern"),
ResolvableType::Product => gettext("product"),
};
write!(f, "{}", label)
}
}

impl From<ResolvableType> for zypp_agama::ResolvableKind {
fn from(value: ResolvableType) -> Self {
match value {
Expand Down
25 changes: 20 additions & 5 deletions rust/agama-software/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@

use crate::{
message,
model::{software_selection::SoftwareSelection, state::SoftwareState, ModelAdapter},
model::{
software_selection::SoftwareSelection, state::SoftwareState, ModelAdapter, WriteIssues,
},
zypp_server::{self, SoftwareAction, ZyppServer},
Model, ResolvableType,
};
Expand All @@ -39,6 +41,7 @@ use agama_utils::{
progress, question,
};
use async_trait::async_trait;
use gettextrs::gettext;
use std::{path::PathBuf, process::Command, sync::Arc};
use tokio::sync::{broadcast, Mutex, MutexGuard, RwLock};
use url::Url;
Expand Down Expand Up @@ -274,13 +277,25 @@ impl Service {
.await
.unwrap_or_else(|e| {
let new_issue = Issue::new(
"software.proposal_failed",
"It was not possible to create a software proposal",
"software_proposal_failed",
&gettext("Due to an internal error, it was not possible to create a software proposal."),
)
.with_details(&e.to_string());
vec![new_issue]
WriteIssues {
software: vec![new_issue],
..Default::default()
}
});
_ = issues.cast(issue::message::Set::new(Scope::Software, found_issues));

_ = issues.cast(issue::message::Set::new(
Scope::Software,
found_issues.software,
));

_ = issues.cast(issue::message::Set::new(
Scope::Product,
found_issues.product,
));

Self::update_state(state, my_model, events).await;
});
Expand Down
7 changes: 3 additions & 4 deletions rust/agama-software/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ use agama_utils::{
api::{
event,
software::{SoftwareProposal, SystemInfo},
Issue,
},
issue,
products::ProductSpec,
Expand All @@ -33,7 +32,7 @@ use agama_utils::{
use async_trait::async_trait;

use crate::{
model::state::SoftwareState,
model::{state::SoftwareState, WriteIssues},
service::{self},
ModelAdapter, Service,
};
Expand Down Expand Up @@ -78,8 +77,8 @@ impl ModelAdapter for TestModel {
&mut self,
_software: SoftwareState,
_progress: Handler<progress::Service>,
) -> Result<Vec<Issue>, service::Error> {
Ok(vec![])
) -> Result<WriteIssues, service::Error> {
Ok(Default::default())
}
}

Expand Down
Loading
Loading