mirror of
https://github.com/chatmail/core.git
synced 2026-05-22 16:26:31 +03:00
(dig,hpk) add test and fix for wrong dbs
This commit is contained in:
@@ -558,12 +558,7 @@ impl Imap {
|
|||||||
Some(ref mut session) => {
|
Some(ref mut session) => {
|
||||||
if let Ok(caps) = session.capabilities() {
|
if let Ok(caps) = session.capabilities() {
|
||||||
if !context.sql.is_open() {
|
if !context.sql.is_open() {
|
||||||
warn!(
|
warn!(context, 0, "IMAP-LOGIN as {} ok but ABORTING", lp.mail_user,);
|
||||||
context,
|
|
||||||
0,
|
|
||||||
"IMAP-LOGIN as {} ok but ABORTING",
|
|
||||||
lp.mail_user,
|
|
||||||
);
|
|
||||||
teardown = true;
|
teardown = true;
|
||||||
} else {
|
} else {
|
||||||
let can_idle = caps.has("IDLE");
|
let can_idle = caps.has("IDLE");
|
||||||
|
|||||||
10
src/sql.rs
10
src/sql.rs
@@ -141,7 +141,7 @@ impl Sql {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn table_exists(&self, name: impl AsRef<str>) -> bool {
|
pub fn table_exists(&self, name: impl AsRef<str>) -> bool {
|
||||||
self.with_conn(|conn| Ok(table_exists(conn, name)))
|
self.with_conn(|conn| table_exists(conn, name))
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -261,16 +261,14 @@ impl Sql {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn table_exists(conn: &Connection, name: impl AsRef<str>) -> bool {
|
fn table_exists(conn: &Connection, name: impl AsRef<str>) -> Result<bool> {
|
||||||
let mut exists = false;
|
let mut exists = false;
|
||||||
conn.pragma(None, "table_info", &format!("{}", name.as_ref()), |_row| {
|
conn.pragma(None, "table_info", &format!("{}", name.as_ref()), |_row| {
|
||||||
// will only be executed if the info was found
|
// will only be executed if the info was found
|
||||||
exists = true;
|
exists = true;
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})?;
|
||||||
.expect("bad sqlite state");
|
Ok(exists)
|
||||||
|
|
||||||
exists
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn open(
|
fn open(
|
||||||
|
|||||||
@@ -998,6 +998,20 @@ fn test_chat() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_wrong_db() {
|
||||||
|
unsafe {
|
||||||
|
let mut ctx = dc_context_new(Some(cb), std::ptr::null_mut(), std::ptr::null_mut());
|
||||||
|
let dir = tempdir().unwrap();
|
||||||
|
let dbfile = dir.path().join("db.sqlite");
|
||||||
|
std::fs::write(&dbfile, b"123").unwrap();
|
||||||
|
|
||||||
|
let dbfile_c = CString::new(dbfile.to_str().unwrap()).unwrap();
|
||||||
|
let res = dc_open(&mut ctx, dbfile_c.as_ptr(), std::ptr::null());
|
||||||
|
assert_eq!(res, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_arr_to_string() {
|
fn test_arr_to_string() {
|
||||||
let arr2: [uint32_t; 4] = [
|
let arr2: [uint32_t; 4] = [
|
||||||
|
|||||||
Reference in New Issue
Block a user