Skip to content

Commit afe584d

Browse files
A6GibKmbilelmoussaoui
authored andcommitted
server: clean remaining &OwnedObjectPath
1 parent 19d0f9c commit afe584d

3 files changed

Lines changed: 21 additions & 19 deletions

File tree

server/src/gnome/prompter.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::sync::Arc;
33
use oo7::{Key, ashpd::WindowIdentifierType, dbus::ServiceError};
44
use serde::{Deserialize, Serialize};
55
use tokio::sync::OnceCell;
6-
use zbus::zvariant::{self, Optional, OwnedObjectPath, Type, as_value};
6+
use zbus::zvariant::{self, ObjectPath, Optional, OwnedObjectPath, Type, as_value};
77

88
use super::secret_exchange;
99
use crate::{
@@ -126,17 +126,17 @@ enum PromptType {
126126
gen_blocking = false
127127
)]
128128
pub trait Prompter {
129-
fn begin_prompting(&self, callback: &OwnedObjectPath) -> Result<(), ServiceError>;
129+
fn begin_prompting(&self, callback: &ObjectPath<'_>) -> Result<(), ServiceError>;
130130

131131
fn perform_prompt(
132132
&self,
133-
callback: OwnedObjectPath,
133+
callback: &ObjectPath<'_>,
134134
type_: PromptType,
135135
properties: Properties,
136136
exchange: &str,
137137
) -> Result<(), ServiceError>;
138138

139-
fn stop_prompting(&self, callback: OwnedObjectPath) -> Result<(), ServiceError>;
139+
fn stop_prompting(&self, callback: &ObjectPath<'_>) -> Result<(), ServiceError>;
140140
}
141141

142142
#[derive(Debug, Clone)]
@@ -178,7 +178,8 @@ impl PrompterCallback {
178178
}
179179
// Dismissed prompt
180180
Some(Reply::No) => {
181-
self.prompter_dismissed(prompt.path()).await?;
181+
self.prompter_dismissed(prompt.path().clone().into())
182+
.await?;
182183
}
183184
};
184185
Ok(())
@@ -224,7 +225,7 @@ impl PrompterCallback {
224225
})
225226
}
226227

227-
pub fn path(&self) -> &OwnedObjectPath {
228+
pub fn path(&self) -> &ObjectPath<'_> {
228229
&self.path
229230
}
230231

@@ -265,7 +266,7 @@ impl PrompterCallback {
265266
let exchange = self.exchange.get().unwrap().clone();
266267
tokio::spawn(async move {
267268
prompter
268-
.perform_prompt(path, prompt_type, properties, &exchange)
269+
.perform_prompt(&path, prompt_type, properties, &exchange)
269270
.await
270271
});
271272
Ok(())
@@ -319,7 +320,7 @@ impl PrompterCallback {
319320
tokio::spawn(async move {
320321
prompter
321322
.perform_prompt(
322-
path,
323+
&path,
323324
PromptType::Password,
324325
properties,
325326
&server_exchange,
@@ -340,9 +341,10 @@ impl PrompterCallback {
340341
}
341342

342343
let path = self.path.clone();
343-
tokio::spawn(async move { prompter.stop_prompting(path).await });
344+
let prompt_path = OwnedObjectPath::from(prompt.path().clone());
345+
tokio::spawn(async move { prompter.stop_prompting(&path).await });
344346

345-
let signal_emitter = self.service.signal_emitter(prompt.path().clone())?;
347+
let signal_emitter = self.service.signal_emitter(prompt_path)?;
346348
let result = zvariant::Value::new(prompt.objects())
347349
.try_to_owned()
348350
.unwrap();
@@ -372,18 +374,18 @@ impl PrompterCallback {
372374
.map(|(parent, _)| parent)?;
373375
let collection = self
374376
.service
375-
.collection_from_path(&OwnedObjectPath::try_from(path).unwrap())
377+
.collection_from_path(&ObjectPath::try_from(path).unwrap())
376378
.await?;
377379

378380
Some(collection.label().await)
379381
}
380382

381-
async fn prompter_dismissed(&self, prompt_path: &OwnedObjectPath) -> Result<(), ServiceError> {
383+
async fn prompter_dismissed(&self, prompt_path: OwnedObjectPath) -> Result<(), ServiceError> {
382384
let path = self.path.clone();
383385
let prompter = PrompterProxy::new(self.service.connection()).await?;
384386

385-
tokio::spawn(async move { prompter.stop_prompting(path).await });
386-
let signal_emitter = self.service.signal_emitter(prompt_path.clone())?;
387+
tokio::spawn(async move { prompter.stop_prompting(&path).await });
388+
let signal_emitter = self.service.signal_emitter(prompt_path)?;
387389
let result = zvariant::Value::new::<Vec<OwnedObjectPath>>(vec![])
388390
.try_to_owned()
389391
.unwrap();

server/src/prompt.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use tokio::sync::OnceCell;
77
use zbus::{
88
interface,
99
object_server::SignalEmitter,
10-
zvariant::{Optional, OwnedObjectPath, OwnedValue},
10+
zvariant::{ObjectPath, Optional, OwnedObjectPath, OwnedValue},
1111
};
1212

1313
use crate::{
@@ -66,7 +66,7 @@ impl Prompt {
6666
custom_service_error(&format!("Failed to create PrompterCallback {err}."))
6767
})?;
6868

69-
let path = callback.path().clone();
69+
let path = OwnedObjectPath::from(callback.path().clone());
7070

7171
self.callback
7272
.set(callback.clone())
@@ -120,7 +120,7 @@ impl Prompt {
120120
}
121121
}
122122

123-
pub fn path(&self) -> &OwnedObjectPath {
123+
pub fn path(&self) -> &ObjectPath<'_> {
124124
&self.path
125125
}
126126

server/src/service.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ impl Service {
152152
let (unlocked, not_unlocked) = self.set_locked(false, &objects, false).await?;
153153
if !not_unlocked.is_empty() {
154154
let prompt = Prompt::new(self.clone(), not_unlocked, PromptRole::Unlock).await;
155-
let path = prompt.path().clone();
155+
let path = OwnedObjectPath::from(prompt.path().clone());
156156
self.prompts
157157
.lock()
158158
.await
@@ -173,7 +173,7 @@ impl Service {
173173
let (locked, not_locked) = self.set_locked(true, &objects, false).await?;
174174
if !not_locked.is_empty() {
175175
let prompt = Prompt::new(self.clone(), not_locked, PromptRole::Lock).await;
176-
let path = prompt.path().clone();
176+
let path = OwnedObjectPath::from(prompt.path().clone());
177177
self.prompts
178178
.lock()
179179
.await

0 commit comments

Comments
 (0)