Bugfix/backup lock order (#1583)

* different fix

* Revert "fix backup lock ordering (#1582)"

This reverts commit f1e065a448.
This commit is contained in:
Aiden McClelland
2022-06-29 09:03:10 -06:00
committed by GitHub
parent f1e065a448
commit 4b0ff07d70

View File

@@ -159,6 +159,7 @@ pub async fn backup_all(
} }
let revision = assure_backing_up(&mut db, &service_ids).await?; let revision = assure_backing_up(&mut db, &service_ids).await?;
tokio::task::spawn(async move { tokio::task::spawn(async move {
let backup_res = perform_backup(&ctx, &mut db, backup_guard).await;
let backup_progress = crate::db::DatabaseModel::new() let backup_progress = crate::db::DatabaseModel::new()
.server_info() .server_info()
.status_info() .status_info()
@@ -168,7 +169,6 @@ pub async fn backup_all(
.lock(&mut db, LockType::Write) .lock(&mut db, LockType::Write)
.await .await
.expect("failed to lock server status"); .expect("failed to lock server status");
let backup_res = perform_backup(&ctx, &mut db, backup_guard).await;
match backup_res { match backup_res {
Ok(report) if report.iter().all(|(_, rep)| rep.error.is_none()) => ctx Ok(report) if report.iter().all(|(_, rep)| rep.error.is_none()) => ctx
.notification_manager .notification_manager
@@ -397,23 +397,22 @@ async fn perform_backup<Db: DbHandle>(
) )
.await?; .await?;
let mut backup_progress: BTreeMap<_, _> = (crate::db::DatabaseModel::new() let mut backup_progress = crate::db::DatabaseModel::new()
.server_info() .server_info()
.status_info() .status_info()
.backup_progress() .backup_progress()
.get(&mut tx, true) .get_mut(&mut tx)
.await? .await?;
.into_owned()) if backup_progress.is_none() {
.unwrap_or_default(); *backup_progress = Some(Default::default());
if let Some(mut backup_progress) = backup_progress.get_mut(&package_id) { }
if let Some(mut backup_progress) = backup_progress
.as_mut()
.and_then(|bp| bp.get_mut(&package_id))
{
(*backup_progress).complete = true; (*backup_progress).complete = true;
} }
crate::db::DatabaseModel::new() backup_progress.save(&mut tx).await?;
.server_info()
.status_info()
.backup_progress()
.put(&mut tx, &backup_progress)
.await?;
tx.save().await?; tx.save().await?;
} }