From adcb9d6069ba130b739f89c4300a1e543dd36303 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Wed, 3 Jul 2019 20:02:05 +0200 Subject: [PATCH] fixed: make export/import work with blob-files again also add some more logging. --- python/src/deltachat/account.py | 1 + python/tests/test_account.py | 12 ++++++++++++ src/dc_imex.rs | 6 ++++++ src/dc_tools.rs | 3 +++ 4 files changed, 22 insertions(+) diff --git a/python/src/deltachat/account.py b/python/src/deltachat/account.py index e911889d5..af2710bed 100644 --- a/python/src/deltachat/account.py +++ b/python/src/deltachat/account.py @@ -189,6 +189,7 @@ class Account(object): :param contact: chat_id (int) or contact object. :returns: a :class:`deltachat.chatting.Chat` object. """ + assert contact._dc_context == self._dc_context contact_id = getattr(contact, "id", contact) assert isinstance(contact_id, int) chat_id = lib.dc_create_chat_by_contact_id( diff --git a/python/tests/test_account.py b/python/tests/test_account.py index 837816261..d361029ff 100644 --- a/python/tests/test_account.py +++ b/python/tests/test_account.py @@ -207,7 +207,14 @@ class TestOfflineAccount: ac1 = acfactory.get_configured_offline_account() contact1 = ac1.create_contact("some1@hello.com", name="some1") chat = ac1.create_chat_by_contact(contact1) + # send a text message msg = chat.send_text("msg1") + # send a binary file + bin = tmpdir.join("some.bin") + with bin.open("w") as f: + f.write("\00123" * 10000) + msg = chat.send_file(bin.strpath) + contact = msg.get_sender_contact() assert contact == ac1.get_self_contact() assert not backupdir.listdir() @@ -220,6 +227,11 @@ class TestOfflineAccount: assert len(l) == 1 contact2 = l[0] assert contact2.addr == "some1@hello.com" + chat2 = ac2.create_chat_by_contact(contact2) + messages = chat2.get_messages() + assert len(messages) == 2 + assert messages[0].text == "msg1" + assert os.path.exists(messages[1].filename) class TestOnlineAccount: diff --git a/src/dc_imex.rs b/src/dc_imex.rs index 30fee341f..53c36d9d0 100644 --- a/src/dc_imex.rs +++ b/src/dc_imex.rs @@ -915,6 +915,7 @@ unsafe fn import_backup(context: &Context, backup_to_import: *const libc::c_char backup_to_import, context.get_dbfile(), ); + if 0 != dc_is_configured(context) { dc_log_error( context, @@ -942,6 +943,7 @@ unsafe fn import_backup(context: &Context, backup_to_import: *const libc::c_char ); sqlite3_step(stmt); total_files_cnt = sqlite3_column_int(stmt, 0i32); + info!(context, 0, "***IMPORT-in-progress: total_files_cnt={:?}", total_files_cnt); sqlite3_finalize(stmt); stmt = dc_sqlite3_prepare( context, @@ -1132,6 +1134,7 @@ unsafe fn export_backup(context: &Context, dir: *const libc::c_char) -> libc::c_ let dir_handle = dir_handle.unwrap(); total_files_cnt += dir_handle.filter(|r| r.is_ok()).count(); + info!(context, 0, "EXPORT: total_files_cnt={}", total_files_cnt); if total_files_cnt > 0 { // scan directory, pass 2: copy files let dir_handle = std::fs::read_dir(dir); @@ -1191,6 +1194,9 @@ unsafe fn export_backup(context: &Context, dir: *const libc::c_char) -> libc::c_ let name = name_f.to_string_lossy(); if name.starts_with("delt-chat") && name.ends_with(".bak") { // dc_log_info(context, 0, "Backup: Skipping \"%s\".", name); + continue; + } else { + info!(context, 0, "EXPORTing filename={}", name); free(curr_pathNfilename as *mut libc::c_void); let name_c = to_cstring(name); curr_pathNfilename = dc_mprintf( diff --git a/src/dc_tools.rs b/src/dc_tools.rs index ee037b053..738639c4a 100644 --- a/src/dc_tools.rs +++ b/src/dc_tools.rs @@ -1258,6 +1258,9 @@ pub unsafe fn dc_write_file( ) -> libc::c_int { let mut success = 0; let pathNfilename_abs = dc_get_abs_path(context, pathNfilename); + + info!(context, 0, "trying to write file {:?}", pathNfilename); + if pathNfilename_abs.is_null() { return 0; }