mirror of
https://github.com/chatmail/core.git
synced 2026-05-13 20:06:30 +03:00
Make getting backup use the ongoing process
This commit is contained in:
@@ -4159,7 +4159,7 @@ pub unsafe extern "C" fn dc_backup_provider_qr(
|
|||||||
provider: *const dc_backup_provider_t,
|
provider: *const dc_backup_provider_t,
|
||||||
) -> *mut libc::c_char {
|
) -> *mut libc::c_char {
|
||||||
let provider = &*provider;
|
let provider = &*provider;
|
||||||
deltachat::qr::format_backup(provider.qr())
|
deltachat::qr::format_backup(&provider.qr())
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
.strdup()
|
.strdup()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,10 +28,6 @@ use std::sync::atomic::{AtomicU16, AtomicU64, Ordering};
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::task::Poll;
|
use std::task::Poll;
|
||||||
|
|
||||||
use crate::chat::delete_and_reset_all_device_msgs;
|
|
||||||
use crate::context::Context;
|
|
||||||
use crate::qr::Qr;
|
|
||||||
use crate::{e2ee, EventType};
|
|
||||||
use anyhow::{anyhow, bail, ensure, format_err, Context as _, Result};
|
use anyhow::{anyhow, bail, ensure, format_err, Context as _, Result};
|
||||||
use async_channel::Receiver;
|
use async_channel::Receiver;
|
||||||
use futures_lite::StreamExt;
|
use futures_lite::StreamExt;
|
||||||
@@ -46,6 +42,11 @@ use tokio::sync::broadcast::error::RecvError;
|
|||||||
use tokio::task::JoinHandle;
|
use tokio::task::JoinHandle;
|
||||||
use tokio_stream::wrappers::ReadDirStream;
|
use tokio_stream::wrappers::ReadDirStream;
|
||||||
|
|
||||||
|
use crate::chat::delete_and_reset_all_device_msgs;
|
||||||
|
use crate::context::Context;
|
||||||
|
use crate::qr::Qr;
|
||||||
|
use crate::{e2ee, EventType};
|
||||||
|
|
||||||
use super::{export_database, BlobDirContents, DeleteOnDrop, DBFILE_BACKUP_NAME};
|
use super::{export_database, BlobDirContents, DeleteOnDrop, DBFILE_BACKUP_NAME};
|
||||||
|
|
||||||
/// Provide or send a backup of this device.
|
/// Provide or send a backup of this device.
|
||||||
@@ -273,9 +274,10 @@ impl From<SendProgress> for EventType {
|
|||||||
/// does avoid having [`sendme::provider::Ticket`] in the primary API however, without
|
/// does avoid having [`sendme::provider::Ticket`] in the primary API however, without
|
||||||
/// having to revert to untyped bytes.
|
/// having to revert to untyped bytes.
|
||||||
pub async fn get_backup(context: &Context, qr: Qr) -> Result<()> {
|
pub async fn get_backup(context: &Context, qr: Qr) -> Result<()> {
|
||||||
let Qr::Backup { ticket } = qr else {
|
ensure!(
|
||||||
bail!("QR code for backup must be of type DCBACKUP");
|
matches!(qr, Qr::Backup { .. }),
|
||||||
};
|
"QR code for backup must be of type DCBACKUP"
|
||||||
|
);
|
||||||
ensure!(
|
ensure!(
|
||||||
!context.is_configured().await?,
|
!context.is_configured().await?,
|
||||||
"Cannot import backups to accounts in use."
|
"Cannot import backups to accounts in use."
|
||||||
@@ -284,6 +286,23 @@ pub async fn get_backup(context: &Context, qr: Qr) -> Result<()> {
|
|||||||
context.scheduler.read().await.is_none(),
|
context.scheduler.read().await.is_none(),
|
||||||
"cannot import backup, IO is running"
|
"cannot import backup, IO is running"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Acquire global "ongoing" mutex.
|
||||||
|
let cancel_token = context.alloc_ongoing().await?;
|
||||||
|
tokio::select! {
|
||||||
|
biased;
|
||||||
|
res = get_backup_inner(context, qr) => {
|
||||||
|
context.free_ongoing().await;
|
||||||
|
res
|
||||||
|
}
|
||||||
|
_ = cancel_token.recv() => Err(format_err!("cancelled")),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn get_backup_inner(context: &Context, qr: Qr) -> Result<()> {
|
||||||
|
let Qr::Backup { ticket } = qr else {
|
||||||
|
bail!("QR code for backup must be of type DCBACKUP");
|
||||||
|
};
|
||||||
let opts = Options {
|
let opts = Options {
|
||||||
addr: ticket.addr,
|
addr: ticket.addr,
|
||||||
peer_id: Some(ticket.peer),
|
peer_id: Some(ticket.peer),
|
||||||
|
|||||||
Reference in New Issue
Block a user