mirror of
https://github.com/chatmail/core.git
synced 2026-05-08 09:26:29 +03:00
remove dc_accounts_import_account() api
in most (all?) UIs, import/export works on an already created account, so, dc_accounts_import_account() does not really help here - but adds some noise and confusion eg. as for the other dc_accounts_t functions, the corrsponding dc_context_t functions must not be called. if really a new account is required for import, it seems to be easier to call add_account() before import.
This commit is contained in:
@@ -2412,7 +2412,7 @@ void dc_str_unref (char* str);
|
|||||||
* The account manager takes an directory
|
* The account manager takes an directory
|
||||||
* where all context-databases are placed in.
|
* where all context-databases are placed in.
|
||||||
* To add a context to the account manager,
|
* To add a context to the account manager,
|
||||||
* use dc_accounts_add_account(), dc_accounts_import_account or dc_accounts_migrate_account().
|
* use dc_accounts_add_account() or dc_accounts_migrate_account().
|
||||||
* All account information are persisted.
|
* All account information are persisted.
|
||||||
* To remove a context from the account manager,
|
* To remove a context from the account manager,
|
||||||
* use dc_accounts_remove_account().
|
* use dc_accounts_remove_account().
|
||||||
@@ -2457,21 +2457,6 @@ void dc_accounts_unref (dc_accounts_t* accounts);
|
|||||||
uint32_t dc_accounts_add_account (dc_accounts_t* accounts);
|
uint32_t dc_accounts_add_account (dc_accounts_t* accounts);
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Import a tarfile-backup to the account manager.
|
|
||||||
* On success, a new account is added to the account-manager,
|
|
||||||
* with all the data provided by the backup-file.
|
|
||||||
* Moreover, the newly created account will be the selected one.
|
|
||||||
*
|
|
||||||
* @memberof dc_accounts_t
|
|
||||||
* @param accounts Account manager as created by dc_accounts_new().
|
|
||||||
* @param tarfile Backup as created by dc_imex().
|
|
||||||
* @return Account-id, use dc_accounts_get_account() to get the context object.
|
|
||||||
* On errors, 0 is returned.
|
|
||||||
*/
|
|
||||||
uint32_t dc_accounts_import_account (dc_accounts_t* accounts, const char* tarfile);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Migrate independent accounts into accounts managed by the account manager.
|
* Migrate independent accounts into accounts managed by the account manager.
|
||||||
* This will _move_ the database-file and all blob-files to the directory managed
|
* This will _move_ the database-file and all blob-files to the directory managed
|
||||||
|
|||||||
@@ -3799,23 +3799,6 @@ pub unsafe extern "C" fn dc_accounts_get_all(accounts: *mut dc_accounts_t) -> *m
|
|||||||
Box::into_raw(Box::new(array))
|
Box::into_raw(Box::new(array))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn dc_accounts_import_account(
|
|
||||||
accounts: *mut dc_accounts_t,
|
|
||||||
file: *const libc::c_char,
|
|
||||||
) -> u32 {
|
|
||||||
if accounts.is_null() || file.is_null() {
|
|
||||||
eprintln!("ignoring careless call to dc_accounts_import_account()");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
let accounts = &*accounts;
|
|
||||||
let file = to_string_lossy(file);
|
|
||||||
block_on(accounts.import_account(async_std::path::PathBuf::from(file)))
|
|
||||||
.map(|_| 1)
|
|
||||||
.unwrap_or_else(|_| 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn dc_accounts_start_io(accounts: *mut dc_accounts_t) {
|
pub unsafe extern "C" fn dc_accounts_start_io(accounts: *mut dc_accounts_t) {
|
||||||
if accounts.is_null() {
|
if accounts.is_null() {
|
||||||
|
|||||||
@@ -179,25 +179,6 @@ impl Accounts {
|
|||||||
self.accounts.read().await.keys().copied().collect()
|
self.accounts.read().await.keys().copied().collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Import a backup using a new account and selects it.
|
|
||||||
pub async fn import_account(&self, file: PathBuf) -> Result<u32> {
|
|
||||||
let old_id = self.config.get_selected_account().await;
|
|
||||||
|
|
||||||
let id = self.add_account().await?;
|
|
||||||
let ctx = self.get_account(id).await.expect("just added");
|
|
||||||
|
|
||||||
match crate::imex::imex(&ctx, crate::imex::ImexMode::ImportBackup, &file).await {
|
|
||||||
Ok(_) => Ok(id),
|
|
||||||
Err(err) => {
|
|
||||||
// remove temp account
|
|
||||||
self.remove_account(id).await?;
|
|
||||||
// set selection back
|
|
||||||
self.select_account(old_id).await?;
|
|
||||||
Err(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn start_io(&self) {
|
pub async fn start_io(&self) {
|
||||||
let accounts = &*self.accounts.read().await;
|
let accounts = &*self.accounts.read().await;
|
||||||
for account in accounts.values() {
|
for account in accounts.values() {
|
||||||
|
|||||||
Reference in New Issue
Block a user