From 7b00e7ed1f247ae22873c01f73a5c6337d72586d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Imobach=20Gonz=C3=A1lez=20Sosa?= Date: Wed, 27 Dec 2023 12:38:52 +0000 Subject: [PATCH 1/4] Fix several issues detected by Clippy --- rust/agama-cli/src/logs.rs | 7 ++----- rust/agama-dbus-server/src/locale/timezone.rs | 8 ++------ rust/agama-dbus-server/src/network/dbus/service.rs | 1 - rust/agama-dbus-server/src/network/nm/dbus.rs | 5 +---- rust/agama-dbus-server/tests/common/mod.rs | 2 +- rust/agama-dbus-server/tests/network.rs | 4 ++-- rust/agama-lib/src/storage/store.rs | 2 -- rust/agama-locale-data/src/lib.rs | 4 ++-- 8 files changed, 10 insertions(+), 23 deletions(-) diff --git a/rust/agama-cli/src/logs.rs b/rust/agama-cli/src/logs.rs index 9b94adb8e3..7038eaa121 100644 --- a/rust/agama-cli/src/logs.rs +++ b/rust/agama-cli/src/logs.rs @@ -279,7 +279,7 @@ impl LogItem for LogCmd { /// Collect existing / requested paths which should already exist in the system. /// Turns them into list of log sources -fn paths_to_log_sources(paths: &Vec, tmp_dir: &TempDir) -> Vec> { +fn paths_to_log_sources(paths: &[String], tmp_dir: &TempDir) -> Vec> { let mut log_sources: Vec> = Vec::new(); for path in paths.iter() { @@ -293,10 +293,7 @@ fn paths_to_log_sources(paths: &Vec, tmp_dir: &TempDir) -> Vec, - tmp_dir: &TempDir, -) -> Vec> { +fn cmds_to_log_sources(commands: &[(String, String)], tmp_dir: &TempDir) -> Vec> { let mut log_sources: Vec> = Vec::new(); for cmd in commands.iter() { diff --git a/rust/agama-dbus-server/src/locale/timezone.rs b/rust/agama-dbus-server/src/locale/timezone.rs index d032122d66..bfa7ddae8f 100644 --- a/rust/agama-dbus-server/src/locale/timezone.rs +++ b/rust/agama-dbus-server/src/locale/timezone.rs @@ -131,11 +131,7 @@ mod tests { fn test_read_timezone_without_country() { let mut db = TimezonesDatabase::new(); db.read("es").unwrap(); - let timezone = db - .entries() - .into_iter() - .find(|tz| tz.code == "UTC") - .unwrap(); + let timezone = db.entries().iter().find(|tz| tz.code == "UTC").unwrap(); assert_eq!(timezone.country, None); } @@ -145,7 +141,7 @@ mod tests { db.read("en").unwrap(); let timezone = db .entries() - .into_iter() + .iter() .find(|tz| tz.code == "Europe/Kiev") .unwrap(); assert_eq!(timezone.country, Some("Ukraine".to_string())); diff --git a/rust/agama-dbus-server/src/network/dbus/service.rs b/rust/agama-dbus-server/src/network/dbus/service.rs index 9bbf17ffa7..b085cf4855 100644 --- a/rust/agama-dbus-server/src/network/dbus/service.rs +++ b/rust/agama-dbus-server/src/network/dbus/service.rs @@ -17,7 +17,6 @@ impl NetworkService { connection: &Connection, adapter: T, ) -> Result<(), Box> { - let connection = connection.clone(); let mut network = NetworkSystem::new(connection.clone(), adapter); tokio::spawn(async move { diff --git a/rust/agama-dbus-server/src/network/nm/dbus.rs b/rust/agama-dbus-server/src/network/nm/dbus.rs index df3ce6cdf8..3dc7846a38 100644 --- a/rust/agama-dbus-server/src/network/nm/dbus.rs +++ b/rust/agama-dbus-server/src/network/nm/dbus.rs @@ -781,10 +781,7 @@ mod test { )])); let dbus_conn = HashMap::from([ - ( - "connection".to_string(), - connection_section.try_into().unwrap(), - ), + ("connection".to_string(), connection_section), (BOND_KEY.to_string(), bond_options.try_into().unwrap()), ]); diff --git a/rust/agama-dbus-server/tests/common/mod.rs b/rust/agama-dbus-server/tests/common/mod.rs index 47841518e8..009d95bfb1 100644 --- a/rust/agama-dbus-server/tests/common/mod.rs +++ b/rust/agama-dbus-server/tests/common/mod.rs @@ -109,7 +109,7 @@ impl NameOwnerChangedStream { loop { let signal = self.0.next().await.unwrap().unwrap(); let (sname, _, _): (String, String, String) = signal.body().unwrap(); - if &sname == name { + if sname == name { return; } } diff --git a/rust/agama-dbus-server/tests/network.rs b/rust/agama-dbus-server/tests/network.rs index 87b1aaa475..71bbf8f638 100644 --- a/rust/agama-dbus-server/tests/network.rs +++ b/rust/agama-dbus-server/tests/network.rs @@ -102,7 +102,7 @@ async fn test_add_bond_connection() -> Result<(), Box> { let adapter = NetworkTestAdapter(NetworkState::default()); - let _service = NetworkService::start(&server.connection(), adapter).await?; + NetworkService::start(&server.connection(), adapter).await?; server.request_name().await?; let client = NetworkClient::new(server.connection().clone()).await?; @@ -128,7 +128,7 @@ async fn test_add_bond_connection() -> Result<(), Box> { let conns = async_retry(|| client.connections()).await?; assert_eq!(conns.len(), 2); - let conn = conns.iter().find(|c| c.id == "bond0".to_string()).unwrap(); + let conn = conns.iter().find(|c| &c.id == "bond0").unwrap(); assert_eq!(conn.id, "bond0"); assert_eq!(conn.device_type(), DeviceType::Bond); let bond = conn.bond.clone().unwrap(); diff --git a/rust/agama-lib/src/storage/store.rs b/rust/agama-lib/src/storage/store.rs index 7c6ea81b51..926366f721 100644 --- a/rust/agama-lib/src/storage/store.rs +++ b/rust/agama-lib/src/storage/store.rs @@ -2,7 +2,6 @@ use super::{StorageClient, StorageSettings}; use crate::error::ServiceError; -use std::default::Default; use zbus::Connection; /// Loads and stores the storage settings from/to the D-Bus service. @@ -26,7 +25,6 @@ impl<'a> StorageStore<'a> { boot_device, lvm, encryption_password, - ..Default::default() }) } diff --git a/rust/agama-locale-data/src/lib.rs b/rust/agama-locale-data/src/lib.rs index 7c4c313660..71d6c1654c 100644 --- a/rust/agama-locale-data/src/lib.rs +++ b/rust/agama-locale-data/src/lib.rs @@ -162,9 +162,9 @@ mod tests { let first = result.first().expect("no keyboards"); assert_eq!(first, "Africa/Abidjan"); // test that we filter out deprecates Asmera ( there is already recent Asmara) - let asmera = result.iter().find(|&t| *t == "Africa/Asmera".to_string()); + let asmera = result.iter().find(|&t| t == "Africa/Asmera"); assert_eq!(asmera, None); - let asmara = result.iter().find(|&t| *t == "Africa/Asmara".to_string()); + let asmara = result.iter().find(|&t| t == "Africa/Asmara"); assert_eq!(asmara, Some(&"Africa/Asmara".to_string())); // here test that timezones from timezones matches ones in langtable ( as timezones can contain deprecated ones) // so this test catch if there is new zone that is not translated or if a zone is become deprecated From 4a76c9eac15973190cc4ec3394d3d9a04f41a311 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Imobach=20Gonz=C3=A1lez=20Sosa?= Date: Wed, 27 Dec 2023 12:48:53 +0000 Subject: [PATCH 2/4] Rename agama-dbus-server "locale" to "l10n" --- rust/agama-dbus-server/src/{locale.rs => l10n.rs} | 0 rust/agama-dbus-server/src/{locale => l10n}/helpers.rs | 0 rust/agama-dbus-server/src/{locale => l10n}/keyboard.rs | 0 rust/agama-dbus-server/src/{locale => l10n}/locale.rs | 0 rust/agama-dbus-server/src/{locale => l10n}/timezone.rs | 0 rust/agama-dbus-server/src/lib.rs | 2 +- rust/agama-dbus-server/src/main.rs | 7 +++++-- 7 files changed, 6 insertions(+), 3 deletions(-) rename rust/agama-dbus-server/src/{locale.rs => l10n.rs} (100%) rename rust/agama-dbus-server/src/{locale => l10n}/helpers.rs (100%) rename rust/agama-dbus-server/src/{locale => l10n}/keyboard.rs (100%) rename rust/agama-dbus-server/src/{locale => l10n}/locale.rs (100%) rename rust/agama-dbus-server/src/{locale => l10n}/timezone.rs (100%) diff --git a/rust/agama-dbus-server/src/locale.rs b/rust/agama-dbus-server/src/l10n.rs similarity index 100% rename from rust/agama-dbus-server/src/locale.rs rename to rust/agama-dbus-server/src/l10n.rs diff --git a/rust/agama-dbus-server/src/locale/helpers.rs b/rust/agama-dbus-server/src/l10n/helpers.rs similarity index 100% rename from rust/agama-dbus-server/src/locale/helpers.rs rename to rust/agama-dbus-server/src/l10n/helpers.rs diff --git a/rust/agama-dbus-server/src/locale/keyboard.rs b/rust/agama-dbus-server/src/l10n/keyboard.rs similarity index 100% rename from rust/agama-dbus-server/src/locale/keyboard.rs rename to rust/agama-dbus-server/src/l10n/keyboard.rs diff --git a/rust/agama-dbus-server/src/locale/locale.rs b/rust/agama-dbus-server/src/l10n/locale.rs similarity index 100% rename from rust/agama-dbus-server/src/locale/locale.rs rename to rust/agama-dbus-server/src/l10n/locale.rs diff --git a/rust/agama-dbus-server/src/locale/timezone.rs b/rust/agama-dbus-server/src/l10n/timezone.rs similarity index 100% rename from rust/agama-dbus-server/src/locale/timezone.rs rename to rust/agama-dbus-server/src/l10n/timezone.rs diff --git a/rust/agama-dbus-server/src/lib.rs b/rust/agama-dbus-server/src/lib.rs index a4c9dc66c8..5c04239e62 100644 --- a/rust/agama-dbus-server/src/lib.rs +++ b/rust/agama-dbus-server/src/lib.rs @@ -1,4 +1,4 @@ pub mod error; -pub mod locale; +pub mod l10n; pub mod network; pub mod questions; diff --git a/rust/agama-dbus-server/src/main.rs b/rust/agama-dbus-server/src/main.rs index c890f5db71..3145228fd3 100644 --- a/rust/agama-dbus-server/src/main.rs +++ b/rust/agama-dbus-server/src/main.rs @@ -1,4 +1,7 @@ -use agama_dbus_server::{locale, locale::helpers, network, questions}; +use agama_dbus_server::{ + l10n::{self, helpers}, + network, questions, +}; use agama_lib::connection_to; use anyhow::Context; @@ -36,7 +39,7 @@ async fn main() -> Result<(), Box> { // When adding more services here, the order might be important. questions::export_dbus_objects(&connection).await?; log::info!("Started questions interface"); - locale::export_dbus_objects(&connection, &locale).await?; + l10n::export_dbus_objects(&connection, &locale).await?; log::info!("Started locale interface"); network::export_dbus_objects(&connection).await?; log::info!("Started network interface"); From c7d43c88a813ac83174204d3017c11059f0d8059 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Imobach=20Gonz=C3=A1lez=20Sosa?= Date: Wed, 27 Dec 2023 13:20:03 +0000 Subject: [PATCH 3/4] Define some 'types' for D-Bus proxies --- .../src/network/nm/proxies.rs | 12 +----- rust/agama-lib/src/software/proxies.rs | 39 ++++++++++++------- rust/agama-lib/src/users/client.rs | 12 +----- rust/agama-lib/src/users/proxies.rs | 27 ++++++++----- 4 files changed, 48 insertions(+), 42 deletions(-) diff --git a/rust/agama-dbus-server/src/network/nm/proxies.rs b/rust/agama-dbus-server/src/network/nm/proxies.rs index 8bfa6f43bb..fd933a3d9d 100644 --- a/rust/agama-dbus-server/src/network/nm/proxies.rs +++ b/rust/agama-dbus-server/src/network/nm/proxies.rs @@ -12,6 +12,7 @@ //! …consequently `zbus-xmlgen` did not generate code for the above interfaces. //! Also some proxies can be used against multiple services when they share interface. +use agama_lib::dbus::OwnedNestedHash; use zbus::dbus_proxy; #[dbus_proxy( @@ -267,16 +268,7 @@ trait Device { fn disconnect(&self) -> zbus::Result<()>; /// GetAppliedConnection method - fn get_applied_connection( - &self, - flags: u32, - ) -> zbus::Result<( - std::collections::HashMap< - String, - std::collections::HashMap, - >, - u64, - )>; + fn get_applied_connection(&self, flags: u32) -> zbus::Result<(OwnedNestedHash, u64)>; /// Reapply method fn reapply( diff --git a/rust/agama-lib/src/software/proxies.rs b/rust/agama-lib/src/software/proxies.rs index a37cc1b341..e7298f2187 100644 --- a/rust/agama-lib/src/software/proxies.rs +++ b/rust/agama-lib/src/software/proxies.rs @@ -3,6 +3,17 @@ //! This code was generated by `zbus-xmlgen` `3.1.1` from DBus introspection data. use zbus::dbus_proxy; +/// Software patterns map. +/// +/// It uses the pattern name as key and a tuple containing the following information as value: +/// +/// * Category. +/// * Description. +/// * Icon. +/// * Summary. +/// * Order. +pub type PatternsMap = std::collections::HashMap; + #[dbus_proxy( interface = "org.opensuse.Agama.Software1", default_service = "org.opensuse.Agama.Software1", @@ -22,10 +33,7 @@ trait Software1 { fn is_package_installed(&self, name: &str) -> zbus::Result; /// ListPatterns method - fn list_patterns( - &self, - filtered: bool, - ) -> zbus::Result>; + fn list_patterns(&self, filtered: bool) -> zbus::Result; /// Probe method fn probe(&self) -> zbus::Result<()>; @@ -50,6 +58,19 @@ trait Software1 { fn selected_patterns(&self) -> zbus::Result>; } +/// Product definition. +/// +/// It is composed of the following elements: +/// +/// * Product ID. +/// * Display name. +/// * Some additional data which includes a "description" key. +pub type Product = ( + String, + String, + std::collections::HashMap, +); + #[dbus_proxy( interface = "org.opensuse.Agama.Software1.Product", default_service = "org.opensuse.Agama.Software1", @@ -61,15 +82,7 @@ trait SoftwareProduct { /// AvailableProducts property #[dbus_proxy(property)] - fn available_products( - &self, - ) -> zbus::Result< - Vec<( - String, - String, - std::collections::HashMap, - )>, - >; + fn available_products(&self) -> zbus::Result>; /// SelectedProduct property #[dbus_proxy(property)] diff --git a/rust/agama-lib/src/users/client.rs b/rust/agama-lib/src/users/client.rs index d510b20fd0..437ff3f21d 100644 --- a/rust/agama-lib/src/users/client.rs +++ b/rust/agama-lib/src/users/client.rs @@ -1,6 +1,6 @@ //! Implements a client to access Agama's users service. -use super::proxies::Users1Proxy; +use super::proxies::{FirstUser as FirstUserFromDBus, Users1Proxy}; use crate::error::ServiceError; use agama_settings::{settings::Settings, SettingValue, SettingsError}; use serde::Serialize; @@ -22,15 +22,7 @@ pub struct FirstUser { } impl FirstUser { - pub fn from_dbus( - dbus_data: zbus::Result<( - String, - String, - String, - bool, - std::collections::HashMap, - )>, - ) -> zbus::Result { + pub fn from_dbus(dbus_data: zbus::Result) -> zbus::Result { let data = dbus_data?; Ok(Self { full_name: data.0, diff --git a/rust/agama-lib/src/users/proxies.rs b/rust/agama-lib/src/users/proxies.rs index f1a71a2825..6e2793fd2f 100644 --- a/rust/agama-lib/src/users/proxies.rs +++ b/rust/agama-lib/src/users/proxies.rs @@ -3,6 +3,23 @@ //! This code was generated by `zbus-xmlgen` `3.1.0` from DBus introspection data.`. use zbus::dbus_proxy; +/// First user as it comes from D-Bus. +/// +/// It is composed of: +/// +/// * full name +/// * user name +/// * password +/// * auto-login (enabled or not) +/// * some optional and additional data +pub type FirstUser = ( + String, + String, + String, + bool, + std::collections::HashMap, +); + #[dbus_proxy( interface = "org.opensuse.Agama.Users1", default_service = "org.opensuse.Agama.Manager1", @@ -37,15 +54,7 @@ trait Users1 { /// FirstUser property #[dbus_proxy(property)] - fn first_user( - &self, - ) -> zbus::Result<( - String, - String, - String, - bool, - std::collections::HashMap, - )>; + fn first_user(&self) -> zbus::Result; /// RootPasswordSet property #[dbus_proxy(property)] From d5860fabccfa85232a42efffede0039fedf06c29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Imobach=20Gonz=C3=A1lez=20Sosa?= Date: Wed, 27 Dec 2023 13:29:37 +0000 Subject: [PATCH 4/4] Run Clippy in CI --- .github/workflows/ci-rust.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci-rust.yml b/.github/workflows/ci-rust.yml index 6094cf6f84..a4576120bd 100644 --- a/.github/workflows/ci-rust.yml +++ b/.github/workflows/ci-rust.yml @@ -78,6 +78,12 @@ jobs: - name: Install Rust toolchains run: rustup toolchain install stable + - name: Run clippy linter + run: cargo clippy + + - name: Run rustfmt + run: cargo fmt --all -- --check + - name: Install cargo-binstall uses: taiki-e/install-action@v2 with: @@ -89,9 +95,6 @@ jobs: - name: Run the tests run: cargo tarpaulin --out xml - - name: Lint formatting - run: cargo fmt --all -- --check - # send the code coverage for the Rust part to the coveralls.io - name: Coveralls GitHub Action uses: coverallsapp/github-action@v2