From 4b06138d35ce3fbf9d75634cd3b0bdfc230178cc Mon Sep 17 00:00:00 2001 From: J M <2364004+Blu-J@users.noreply.github.com> Date: Sat, 3 Dec 2022 12:17:46 -0700 Subject: [PATCH] fix: Stop service before (#2019) --- backend/src/control.rs | 13 +++++++------ backend/src/install/mod.rs | 9 +++++++++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/backend/src/control.rs b/backend/src/control.rs index 71125edff..fe105dc04 100644 --- a/backend/src/control.rs +++ b/backend/src/control.rs @@ -121,13 +121,14 @@ impl StopReceipts { } #[instrument(skip(db))] -async fn stop_common( +pub async fn stop_common( db: &mut Db, id: &PackageId, breakages: &mut BTreeMap, -) -> Result<(), Error> { +) -> Result { let mut tx = db.begin().await?; let receipts = StopReceipts::new(&mut tx, id).await?; + let last_status = receipts.status.get(&mut tx).await?; receipts.status.set(&mut tx, MainStatus::Stopping).await?; tx.save().await?; @@ -140,7 +141,7 @@ async fn stop_common( ) .await?; - Ok(()) + Ok(last_status) } #[command( @@ -170,15 +171,15 @@ pub async fn stop_dry( } #[instrument(skip(ctx))] -pub async fn stop_impl(ctx: RpcContext, id: PackageId) -> Result<(), Error> { +pub async fn stop_impl(ctx: RpcContext, id: PackageId) -> Result { let mut db = ctx.db.handle(); let mut tx = db.begin().await?; - stop_common(&mut tx, &id, &mut BTreeMap::new()).await?; + let last_statuts = stop_common(&mut tx, &id, &mut BTreeMap::new()).await?; tx.commit().await?; - Ok(()) + Ok(last_statuts) } #[command(display(display_none), metadata(sync_db = true))] diff --git a/backend/src/install/mod.rs b/backend/src/install/mod.rs index 1cddece6c..e12f41ebd 100644 --- a/backend/src/install/mod.rs +++ b/backend/src/install/mod.rs @@ -710,8 +710,10 @@ pub async fn download_install_s9pk( ) -> Result<(), Error> { let pkg_id = &temp_manifest.id; let version = &temp_manifest.version; + let mut previous_state: Option = None; if let Err(e) = async { + previous_state = Some(crate::control::stop_impl(ctx.clone(), pkg_id.clone()).await?); let mut db_handle = ctx.db.handle(); let mut tx = db_handle.begin().await?; let receipts = DownloadInstallReceipts::new(&mut tx, &pkg_id).await?; @@ -813,6 +815,10 @@ pub async fn download_install_s9pk( } .await { + if previous_state.map(|x| x.running()).unwrap_or(false) { + crate::control::start(ctx.clone(), pkg_id.clone()).await?; + } + let mut handle = ctx.db.handle(); let mut tx = handle.begin().await?; let receipts = cleanup::CleanupFailedReceipts::new(&mut tx).await?; @@ -825,6 +831,9 @@ pub async fn download_install_s9pk( } Err(e) } else { + if previous_state.map(|x| x.running()).unwrap_or(false) { + crate::control::start(ctx.clone(), pkg_id.clone()).await?; + } Ok(()) } }