fix: Stop service before (#2019)

This commit is contained in:
J M
2022-12-03 12:17:46 -07:00
committed by GitHub
parent bd5668d15d
commit 4b06138d35
2 changed files with 16 additions and 6 deletions

View File

@@ -121,13 +121,14 @@ impl StopReceipts {
}
#[instrument(skip(db))]
async fn stop_common<Db: DbHandle>(
pub async fn stop_common<Db: DbHandle>(
db: &mut Db,
id: &PackageId,
breakages: &mut BTreeMap<PackageId, TaggedDependencyError>,
) -> Result<(), Error> {
) -> Result<MainStatus, Error> {
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<Db: DbHandle>(
)
.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<MainStatus, Error> {
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))]

View File

@@ -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<MainStatus> = 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(())
}
}