chore: Refactor out big fn

This commit is contained in:
Justin Miller
2021-10-09 16:09:04 -06:00
committed by Aiden McClelland
parent c2150efb69
commit dc96e74391
2 changed files with 40 additions and 29 deletions

View File

@@ -709,34 +709,7 @@ pub async fn install_s9pk<R: AsyncRead + AsyncSeek + Unpin>(
.get(&mut tx, true)
.await?
.into_owned();
if let Some(recovered) = recovered {
let configured = if let Some(res) = manifest
.migrations
.from(ctx, &recovered.version, pkg_id, version, &manifest.volumes)
.await?
{
res.configured
} else {
false
};
if configured {
crate::config::configure(
ctx,
&mut tx,
pkg_id,
None,
&None,
false,
&mut BTreeMap::new(),
&mut BTreeMap::new(),
)
.await?;
}
crate::db::DatabaseModel::new()
.recovered_packages()
.remove(&mut tx, pkg_id)
.await?
}
handle_recovered_package(recovered, manifest, ctx, pkg_id, version, &mut tx).await?;
}
sql_tx.commit().await?;
@@ -747,6 +720,44 @@ pub async fn install_s9pk<R: AsyncRead + AsyncSeek + Unpin>(
Ok(())
}
async fn handle_recovered_package(
recovered: Option<crate::db::model::RecoveredPackageInfo>,
manifest: Manifest,
ctx: &RpcContext,
pkg_id: &PackageId,
version: &Version,
tx: &mut patch_db::Transaction<&mut patch_db::PatchDbHandle>,
) -> Result<(), Error> {
Ok(if let Some(recovered) = recovered {
let configured = if let Some(res) = manifest
.migrations
.from(ctx, &recovered.version, pkg_id, version, &manifest.volumes)
.await?
{
res.configured
} else {
false
};
if configured {
crate::config::configure(
ctx,
tx,
pkg_id,
None,
&None,
false,
&mut BTreeMap::new(),
&mut BTreeMap::new(),
)
.await?;
}
crate::db::DatabaseModel::new()
.recovered_packages()
.remove(tx, pkg_id)
.await?
})
}
pub async fn load_images<P: AsRef<Path>>(datadir: P) -> Result<(), Error> {
let docker_dir = datadir.as_ref().join(PKG_DOCKER_DIR);
if tokio::fs::metadata(&docker_dir).await.is_ok() {