mirror of
https://github.com/chatmail/core.git
synced 2026-04-17 21:46:35 +03:00
fixed: make export/import work with blob-files again
also add some more logging.
This commit is contained in:
@@ -189,6 +189,7 @@ class Account(object):
|
|||||||
:param contact: chat_id (int) or contact object.
|
:param contact: chat_id (int) or contact object.
|
||||||
:returns: a :class:`deltachat.chatting.Chat` object.
|
:returns: a :class:`deltachat.chatting.Chat` object.
|
||||||
"""
|
"""
|
||||||
|
assert contact._dc_context == self._dc_context
|
||||||
contact_id = getattr(contact, "id", contact)
|
contact_id = getattr(contact, "id", contact)
|
||||||
assert isinstance(contact_id, int)
|
assert isinstance(contact_id, int)
|
||||||
chat_id = lib.dc_create_chat_by_contact_id(
|
chat_id = lib.dc_create_chat_by_contact_id(
|
||||||
|
|||||||
@@ -207,7 +207,14 @@ class TestOfflineAccount:
|
|||||||
ac1 = acfactory.get_configured_offline_account()
|
ac1 = acfactory.get_configured_offline_account()
|
||||||
contact1 = ac1.create_contact("some1@hello.com", name="some1")
|
contact1 = ac1.create_contact("some1@hello.com", name="some1")
|
||||||
chat = ac1.create_chat_by_contact(contact1)
|
chat = ac1.create_chat_by_contact(contact1)
|
||||||
|
# send a text message
|
||||||
msg = chat.send_text("msg1")
|
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()
|
contact = msg.get_sender_contact()
|
||||||
assert contact == ac1.get_self_contact()
|
assert contact == ac1.get_self_contact()
|
||||||
assert not backupdir.listdir()
|
assert not backupdir.listdir()
|
||||||
@@ -220,6 +227,11 @@ class TestOfflineAccount:
|
|||||||
assert len(l) == 1
|
assert len(l) == 1
|
||||||
contact2 = l[0]
|
contact2 = l[0]
|
||||||
assert contact2.addr == "some1@hello.com"
|
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:
|
class TestOnlineAccount:
|
||||||
|
|||||||
@@ -915,6 +915,7 @@ unsafe fn import_backup(context: &Context, backup_to_import: *const libc::c_char
|
|||||||
backup_to_import,
|
backup_to_import,
|
||||||
context.get_dbfile(),
|
context.get_dbfile(),
|
||||||
);
|
);
|
||||||
|
|
||||||
if 0 != dc_is_configured(context) {
|
if 0 != dc_is_configured(context) {
|
||||||
dc_log_error(
|
dc_log_error(
|
||||||
context,
|
context,
|
||||||
@@ -942,6 +943,7 @@ unsafe fn import_backup(context: &Context, backup_to_import: *const libc::c_char
|
|||||||
);
|
);
|
||||||
sqlite3_step(stmt);
|
sqlite3_step(stmt);
|
||||||
total_files_cnt = sqlite3_column_int(stmt, 0i32);
|
total_files_cnt = sqlite3_column_int(stmt, 0i32);
|
||||||
|
info!(context, 0, "***IMPORT-in-progress: total_files_cnt={:?}", total_files_cnt);
|
||||||
sqlite3_finalize(stmt);
|
sqlite3_finalize(stmt);
|
||||||
stmt = dc_sqlite3_prepare(
|
stmt = dc_sqlite3_prepare(
|
||||||
context,
|
context,
|
||||||
@@ -1132,6 +1134,7 @@ unsafe fn export_backup(context: &Context, dir: *const libc::c_char) -> libc::c_
|
|||||||
let dir_handle = dir_handle.unwrap();
|
let dir_handle = dir_handle.unwrap();
|
||||||
total_files_cnt += dir_handle.filter(|r| r.is_ok()).count();
|
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 {
|
if total_files_cnt > 0 {
|
||||||
// scan directory, pass 2: copy files
|
// scan directory, pass 2: copy files
|
||||||
let dir_handle = std::fs::read_dir(dir);
|
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();
|
let name = name_f.to_string_lossy();
|
||||||
if name.starts_with("delt-chat") && name.ends_with(".bak") {
|
if name.starts_with("delt-chat") && name.ends_with(".bak") {
|
||||||
// dc_log_info(context, 0, "Backup: Skipping \"%s\".", name);
|
// 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);
|
free(curr_pathNfilename as *mut libc::c_void);
|
||||||
let name_c = to_cstring(name);
|
let name_c = to_cstring(name);
|
||||||
curr_pathNfilename = dc_mprintf(
|
curr_pathNfilename = dc_mprintf(
|
||||||
|
|||||||
@@ -1258,6 +1258,9 @@ pub unsafe fn dc_write_file(
|
|||||||
) -> libc::c_int {
|
) -> libc::c_int {
|
||||||
let mut success = 0;
|
let mut success = 0;
|
||||||
let pathNfilename_abs = dc_get_abs_path(context, pathNfilename);
|
let pathNfilename_abs = dc_get_abs_path(context, pathNfilename);
|
||||||
|
|
||||||
|
info!(context, 0, "trying to write file {:?}", pathNfilename);
|
||||||
|
|
||||||
if pathNfilename_abs.is_null() {
|
if pathNfilename_abs.is_null() {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user