diff --git a/.github/workflows/ci-rust.yml b/.github/workflows/ci-rust.yml index 4ffe462359..10153a1561 100644 --- a/.github/workflows/ci-rust.yml +++ b/.github/workflows/ci-rust.yml @@ -85,6 +85,7 @@ jobs: - name: Install required packages run: zypper --non-interactive install --allow-downgrade clang-devel + findutils gcc-c++ git libopenssl-3-devel @@ -117,8 +118,13 @@ jobs: rust/target key: ${{ runner.os }}-cargo-clippy-${{ hashFiles('**/Cargo.lock') }} + - name: Run Clang Format check for the C/C++ zypp bindings + run: make check + working-directory: ./rust/zypp-agama/zypp-agama-sys/c-layer + - name: Run clippy linter - run: cargo clippy + # deny warnings: clippy or rustc warnings will fail the build + run: cargo clippy -- -D warnings working-directory: ./rust tests: diff --git a/rust/agama-network/src/service.rs b/rust/agama-network/src/service.rs index 58a19e4d8b..d6b4cccb46 100644 --- a/rust/agama-network/src/service.rs +++ b/rust/agama-network/src/service.rs @@ -281,7 +281,6 @@ impl NetworkSystemClient { } /// Copies the persistent network connections to the target system. - pub async fn install(&self) -> Result<(), NetworkSystemError> { let (tx, rx) = oneshot::channel(); self.actions.send(Action::Install(tx))?; diff --git a/rust/agama-s390/src/service.rs b/rust/agama-s390/src/service.rs index 96217cf4ed..0ddd643018 100644 --- a/rust/agama-s390/src/service.rs +++ b/rust/agama-s390/src/service.rs @@ -90,29 +90,26 @@ impl Starter { pub async fn start(self) -> Result, Error> { // Create storage_client only if needed. - let (service, storage_client) = if self.dasd.is_none() || self.zfcp.is_none() { - let storage_client = storage_client::service::Starter::new(self.connection.clone()) - .start() - .await?; - - let dasd = self - .dasd - .unwrap_or(Box::new(dasd::Client::new(storage_client.clone()))); - - let zfcp = self - .zfcp - .unwrap_or(Box::new(zfcp::Client::new(storage_client.clone()))); - - let service = Service { dasd, zfcp }; - - (service, Some(storage_client)) - } else { - // Note that unwrap is secure here because the if branch covers any case of None. - let service = Service { - dasd: self.dasd.unwrap(), - zfcp: self.zfcp.unwrap(), - }; - (service, None) + let (service, storage_client) = match (self.dasd, self.zfcp) { + (Some(dasd), Some(zfcp)) => { + let service = Service { dasd, zfcp }; + (service, None) + } + (dasd_opt, zfcp_opt) => { + let storage_client = storage_client::service::Starter::new(self.connection.clone()) + .start() + .await?; + + let dasd = + dasd_opt.unwrap_or_else(|| Box::new(dasd::Client::new(storage_client.clone()))); + + let zfcp = + zfcp_opt.unwrap_or_else(|| Box::new(zfcp::Client::new(storage_client.clone()))); + + let service = Service { dasd, zfcp }; + + (service, Some(storage_client)) + } }; let handler = actor::spawn(service); diff --git a/rust/agama-users/src/model.rs b/rust/agama-users/src/model.rs index dfa417ef0e..c1c93d6f42 100644 --- a/rust/agama-users/src/model.rs +++ b/rust/agama-users/src/model.rs @@ -128,7 +128,7 @@ impl Model { ))); } - self.set_user_group(user_name); + self.set_user_group(user_name)?; self.set_user_password(user_name, user_password)?; self.update_user_fullname(user) } diff --git a/rust/agama-users/src/service.rs b/rust/agama-users/src/service.rs index 57d7b291df..5b2c939d21 100644 --- a/rust/agama-users/src/service.rs +++ b/rust/agama-users/src/service.rs @@ -32,7 +32,7 @@ use agama_utils::{ issue, }; use async_trait::async_trait; -use gettextrs::{gettext, LocaleCategory}; +use gettextrs::gettext; use tokio::sync::broadcast; #[derive(thiserror::Error, Debug)] diff --git a/rust/agama-utils/src/api/network/types.rs b/rust/agama-utils/src/api/network/types.rs index ebc7ed5ea5..92e3ab8c6d 100644 --- a/rust/agama-utils/src/api/network/types.rs +++ b/rust/agama-utils/src/api/network/types.rs @@ -626,9 +626,10 @@ impl TryFrom<&str> for Status { } /// Bond mode -#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone, Copy, utoipa::ToSchema)] +#[derive(Serialize, Deserialize, Debug, Default, PartialEq, Eq, Clone, Copy, utoipa::ToSchema)] pub enum BondMode { #[serde(rename = "balance-rr")] + #[default] RoundRobin = 0, #[serde(rename = "active-backup")] ActiveBackup = 1, @@ -643,11 +644,6 @@ pub enum BondMode { #[serde(rename = "balance-alb")] BalanceALB = 6, } -impl Default for BondMode { - fn default() -> Self { - Self::RoundRobin - } -} impl std::fmt::Display for BondMode { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { diff --git a/rust/zypp-agama/zypp-agama-sys/c-layer/Makefile b/rust/zypp-agama/zypp-agama-sys/c-layer/Makefile index f02476b35f..381b457b04 100644 --- a/rust/zypp-agama/zypp-agama-sys/c-layer/Makefile +++ b/rust/zypp-agama/zypp-agama-sys/c-layer/Makefile @@ -11,7 +11,7 @@ clean: check: git ls-files | grep -E '\.(c|h|cxx|hxx)$$' | \ - xargs --verbose clang-format --style=llvm --dry-run + xargs --verbose clang-format --style=llvm -Werror --dry-run libagama-zypp.a: $(OBJ) $(AR) -crs $@ $^ diff --git a/rust/zypp-agama/zypp-agama-sys/c-layer/lib.cxx b/rust/zypp-agama/zypp-agama-sys/c-layer/lib.cxx index 03f4c68298..8f84bfa2ff 100644 --- a/rust/zypp-agama/zypp-agama-sys/c-layer/lib.cxx +++ b/rust/zypp-agama/zypp-agama-sys/c-layer/lib.cxx @@ -38,8 +38,9 @@ struct Zypp { zypp::RepoManager *repo_manager; }; -static struct Zypp the_zypp { - .zypp_pointer = NULL, .repo_manager = NULL, +static struct Zypp the_zypp{ + .zypp_pointer = NULL, + .repo_manager = NULL, }; // formatter which actually logs the messages to the systemd journal, diff --git a/rust/zypp-agama/zypp-agama-sys/src/bindings.rs b/rust/zypp-agama/zypp-agama-sys/src/bindings.rs index a4b0750dc5..1adcaaaa1c 100644 --- a/rust/zypp-agama/zypp-agama-sys/src/bindings.rs +++ b/rust/zypp-agama/zypp-agama-sys/src/bindings.rs @@ -674,7 +674,7 @@ unsafe extern "C" { ) -> bool; #[doc = " Runs solver\n @param zypp see \\ref init_target\n @param only_required if true, only required packages are installed (ignoring\n recommended packages)\n @param[out] status (will overwrite existing contents)\n @return true if solver pass and false if it found some dependency issues"] pub fn run_solver(zypp: *mut Zypp, only_required: bool, status: *mut Status) -> bool; - #[doc = " Create a solver testcase, dumps all all solver data (repositories, loaded packages...) to disk\n @param zypp see \\ref init_target\n @param dir directory path where the solver testcase is saved\n @return true if the solver testcase was successfully created"] + #[doc = " Create a solver testcase, dumps all all solver data (repositories, loaded\n packages...) to disk\n @param zypp see \\ref init_target\n @param dir directory path where the solver testcase is saved\n @return true if the solver testcase was successfully created"] pub fn create_solver_testcase(zypp: *mut Zypp, dir: *const ::std::os::raw::c_char) -> bool; #[doc = " the last call that will free all pointers to zypp holded by agama"] pub fn free_zypp(zypp: *mut Zypp);