Skip to content

Commit

Permalink
Fix Clippy await_holding_lock
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed Aug 11, 2023
1 parent 4df4c55 commit 645bbe1
Showing 1 changed file with 26 additions and 12 deletions.
38 changes: 26 additions & 12 deletions rust/agama-dbus-server/src/network/dbus/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,18 @@ impl Tree {
///
/// * `id`: connection ID.
pub async fn remove_connection(&mut self, id: &str) -> Result<(), ServiceError> {
let mut objects = self.objects.lock();
let Some(path) = objects.connection_path(id) else {
return Ok(())
};
self.remove_connection_on(path.as_str()).await?;
objects.deregister_connection(id).unwrap();
let cloned_path;

{
let mut objects = self.objects.lock();
let Some(path) = objects.connection_path(id) else {
return Ok(())
};
cloned_path = path.to_string();
objects.deregister_connection(id).unwrap();
}

self.remove_connection_on(&cloned_path).await?;
Ok(())
}

Expand All @@ -142,24 +148,32 @@ impl Tree {

/// Clears all the connections from the tree.
async fn remove_connections(&self) -> Result<(), ServiceError> {
let mut objects = self.objects.lock();
for path in objects.connections.values() {
let paths: Vec<_>;
{
let mut objects = self.objects.lock();
objects.connections.clear();
paths = objects.connections.values().cloned().collect();
}
for path in paths {
self.remove_connection_on(path.as_str()).await?;
}
objects.connections.clear();
Ok(())
}

/// Clears all the devices from the tree.
async fn remove_devices(&mut self) -> Result<(), ServiceError> {
let paths: Vec<_>;
let object_server = self.connection.object_server();
let mut objects = self.objects.lock();
for path in objects.devices.values() {
{
let mut objects = self.objects.lock();
objects.devices.clear();
paths = objects.connections.values().cloned().collect();
}
for path in paths {
object_server
.remove::<interfaces::Device, _>(path.as_str())
.await?;
}
objects.devices.clear();
Ok(())
}

Expand Down

0 comments on commit 645bbe1

Please sign in to comment.