Skip to content

Commit bf8c8af

Browse files
apply cr
1 parent 53565f0 commit bf8c8af

File tree

7 files changed

+22
-27
lines changed

7 files changed

+22
-27
lines changed

src/accounts.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ impl Accounts {
101101
let account_config = self.config.new_account(&self.dir).await?;
102102

103103
let ctx = Context::new(
104-
account_config.dbfile(),
104+
&account_config.dbfile(),
105105
account_config.id,
106106
self.events.clone(),
107107
)
@@ -116,7 +116,7 @@ impl Accounts {
116116
let account_config = self.config.new_account(&self.dir).await?;
117117

118118
let ctx = Context::new_closed(
119-
account_config.dbfile(),
119+
&account_config.dbfile(),
120120
account_config.id,
121121
self.events.clone(),
122122
)
@@ -204,7 +204,7 @@ impl Accounts {
204204

205205
match res {
206206
Ok(_) => {
207-
let ctx = Context::new(new_dbfile, account_config.id, self.events.clone()).await?;
207+
let ctx = Context::new(&new_dbfile, account_config.id, self.events.clone()).await?;
208208
self.accounts.insert(account_config.id, ctx);
209209
Ok(account_config.id)
210210
}
@@ -342,7 +342,7 @@ impl Config {
342342
pub async fn load_accounts(&self, events: &Events) -> Result<BTreeMap<u32, Context>> {
343343
let mut accounts = BTreeMap::new();
344344
for account_config in &self.inner.accounts {
345-
let ctx = Context::new(account_config.dbfile(), account_config.id, events.clone())
345+
let ctx = Context::new(&account_config.dbfile(), account_config.id, events.clone())
346346
.await
347347
.with_context(|| {
348348
format!(
@@ -523,7 +523,7 @@ mod tests {
523523
assert_eq!(accounts.config.get_selected_account().await, 0);
524524

525525
let extern_dbfile: PathBuf = dir.path().join("other");
526-
let ctx = Context::new(extern_dbfile.clone(), 0, Events::new())
526+
let ctx = Context::new(&extern_dbfile, 0, Events::new())
527527
.await
528528
.unwrap();
529529
ctx.set_config(crate::config::Config::Addr, Some("[email protected]"))

src/context.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ pub fn get_info() -> BTreeMap<&'static str, String> {
114114

115115
impl Context {
116116
/// Creates new context and opens the database.
117-
pub async fn new<P: AsRef<Path>>(dbfile: P, id: u32, events: Events) -> Result<Context> {
117+
pub async fn new(dbfile: &Path, id: u32, events: Events) -> Result<Context> {
118118
let context = Self::new_closed(dbfile, id, events).await?;
119119

120120
// Open the database if is not encrypted.
@@ -125,9 +125,8 @@ impl Context {
125125
}
126126

127127
/// Creates new context without opening the database.
128-
pub async fn new_closed<P: AsRef<Path>>(dbfile: P, id: u32, events: Events) -> Result<Context> {
128+
pub async fn new_closed(dbfile: &Path, id: u32, events: Events) -> Result<Context> {
129129
let mut blob_fname = OsString::new();
130-
let dbfile = dbfile.as_ref();
131130
blob_fname.push(dbfile.file_name().unwrap_or_default());
132131
blob_fname.push("-blobs");
133132
let blobdir = dbfile.with_file_name(blob_fname);
@@ -684,7 +683,7 @@ mod tests {
684683
let tmp = tempfile::tempdir()?;
685684
let dbfile = tmp.path().join("db.sqlite");
686685
std::fs::write(&dbfile, b"123")?;
687-
let res = Context::new(dbfile, 1, Events::new()).await?;
686+
let res = Context::new(&dbfile, 1, Events::new()).await?;
688687

689688
// Broken database is indistinguishable from encrypted one.
690689
assert_eq!(res.is_open().await, false);
@@ -830,7 +829,7 @@ mod tests {
830829
async fn test_blobdir_exists() {
831830
let tmp = tempfile::tempdir().unwrap();
832831
let dbfile = tmp.path().join("db.sqlite");
833-
Context::new(dbfile, 1, Events::new()).await.unwrap();
832+
Context::new(&dbfile, 1, Events::new()).await.unwrap();
834833
let blobdir = tmp.path().join("db.sqlite-blobs");
835834
assert!(blobdir.is_dir());
836835
}
@@ -841,7 +840,7 @@ mod tests {
841840
let dbfile = tmp.path().join("db.sqlite");
842841
let blobdir = tmp.path().join("db.sqlite-blobs");
843842
std::fs::write(&blobdir, b"123").unwrap();
844-
let res = Context::new(dbfile, 1, Events::new()).await;
843+
let res = Context::new(&dbfile, 1, Events::new()).await;
845844
assert!(res.is_err());
846845
}
847846

@@ -851,7 +850,7 @@ mod tests {
851850
let subdir = tmp.path().join("subdir");
852851
let dbfile = subdir.join("db.sqlite");
853852
let dbfile2 = dbfile.clone();
854-
Context::new(dbfile, 1, Events::new()).await.unwrap();
853+
Context::new(&dbfile, 1, Events::new()).await.unwrap();
855854
assert!(subdir.is_dir());
856855
assert!(dbfile2.is_file());
857856
}

src/dc_tools.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ pub fn dc_get_filemeta(buf: &[u8]) -> Result<(u32, u32), Error> {
277277
///
278278
/// If `path` starts with "$BLOBDIR", replaces it with the blobdir path.
279279
/// Otherwise, returns path as is.
280-
pub(crate) fn dc_get_abs_path<P: AsRef<Path>>(context: &Context, path: P) -> PathBuf {
280+
pub(crate) fn dc_get_abs_path(context: &Context, path: impl AsRef<Path>) -> PathBuf {
281281
let p: &Path = path.as_ref();
282282
if let Ok(p) = p.strip_prefix("$BLOBDIR") {
283283
context.get_blobdir().join(p)

src/key.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,8 @@ async fn generate_keypair(context: &Context) -> Result<KeyPair> {
222222
info!(context, "Generating keypair with type {}", keytype);
223223
let keypair = Handle::current()
224224
.spawn_blocking(move || crate::pgp::create_keypair(addr, keytype))
225-
.await
226-
.unwrap()?;
225+
.await??;
226+
227227
store_self_keypair(context, &keypair, KeyPairUse::Default).await?;
228228
info!(
229229
context,

src/pgp.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,7 @@ pub async fn pk_encrypt(
251251

252252
Ok(encoded_msg)
253253
})
254-
.await
255-
.unwrap()
254+
.await?
256255
}
257256

258257
/// Decrypts the message with keys from the private key keyring.
@@ -280,8 +279,7 @@ pub async fn pk_decrypt(
280279
let (decryptor, _) = msg.decrypt(|| "".into(), || "".into(), &skeys[..])?;
281280
decryptor.collect::<pgp::errors::Result<Vec<_>>>()
282281
})
283-
.await
284-
.unwrap()?;
282+
.await??;
285283

286284
if let Some(msg) = msgs.into_iter().next() {
287285
// get_content() will decompress the message if needed,
@@ -356,8 +354,7 @@ pub async fn symm_encrypt(passphrase: &str, plain: &[u8]) -> Result<String> {
356354

357355
Ok(encoded_msg)
358356
})
359-
.await
360-
.unwrap()
357+
.await?
361358
}
362359

363360
/// Symmetric decryption.
@@ -381,8 +378,7 @@ pub async fn symm_decrypt<T: std::io::Read + std::io::Seek>(
381378
bail!("No valid messages found")
382379
}
383380
})
384-
.await
385-
.unwrap()
381+
.await?
386382
}
387383

388384
#[cfg(test)]

src/provider.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ pub struct Provider {
8585

8686
/// Get resolver to query MX records.
8787
///
88-
/// We first try resolver_from_system_conf() which reads the system's resolver from `/etc/resolv.conf`.
89-
/// This does not work at least on some Androids, therefore we use use ResolverConfig::default()
90-
/// which default eg. to google's 8.8.8.8 or 8.8.4.4 as a fallback.
88+
/// We first try reads the system's resolver from `/etc/resolv.conf`.
89+
/// This does not work at least on some Androids, therefore we fallback
90+
/// to the default `ResolverConfig` which uses eg. to google's `8.8.8.8` or `8.8.4.4`.
9191
fn get_resolver() -> Result<TokioAsyncResolver> {
9292
if let Ok(resolver) = AsyncResolver::tokio_from_system_conf() {
9393
return Ok(resolver);

src/test_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ impl TestContext {
277277
let mut context_names = CONTEXT_NAMES.write().unwrap();
278278
context_names.insert(id, name);
279279
}
280-
let ctx = Context::new(dbfile, id, Events::new())
280+
let ctx = Context::new(&dbfile, id, Events::new())
281281
.await
282282
.expect("failed to create context");
283283

0 commit comments

Comments
 (0)