Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 0 additions & 1 deletion rust/agama-cli/src/printers.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use anyhow;
use serde::Serialize;
use std::fmt::Debug;
use std::io::Write;
Expand Down
2 changes: 1 addition & 1 deletion rust/agama-cli/src/profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fn evaluate(path: String) -> anyhow::Result<()> {
let evaluator = ProfileEvaluator {};
evaluator
.evaluate(Path::new(&path))
.context(format!("Could not evaluate the profile"))?;
.context("Could not evaluate the profile".to_string())?;
Ok(())
}

Expand Down
4 changes: 2 additions & 2 deletions rust/agama-cli/src/progress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl InstallerProgress {
impl ProgressPresenter for InstallerProgress {
fn start(&mut self, progress: &Progress) {
if !progress.finished {
self.update_main(&progress);
self.update_main(progress);
}
}

Expand All @@ -49,7 +49,7 @@ impl ProgressPresenter for InstallerProgress {
bar.finish_and_clear();
}
} else {
self.update_bar(&progress);
self.update_bar(progress);
}
}

Expand Down
9 changes: 4 additions & 5 deletions rust/agama-dbus-server/src/locale.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl Locale {

#[dbus_interface(property)]
fn locales(&self) -> Vec<String> {
return self.locales.to_owned();
self.locales.to_owned()
}

#[dbus_interface(property)]
Expand Down Expand Up @@ -112,16 +112,15 @@ impl Locale {

#[dbus_interface(property, name = "VConsoleKeyboard")]
fn keymap(&self) -> &str {
return &self.keymap.as_str();
self.keymap.as_str()
}

#[dbus_interface(property, name = "VConsoleKeyboard")]
fn set_keymap(&mut self, keyboard: &str) -> Result<(), zbus::fdo::Error> {
let exist = agama_locale_data::get_key_maps()
.unwrap()
.iter()
.find(|&k| k == keyboard)
.is_some();
.any(|k| k == keyboard);
if !exist {
return Err(zbus::fdo::Error::Failed(
"Invalid keyboard value".to_string(),
Expand All @@ -141,7 +140,7 @@ impl Locale {

#[dbus_interface(property)]
fn timezone(&self) -> &str {
return &self.timezone_id.as_str();
self.timezone_id.as_str()
}

#[dbus_interface(property)]
Expand Down
8 changes: 4 additions & 4 deletions rust/agama-dbus-server/src/network/dbus/interfaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ impl Connections {
/// * `id`: connection ID.
pub async fn get_connection(&self, id: &str) -> zbus::fdo::Result<OwnedObjectPath> {
let objects = self.objects.lock();
match objects.connection_path(&id) {
match objects.connection_path(id) {
Some(path) => Ok(path.into()),
None => Err(NetworkStateError::UnknownConnection(id.to_string()).into()),
}
Expand Down Expand Up @@ -308,8 +308,8 @@ impl Ipv4 {
.iter()
.map(|addr| addr.parse::<Ipv4Addr>())
.collect::<Result<Vec<Ipv4Addr>, AddrParseError>>()
.and_then(|parsed| Ok(ipv4.nameservers = parsed))
.map_err(|err| NetworkStateError::from(err))?;
.map(|parsed| ipv4.nameservers = parsed)
.map_err(NetworkStateError::from)?;
self.update_connection(connection)
}

Expand All @@ -335,7 +335,7 @@ impl Ipv4 {
} else {
let parsed: Ipv4Addr = gateway
.parse()
.map_err(|err| NetworkStateError::from(err))?;
.map_err(NetworkStateError::from)?;
ipv4.gateway = Some(parsed);
}
self.update_connection(connection)
Expand Down
2 changes: 1 addition & 1 deletion rust/agama-dbus-server/src/network/dbus/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl NetworkService {
connection
.request_name(SERVICE_NAME)
.await
.expect(&format!("Could not request name {SERVICE_NAME}"));
.unwrap_or_else(|_| panic!("Could not request name {SERVICE_NAME}"));

network.listen().await;
})
Expand Down
12 changes: 6 additions & 6 deletions rust/agama-dbus-server/src/network/dbus/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl Tree {
/// * `connections`: list of connections.
pub async fn set_connections(
&self,
connections: &mut Vec<Connection>,
connections: &mut [Connection],
) -> Result<(), ServiceError> {
self.remove_connections().await?;
self.add_connections(connections).await?;
Expand All @@ -49,7 +49,7 @@ impl Tree {
/// Refreshes the list of devices.
///
/// * `devices`: list of devices.
pub async fn set_devices(&mut self, devices: &Vec<Device>) -> Result<(), ServiceError> {
pub async fn set_devices(&mut self, devices: &[Device]) -> Result<(), ServiceError> {
self.remove_devices().await?;
self.add_devices(devices).await?;
Ok(())
Expand All @@ -58,7 +58,7 @@ impl Tree {
/// Adds devices to the D-Bus tree.
///
/// * `devices`: list of devices.
pub async fn add_devices(&mut self, devices: &Vec<Device>) -> Result<(), ServiceError> {
pub async fn add_devices(&mut self, devices: &[Device]) -> Result<(), ServiceError> {
for (i, dev) in devices.iter().enumerate() {
let path = format!("{}/{}", DEVICES_PATH, i);
let path = ObjectPath::try_from(path.as_str()).unwrap();
Expand All @@ -83,7 +83,7 @@ impl Tree {
pub async fn add_connection(&self, conn: &mut Connection) -> Result<(), ServiceError> {
let mut objects = self.objects.lock();

let (id, path) = objects.register_connection(&conn);
let (id, path) = objects.register_connection(conn);
if id != conn.id() {
conn.set_id(&id)
}
Expand Down Expand Up @@ -126,7 +126,7 @@ impl Tree {
/// Adds connections to the D-Bus tree.
///
/// * `connections`: list of connections.
async fn add_connections(&self, connections: &mut Vec<Connection>) -> Result<(), ServiceError> {
async fn add_connections(&self, connections: &mut [Connection]) -> Result<(), ServiceError> {
for conn in connections.iter_mut() {
self.add_connection(conn).await?;
}
Expand Down Expand Up @@ -181,7 +181,7 @@ impl Tree {
T: zbus::Interface,
{
let object_server = self.connection.object_server();
Ok(object_server.at(path.clone(), iface).await?)
Ok(object_server.at(path, iface).await?)
}
}

Expand Down
2 changes: 1 addition & 1 deletion rust/agama-dbus-server/src/network/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ pub enum NetworkStateError {

impl From<NetworkStateError> for zbus::fdo::Error {
fn from(value: NetworkStateError) -> zbus::fdo::Error {
zbus::fdo::Error::Failed(format!("Network error: {}", value.to_string()))
zbus::fdo::Error::Failed(format!("Network error: {value}"))
}
}
12 changes: 5 additions & 7 deletions rust/agama-dbus-server/src/network/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl NetworkState {
///
/// It uses the `id` to decide whether the connection already exists.
pub fn add_connection(&mut self, conn: Connection) -> Result<(), NetworkStateError> {
if let Some(_) = self.get_connection(conn.id()) {
if self.get_connection(conn.id()).is_some() {
return Err(NetworkStateError::ConnectionExists(conn.uuid()));
}

Expand Down Expand Up @@ -206,7 +206,7 @@ pub enum Connection {
impl Connection {
pub fn new(id: String, device_type: DeviceType) -> Self {
let base = BaseConnection {
id: id.to_string(),
id,
..Default::default()
};
match device_type {
Expand Down Expand Up @@ -491,13 +491,11 @@ impl FromStr for IpAddress {
type Err = ParseIpAddressError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
let Some((address, prefix)) = s.split_once("/") else {
let Some((address, prefix)) = s.split_once('/') else {
return Err(ParseIpAddressError::MissingPrefix);
};

let address: Ipv4Addr = address
.parse()
.map_err(|e| ParseIpAddressError::InvalidAddr(e))?;
let address: Ipv4Addr = address.parse().map_err(ParseIpAddressError::InvalidAddr)?;

let prefix: u32 = prefix
.parse()
Expand All @@ -509,6 +507,6 @@ impl FromStr for IpAddress {

impl fmt::Display for IpAddress {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}/{}", self.0.to_string(), self.1)
write!(f, "{}/{}", self.0, self.1)
}
}
11 changes: 3 additions & 8 deletions rust/agama-dbus-server/src/network/nm/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ impl<'a> NetworkManagerAdapter<'a> {
///
/// * `conn`: connection
fn is_writable(conn: &Connection) -> bool {
match conn {
Connection::Loopback(_) => false,
_ => true,
}
matches!(conn, Connection::Loopback(_))
}
}

Expand All @@ -51,10 +48,8 @@ impl<'a> Adapter for NetworkManagerAdapter<'a> {
if let Err(e) = self.client.remove_connection(conn.uuid()).await {
log::error!("Could not remove the connection {}: {}", conn.uuid(), e);
}
} else {
if let Err(e) = self.client.add_or_update_connection(conn).await {
log::error!("Could not add/update the connection {}: {}", conn.uuid(), e);
}
} else if let Err(e) = self.client.add_or_update_connection(conn).await {
log::error!("Could not add/update the connection {}: {}", conn.uuid(), e);
}
}
});
Expand Down
2 changes: 1 addition & 1 deletion rust/agama-dbus-server/src/network/nm/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl<'a> NetworkManagerClient<'a> {
let settings = proxy.get_settings().await?;
// TODO: log an error if a connection is not found
if let Some(connection) = connection_from_dbus(settings) {
connections.push(connection.into());
connections.push(connection);
}
}
Ok(connections)
Expand Down
8 changes: 4 additions & 4 deletions rust/agama-dbus-server/src/network/nm/dbus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ pub fn merge_dbus_connections<'a>(
inner.insert(inner_key, value.clone());
}
}
merged.insert(key.as_str(), inner.into());
merged.insert(key.as_str(), inner);
}
cleanup_dbus_connection(&mut merged);
merged
Expand All @@ -95,7 +95,7 @@ pub fn merge_dbus_connections<'a>(
/// replaced with "address-data". However, if "addresses" is present, it takes precedence.
///
/// * `conn`: connection represented as a NestedHash.
fn cleanup_dbus_connection<'a>(conn: &'a mut NestedHash) {
fn cleanup_dbus_connection(conn: &mut NestedHash) {
if let Some(ipv4) = conn.get_mut("ipv4") {
ipv4.remove("addresses");
ipv4.remove("dns");
Expand Down Expand Up @@ -123,7 +123,7 @@ fn ipv4_to_dbus(ipv4: &Ipv4Config) -> HashMap<&str, zvariant::Value> {
let dns_data: Value = ipv4
.nameservers
.iter()
.map(|ns| ns.to_string().into())
.map(|ns| ns.to_string())
.collect::<Vec<String>>()
.into();

Expand Down Expand Up @@ -263,7 +263,7 @@ mod test {

let address_data = vec![HashMap::from([
("address".to_string(), Value::new("192.168.0.10")),
("prefix".to_string(), Value::new(24 as u32)),
("prefix".to_string(), Value::new(24_u32)),
])];

let ipv4_section = HashMap::from([
Expand Down
14 changes: 4 additions & 10 deletions rust/agama-dbus-server/src/network/nm/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl From<&str> for NmWirelessMode {

impl NmWirelessMode {
pub fn as_str(&self) -> &str {
&self.0.as_str()
self.0.as_str()
}
}

Expand Down Expand Up @@ -59,7 +59,7 @@ impl fmt::Display for NmWirelessMode {
/// As we are using the number just to filter wireless devices, using the newtype
/// pattern around an u32 is enough. For proper support, we might replace this
/// struct with an enum.
#[derive(Debug, Clone, Copy)]
#[derive(Debug, Default, Clone, Copy)]
pub struct NmDeviceType(pub u32);

impl From<NmDeviceType> for u32 {
Expand All @@ -74,12 +74,6 @@ impl fmt::Display for NmDeviceType {
}
}

impl Default for NmDeviceType {
fn default() -> Self {
NmDeviceType(0)
}
}

impl TryFrom<NmDeviceType> for DeviceType {
type Error = NmError;

Expand Down Expand Up @@ -131,7 +125,7 @@ impl TryFrom<NmKeyManagement> for SecurityProtocol {

impl NmKeyManagement {
pub fn as_str(&self) -> &str {
&self.0.as_str()
self.0.as_str()
}
}

Expand All @@ -152,7 +146,7 @@ impl Default for NmMethod {

impl NmMethod {
pub fn as_str(&self) -> &str {
&self.0.as_str()
self.0.as_str()
}
}

Expand Down
4 changes: 2 additions & 2 deletions rust/agama-dbus-server/src/questions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ impl LuksQuestion {
}

#[dbus_interface(property)]
pub fn set_password(&mut self, value: &str) -> () {
pub fn set_password(&mut self, value: &str) {
self.password = value.to_string();
}

Expand Down Expand Up @@ -227,7 +227,7 @@ impl Questions {
/// Removes question at given object path
async fn delete(&mut self, question: ObjectPath<'_>) -> Result<(), Error> {
// TODO: error checking
let id: u32 = question.rsplit("/").next().unwrap().parse().unwrap();
let id: u32 = question.rsplit('/').next().unwrap().parse().unwrap();
let qtype = self.questions.get(&id).unwrap();
match qtype {
QuestionType::Generic => {
Expand Down
8 changes: 4 additions & 4 deletions rust/agama-lib/src/network/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ impl<'a> NetworkClient<'a> {
) -> Result<(), ServiceError> {
let path = match self.connections_proxy.get_connection(&conn.id).await {
Ok(path) => path,
Err(_) => self.add_connection(&conn).await?,
Err(_) => self.add_connection(conn).await?,
};
self.update_connection(&path, &conn).await?;
self.update_connection(&path, conn).await?;
Ok(())
}

Expand Down Expand Up @@ -150,11 +150,11 @@ impl<'a> NetworkClient<'a> {
let nameservers: Vec<_> = conn.nameservers.iter().map(String::as_ref).collect();
proxy.set_nameservers(nameservers.as_slice()).await?;

let gateway = conn.gateway.as_ref().map(|g| g.as_str()).unwrap_or("");
let gateway = conn.gateway.as_deref().unwrap_or("");
proxy.set_gateway(gateway).await?;

if let Some(ref wireless) = conn.wireless {
self.update_wireless_settings(&path, wireless).await?;
self.update_wireless_settings(path, wireless).await?;
}
Ok(())
}
Expand Down
7 changes: 2 additions & 5 deletions rust/agama-lib/src/network/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,12 @@ impl<'a> NetworkStore<'a> {
pub async fn load(&self) -> Result<NetworkSettings, ServiceError> {
let connections = self.network_client.connections().await?;

Ok(NetworkSettings {
connections,
..Default::default()
})
Ok(NetworkSettings { connections })
}

pub async fn store(&self, settings: &NetworkSettings) -> Result<(), ServiceError> {
for conn in &settings.connections {
self.network_client.add_or_update_connection(&conn).await?;
self.network_client.add_or_update_connection(conn).await?;
}
self.network_client.apply().await?;

Expand Down
Loading