chore: use a temporary path for db in example

This commit is contained in:
Lars-Magnus Skog
2019-04-27 23:20:46 +02:00
parent e7ee16e709
commit ab2efb71cc
3 changed files with 21 additions and 18 deletions

1
.gitignore vendored
View File

@@ -1,7 +1,6 @@
/target /target
**/*.rs.bk **/*.rs.bk
Cargo.lock Cargo.lock
*.db
# ignore vi temporaries # ignore vi temporaries
*~ *~

View File

@@ -22,15 +22,18 @@ reqwest = "0.9.15"
num-derive = "0.2.5" num-derive = "0.2.5"
num-traits = "0.2.6" num-traits = "0.2.6"
[dev-dependencies]
tempfile = "3.0.7"
[workspace] [workspace]
members = [ members = [
"deltachat-ffi" "deltachat-ffi"
] ]
[[example]] [[example]]
name = "simple" name = "simple"
[[example]] [[example]]
name = "repl" name = "repl"
path = "examples/repl/main.rs" path = "examples/repl/main.rs"

View File

@@ -2,6 +2,7 @@ extern crate deltachat;
use std::ffi::{CStr, CString}; use std::ffi::{CStr, CString};
use std::ptr::NonNull; use std::ptr::NonNull;
use tempfile::tempdir;
use deltachat::constants::Event; use deltachat::constants::Event;
use deltachat::dc_chat::*; use deltachat::dc_chat::*;
@@ -73,24 +74,24 @@ fn main() {
dc_perform_smtp_idle(sendable_ctx.0.as_ptr()); dc_perform_smtp_idle(sendable_ctx.0.as_ptr());
}); });
let dbfile = CString::new("../deltachat-core/build/hello2.db").unwrap(); let dir = tempdir().unwrap();
println!("opening dir"); 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()); dc_open(ctx, dbfile.as_ptr(), std::ptr::null());
if dc_is_configured(ctx) == 0 { println!("configuring");
println!("configuring"); dc_set_config(
dc_set_config( ctx,
ctx, CString::new("addr").unwrap().as_ptr(),
CString::new("addr").unwrap().as_ptr(), CString::new("d@testrun.org").unwrap().as_ptr(),
CString::new("d@testrun.org").unwrap().as_ptr(), );
); dc_set_config(
dc_set_config( ctx,
ctx, CString::new("mail_pw").unwrap().as_ptr(),
CString::new("mail_pw").unwrap().as_ptr(), CString::new("***").unwrap().as_ptr(),
CString::new("***").unwrap().as_ptr(), );
); dc_configure(ctx);
dc_configure(ctx);
}
std::thread::sleep_ms(4000); std::thread::sleep_ms(4000);