Skip to content

Commit

Permalink
Update Secret Service read_alias(), set_alias() and collections()
Browse files Browse the repository at this point in the history
These changes update Secret Service alias methods and collections property
to be async and fix the following errors,
"`await` is only allowed inside `async` functions and blocks",
"cannot return value referencing temporary value"

Signed-off-by: Dhanuka Warusadura <[email protected]>
  • Loading branch information
warusadura committed Feb 19, 2024
1 parent d16b4eb commit 7d584ae
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions server/src/daemon/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,26 +194,34 @@ impl Service {
Ok(secrets)
}

pub fn read_alias(&self, name: &str) -> ObjectPath {
pub async fn read_alias(&self, name: &str) -> ObjectPath {
self.collections
.read()
.await
.iter()
.find_map(|c| {
if c.label() == name {
Some(c.path())
Some(c.path().to_owned())
} else {
None
}
})
.unwrap_or_default()
}

pub fn set_alias(
pub async fn set_alias(
&self,
#[zbus(signal_context)] ctxt: SignalContext<'_>,
alias: &str,
path: ObjectPath<'_>,
) -> Result<()> {
match self.collections.iter().find(|c| c.path() == path) {
match self
.collections
.read()
.await
.iter()
.find(|c| c.path() == path)
{
Some(collection) => {
collection.set_alias(&ctxt, alias).await?;
Ok(())
Expand All @@ -231,7 +239,7 @@ impl Service {
.read()
.await
.iter()
.map(|collection| collection.path())
.map(|collection| collection.path().to_owned())
.collect()
}

Expand Down

0 comments on commit 7d584ae

Please sign in to comment.