fixed: make export/import work with blob-files again

also add some more logging.
This commit is contained in:
holger krekel
2019-07-03 20:02:05 +02:00
parent 191d11e719
commit adcb9d6069
4 changed files with 22 additions and 0 deletions

View File

@@ -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(

View File

@@ -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:

View File

@@ -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(

View File

@@ -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;
}