mirror of
https://github.com/chatmail/core.git
synced 2026-05-08 09:26:29 +03:00
apply CR feedback
This commit is contained in:
committed by
Floris Bruynooghe
parent
de1e3e1d4f
commit
c2501258b6
@@ -1,5 +1,5 @@
|
|||||||
use std::ffi::OsString;
|
use std::ffi::OsString;
|
||||||
use std::path::PathBuf;
|
use std::path::{Path, PathBuf};
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
use std::sync::{Arc, Condvar, Mutex, RwLock};
|
use std::sync::{Arc, Condvar, Mutex, RwLock};
|
||||||
|
|
||||||
@@ -38,8 +38,8 @@ use crate::x::*;
|
|||||||
pub type ContextCallback = dyn Fn(&Context, Event, uintptr_t, uintptr_t) -> uintptr_t + Send + Sync;
|
pub type ContextCallback = dyn Fn(&Context, Event, uintptr_t, uintptr_t) -> uintptr_t + Send + Sync;
|
||||||
|
|
||||||
pub struct Context {
|
pub struct Context {
|
||||||
pub dbfile: Arc<RwLock<PathBuf>>,
|
pub(crate) dbfile: PathBuf,
|
||||||
pub blobdir: Arc<RwLock<PathBuf>>,
|
pub(crate) blobdir: PathBuf,
|
||||||
pub sql: Sql,
|
pub sql: Sql,
|
||||||
pub inbox: Arc<RwLock<Imap>>,
|
pub inbox: Arc<RwLock<Imap>>,
|
||||||
pub perform_inbox_jobs_needed: Arc<RwLock<bool>>,
|
pub perform_inbox_jobs_needed: Arc<RwLock<bool>>,
|
||||||
@@ -89,8 +89,8 @@ impl Context {
|
|||||||
blobdir.display()
|
blobdir.display()
|
||||||
);
|
);
|
||||||
let ctx = Context {
|
let ctx = Context {
|
||||||
blobdir: Arc::new(RwLock::new(blobdir)),
|
blobdir,
|
||||||
dbfile: Arc::new(RwLock::new(dbfile)),
|
dbfile,
|
||||||
inbox: Arc::new(RwLock::new({
|
inbox: Arc::new(RwLock::new({
|
||||||
Imap::new(
|
Imap::new(
|
||||||
cb_get_config,
|
cb_get_config,
|
||||||
@@ -133,18 +133,21 @@ impl Context {
|
|||||||
perform_inbox_jobs_needed: Arc::new(RwLock::new(false)),
|
perform_inbox_jobs_needed: Arc::new(RwLock::new(false)),
|
||||||
generating_key_mutex: Mutex::new(()),
|
generating_key_mutex: Mutex::new(()),
|
||||||
};
|
};
|
||||||
if !ctx.sql.open(&ctx, &ctx.dbfile.read().unwrap(), 0) {
|
|
||||||
return Err(format_err!("Failed opening sqlite database"));
|
ensure!(
|
||||||
}
|
ctx.sql.open(&ctx, &ctx.dbfile, 0),
|
||||||
|
"Failed opening sqlite database"
|
||||||
|
);
|
||||||
|
|
||||||
Ok(ctx)
|
Ok(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_dbfile(&self) -> PathBuf {
|
pub fn get_dbfile(&self) -> &Path {
|
||||||
self.dbfile.clone().read().unwrap().clone()
|
self.dbfile.as_path()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_blobdir(&self) -> PathBuf {
|
pub fn get_blobdir(&self) -> &Path {
|
||||||
self.blobdir.clone().read().unwrap().clone()
|
self.blobdir.as_path()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn call_cb(&self, event: Event, data1: uintptr_t, data2: uintptr_t) -> uintptr_t {
|
pub fn call_cb(&self, event: Event, data1: uintptr_t, data2: uintptr_t) -> uintptr_t {
|
||||||
|
|||||||
@@ -53,7 +53,11 @@ unsafe fn stress_functions(context: &Context) {
|
|||||||
7i32 as libc::c_ulonglong
|
7i32 as libc::c_ulonglong
|
||||||
);
|
);
|
||||||
|
|
||||||
let abs_path = format!("{}/foobar", context.get_blobdir().to_string_lossy());
|
let abs_path = context
|
||||||
|
.get_blobdir()
|
||||||
|
.join("foobar")
|
||||||
|
.to_string_lossy()
|
||||||
|
.to_string();
|
||||||
|
|
||||||
assert!(dc_is_blobdir_path(context, &abs_path));
|
assert!(dc_is_blobdir_path(context, &abs_path));
|
||||||
assert!(dc_is_blobdir_path(context, "$BLOBDIR/fofo",));
|
assert!(dc_is_blobdir_path(context, "$BLOBDIR/fofo",));
|
||||||
|
|||||||
Reference in New Issue
Block a user