mirror of
https://github.com/chatmail/core.git
synced 2026-05-06 16:36:59 +03:00
Pause I/O in get_backup()
This commit is contained in:
committed by
Floris Bruynooghe
parent
0c02886005
commit
5d80d4788c
@@ -373,21 +373,20 @@ pub async fn get_backup(context: &Context, qr: Qr) -> Result<()> {
|
|||||||
!context.is_configured().await?,
|
!context.is_configured().await?,
|
||||||
"Cannot import backups to accounts in use."
|
"Cannot import backups to accounts in use."
|
||||||
);
|
);
|
||||||
ensure!(
|
let mut guard = context.scheduler.pause(context).await;
|
||||||
!context.scheduler.is_running().await,
|
|
||||||
"cannot import backup, IO is running"
|
|
||||||
);
|
|
||||||
|
|
||||||
// Acquire global "ongoing" mutex.
|
// Acquire global "ongoing" mutex.
|
||||||
let cancel_token = context.alloc_ongoing().await?;
|
let cancel_token = context.alloc_ongoing().await?;
|
||||||
tokio::select! {
|
let res = tokio::select! {
|
||||||
biased;
|
biased;
|
||||||
res = get_backup_inner(context, qr) => {
|
res = get_backup_inner(context, qr) => {
|
||||||
context.free_ongoing().await;
|
context.free_ongoing().await;
|
||||||
res
|
res
|
||||||
}
|
}
|
||||||
_ = cancel_token.recv() => Err(format_err!("cancelled")),
|
_ = cancel_token.recv() => Err(format_err!("cancelled")),
|
||||||
}
|
};
|
||||||
|
guard.resume().await;
|
||||||
|
res
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_backup_inner(context: &Context, qr: Qr) -> Result<()> {
|
async fn get_backup_inner(context: &Context, qr: Qr) -> Result<()> {
|
||||||
|
|||||||
Reference in New Issue
Block a user