Skip to content

Commit

Permalink
Wraps manager field inside Mutex
Browse files Browse the repository at this point in the history
So, we can mutate manager.sessions via insert_session() and remove_session()
Also, updates open_session() to insert the newly created session to
manager.sessions

Signed-off-by: Dhanuka Warusadura <dhanuka@gnome.org>
  • Loading branch information
warusadura committed Feb 21, 2024
1 parent d3d7410 commit 01d1fa7
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
6 changes: 3 additions & 3 deletions server/src/daemon/collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use std::{
collections::HashMap,
sync::{atomic::AtomicBool, Arc},
sync::{atomic::AtomicBool, Arc, Mutex},
time::Duration,
};

Expand All @@ -29,7 +29,7 @@ pub struct Collection {
locked: AtomicBool,
created: Duration,
modified: Duration,
manager: Arc<ServiceManager>,
manager: Arc<Mutex<ServiceManager>>,
path: OwnedObjectPath,
}

Expand Down Expand Up @@ -139,7 +139,7 @@ impl Collection {
alias: &str,
created: Duration,
keyring: Arc<Keyring>,
manager: Arc<ServiceManager>,
manager: Arc<Mutex<ServiceManager>>,
) -> Self {
Self {
items: Default::default(),
Expand Down
9 changes: 6 additions & 3 deletions server/src/daemon/item.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// org.freedesktop.Secret.Item

use std::{collections::HashMap, sync::Arc};
use std::{
collections::HashMap,
sync::{Arc, Mutex},
};

use oo7::{
dbus::api::SecretInner,
Expand All @@ -24,7 +27,7 @@ pub struct Item {
path: OwnedObjectPath,
keyring: Arc<Keyring>,
locked: bool,
manager: Arc<ServiceManager>,
manager: Arc<Mutex<ServiceManager>>,
}

#[zbus::interface(name = "org.freedesktop.Secret.Item")]
Expand Down Expand Up @@ -110,7 +113,7 @@ impl Item {
item: portal::Item,
collection_path: ObjectPath<'_>,
keyring: Arc<Keyring>,
manager: Arc<ServiceManager>,
manager: Arc<Mutex<ServiceManager>>,
) -> Self {
Self {
path: OwnedObjectPath::try_from(format!("{}/items/{}", collection_path, item.label(),))
Expand Down
9 changes: 7 additions & 2 deletions server/src/daemon/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub struct Service {
collections: RwLock<Vec<Collection>>,
keyring: Arc<Keyring>,
cnx: Mutex<Option<zbus::Connection>>,
manager: Arc<ServiceManager>,
manager: Arc<Mutex<ServiceManager>>,
}

#[zbus::interface(name = "org.freedesktop.Secret.Service")]

Check failure on line 37 in server/src/daemon/service.rs

View workflow job for this annotation

GitHub Actions / Clippy

future cannot be sent between threads safely

Check failure on line 37 in server/src/daemon/service.rs

View workflow job for this annotation

GitHub Actions / Check

future cannot be sent between threads safely
Expand All @@ -48,6 +48,11 @@ impl Service {
let (session, key) = Session::new(client_public_key, Arc::clone(&self.manager));
// TODO: clean up the default generated key
// TODO call self.manager.set_sessions();
self.manager
.lock()
.unwrap()
.insert_session(session.path().to_owned(), session.to_owned())
.await;
let key = key
.map(|k| OwnedValue::from(&k))
.unwrap_or_else(|| Value::new::<Vec<u8>>(vec![]).try_to_owned().unwrap());
Expand Down Expand Up @@ -268,7 +273,7 @@ impl Service {
collections: RwLock::new(Vec::new()),
keyring: Arc::new(Keyring::load_default().await.unwrap()),
cnx: Default::default(),
manager: Arc::new(ServiceManager::new()),
manager: Arc::new(Mutex::new(ServiceManager::new())),
}
}

Expand Down
6 changes: 3 additions & 3 deletions server/src/daemon/session.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// org.freedesktop.Secret.Session

use std::sync::Arc;
use std::sync::{Arc, Mutex};

use oo7::Key;
use zbus::{fdo, interface, zvariant};
Expand All @@ -11,7 +11,7 @@ use super::service_manager::ServiceManager;
#[derive(Debug, Clone)]
pub struct Session {
client_public_key: Arc<Option<Key>>,
manager: Arc<ServiceManager>,
manager: Arc<Mutex<ServiceManager>>,
pub path: OwnedObjectPath,
}

Expand All @@ -29,7 +29,7 @@ impl Session {
impl Session {
pub fn new(
client_public_key: Option<Key>,
manager: Arc<ServiceManager>,
manager: Arc<Mutex<ServiceManager>>,
) -> (Self, Option<Key>) {
// make use of the keys
let service_key = vec![0];
Expand Down

0 comments on commit 01d1fa7

Please sign in to comment.