diff --git a/.gitignore b/.gitignore index a19cda836..9f02e71d5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,6 @@ /target **/*.rs.bk Cargo.lock -*.db # ignore vi temporaries *~ diff --git a/Cargo.toml b/Cargo.toml index 580961258..7849aca1d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,15 +22,18 @@ reqwest = "0.9.15" num-derive = "0.2.5" num-traits = "0.2.6" +[dev-dependencies] +tempfile = "3.0.7" + [workspace] members = [ "deltachat-ffi" ] - [[example]] name = "simple" [[example]] name = "repl" path = "examples/repl/main.rs" + diff --git a/examples/simple.rs b/examples/simple.rs index 93af71221..24d54dfae 100644 --- a/examples/simple.rs +++ b/examples/simple.rs @@ -2,6 +2,7 @@ extern crate deltachat; use std::ffi::{CStr, CString}; use std::ptr::NonNull; +use tempfile::tempdir; use deltachat::constants::Event; use deltachat::dc_chat::*; @@ -73,24 +74,24 @@ fn main() { dc_perform_smtp_idle(sendable_ctx.0.as_ptr()); }); - let dbfile = CString::new("../deltachat-core/build/hello2.db").unwrap(); - println!("opening dir"); + let dir = tempdir().unwrap(); + let dbfile = CString::new(dir.path().join("db.sqlite").to_str().unwrap()).unwrap(); + + println!("opening database {:?}", dbfile); dc_open(ctx, dbfile.as_ptr(), std::ptr::null()); - if dc_is_configured(ctx) == 0 { - println!("configuring"); - dc_set_config( - ctx, - CString::new("addr").unwrap().as_ptr(), - CString::new("d@testrun.org").unwrap().as_ptr(), - ); - dc_set_config( - ctx, - CString::new("mail_pw").unwrap().as_ptr(), - CString::new("***").unwrap().as_ptr(), - ); - dc_configure(ctx); - } + println!("configuring"); + dc_set_config( + ctx, + CString::new("addr").unwrap().as_ptr(), + CString::new("d@testrun.org").unwrap().as_ptr(), + ); + dc_set_config( + ctx, + CString::new("mail_pw").unwrap().as_ptr(), + CString::new("***").unwrap().as_ptr(), + ); + dc_configure(ctx); std::thread::sleep_ms(4000);