mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 04:01:58 +00:00
cleanup wip; change cbor lib
This commit is contained in:
committed by
Aiden McClelland
parent
269ee0cf01
commit
1f48fcfb97
@@ -1,11 +1,13 @@
|
||||
use std::borrow::Cow;
|
||||
use std::path::Path;
|
||||
|
||||
use anyhow::anyhow;
|
||||
use bollard::Docker;
|
||||
use patch_db::DbHandle;
|
||||
|
||||
use super::PKG_PUBLIC_DIR;
|
||||
use crate::context::RpcContext;
|
||||
use crate::db::model::InstalledPackageDataEntry;
|
||||
use crate::db::model::{InstalledPackageDataEntry, PackageDataEntry};
|
||||
use crate::dependencies::DependencyError;
|
||||
use crate::s9pk::manifest::{Manifest, PackageId};
|
||||
use crate::util::Version;
|
||||
@@ -63,19 +65,75 @@ pub async fn update_dependents<'a, Db: DbHandle, I: IntoIterator<Item = &'a Pack
|
||||
pub async fn cleanup<Db: DbHandle>(
|
||||
ctx: &RpcContext,
|
||||
db: &mut Db,
|
||||
info: Result<InstalledPackageDataEntry, &Manifest>,
|
||||
id: &PackageId,
|
||||
version: &Version,
|
||||
) -> Result<(), Error> {
|
||||
let man = match info {
|
||||
Ok(pde) => {
|
||||
// TODO
|
||||
|
||||
Cow::Owned(pde.manifest)
|
||||
let pde = crate::db::DatabaseModel::new()
|
||||
.package_data()
|
||||
.idx_model(id)
|
||||
.expect(db)
|
||||
.await?
|
||||
.get(db, true)
|
||||
.await?
|
||||
.to_owned();
|
||||
if let Some(manifest) = match &pde {
|
||||
PackageDataEntry::Installing { manifest, .. } => Some(manifest),
|
||||
PackageDataEntry::Updating { manifest, .. } => {
|
||||
if &manifest.version != version {
|
||||
Some(manifest)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
Err(man) => Cow::Borrowed(man),
|
||||
};
|
||||
ctx.managers
|
||||
.remove(&(man.id.clone(), man.version.clone()))
|
||||
.await;
|
||||
// docker images start9/$APP_ID/*:$VERSION -q | xargs docker rmi
|
||||
_ => {
|
||||
log::warn!("{}: Nothing to clean up!", id);
|
||||
None
|
||||
}
|
||||
} {
|
||||
ctx.managers
|
||||
.remove(&(manifest.id.clone(), manifest.version.clone()))
|
||||
.await;
|
||||
// docker images start9/$APP_ID/*:$VERSION -q | xargs docker rmi
|
||||
let public_dir_path = Path::new(PKG_PUBLIC_DIR).join(id).join(version.as_str());
|
||||
}
|
||||
|
||||
match pde {
|
||||
PackageDataEntry::Installing { .. } => {
|
||||
crate::db::DatabaseModel::new()
|
||||
.package_data()
|
||||
.remove(db, id)
|
||||
.await?;
|
||||
}
|
||||
PackageDataEntry::Updating {
|
||||
installed,
|
||||
manifest,
|
||||
static_files,
|
||||
..
|
||||
} => {
|
||||
crate::db::DatabaseModel::new()
|
||||
.package_data()
|
||||
.idx_model(id)
|
||||
.put(
|
||||
db,
|
||||
&PackageDataEntry::Installed {
|
||||
installed,
|
||||
manifest,
|
||||
static_files,
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
|
||||
Ok(()) // TODO
|
||||
}
|
||||
|
||||
pub async fn uninstall<Db: DbHandle>(
|
||||
ctx: &RpcContext,
|
||||
db: &mut Db,
|
||||
entry: InstalledPackageDataEntry,
|
||||
) -> Result<(), Error> {
|
||||
//TODO
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ use crate::db::model::{
|
||||
StaticFiles,
|
||||
};
|
||||
use crate::dependencies::update_current_dependents;
|
||||
use crate::install::cleanup::update_dependents;
|
||||
use crate::install::cleanup::{uninstall, update_dependents};
|
||||
use crate::s9pk::manifest::{Manifest, PackageId};
|
||||
use crate::s9pk::reader::S9pkReader;
|
||||
use crate::status::{DependencyErrors, MainStatus, Status};
|
||||
@@ -240,7 +240,9 @@ pub async fn download_install_s9pk(
|
||||
|
||||
if let Err(e) = res {
|
||||
let mut handle = ctx.db.handle();
|
||||
if let Err(e) = cleanup(&ctx, &mut handle, Err(temp_manifest)).await {
|
||||
let mut tx = handle.begin().await?;
|
||||
|
||||
if let Err(e) = cleanup(&ctx, &mut tx, pkg_id, version).await {
|
||||
log::error!(
|
||||
"Failed to clean up {}@{}: {}: Adding to broken packages",
|
||||
pkg_id,
|
||||
@@ -563,7 +565,9 @@ pub async fn install_s9pk<R: AsyncRead + AsyncSeek + Unpin>(
|
||||
{
|
||||
configured &= res.configured;
|
||||
}
|
||||
cleanup(&ctx, &mut tx, Ok(prev)).await?;
|
||||
if &prev.manifest.version != version {
|
||||
uninstall(ctx, &mut tx, prev).await?;
|
||||
}
|
||||
if let Some(res) = manifest
|
||||
.migrations
|
||||
.from(&prev_manifest.version, pkg_id, version, &manifest.volumes)
|
||||
|
||||
@@ -68,9 +68,9 @@ impl ManagerMap {
|
||||
) -> Result<(), Error> {
|
||||
let mut lock = self.0.write().await;
|
||||
let id = (manifest.id.clone(), manifest.version.clone());
|
||||
if let Some(man) = lock.get(&id) {
|
||||
if let Some(man) = lock.remove(&id) {
|
||||
if !man.thread.is_empty().await {
|
||||
return Ok(());
|
||||
man.exit().await?;
|
||||
}
|
||||
}
|
||||
lock.insert(
|
||||
|
||||
@@ -55,7 +55,7 @@ impl<
|
||||
|
||||
let mut writer = HashWriter::new(Sha512::new(), &mut self.writer);
|
||||
// manifest
|
||||
serde_cbor::to_writer(&mut writer, self.manifest).with_ctx(|_| {
|
||||
serde_cbor::ser::into_writer(self.manifest, &mut writer).with_ctx(|_| {
|
||||
(
|
||||
crate::ErrorKind::Serialization,
|
||||
"Serializing Manifest (CBOR)",
|
||||
|
||||
@@ -121,8 +121,13 @@ impl<R: AsyncRead + AsyncSeek + Unpin> S9pkReader<R> {
|
||||
})
|
||||
}
|
||||
|
||||
pub async fn manifest_raw<'a>(&'a mut self) -> Result<ReadHandle<'a, R>, Error> {
|
||||
self.read_handle(self.toc.manifest).await
|
||||
}
|
||||
|
||||
pub async fn manifest(&mut self) -> Result<Manifest, Error> {
|
||||
serde_cbor::from_slice(&self.read_handle(self.toc.manifest).await?.to_vec().await?)
|
||||
let slice = self.manifest_raw().await?.to_vec().await?;
|
||||
serde_cbor::de::from_reader(slice.as_slice())
|
||||
.with_ctx(|_| (crate::ErrorKind::ParseS9pk, "Deserializing Manifest (CBOR)"))
|
||||
}
|
||||
|
||||
|
||||
@@ -178,7 +178,7 @@ where
|
||||
{
|
||||
let mut buffer = Vec::new();
|
||||
reader.read_to_end(&mut buffer).await?;
|
||||
serde_cbor::from_slice(&buffer)
|
||||
serde_cbor::de::from_reader(buffer.as_slice())
|
||||
.map_err(anyhow::Error::from)
|
||||
.with_kind(crate::ErrorKind::Deserialization)
|
||||
}
|
||||
@@ -678,9 +678,8 @@ impl IoFormat {
|
||||
IoFormat::Yaml => {
|
||||
serde_yaml::to_writer(writer, value).with_kind(crate::ErrorKind::Serialization)
|
||||
}
|
||||
IoFormat::Cbor => {
|
||||
serde_cbor::to_writer(writer, value).with_kind(crate::ErrorKind::Serialization)
|
||||
}
|
||||
IoFormat::Cbor => serde_cbor::ser::into_writer(value, writer)
|
||||
.with_kind(crate::ErrorKind::Serialization),
|
||||
IoFormat::Toml => writer
|
||||
.write_all(
|
||||
&serde_toml::to_vec(
|
||||
@@ -709,7 +708,12 @@ impl IoFormat {
|
||||
serde_json::to_vec_pretty(value).with_kind(crate::ErrorKind::Serialization)
|
||||
}
|
||||
IoFormat::Yaml => serde_yaml::to_vec(value).with_kind(crate::ErrorKind::Serialization),
|
||||
IoFormat::Cbor => serde_cbor::to_vec(value).with_kind(crate::ErrorKind::Serialization),
|
||||
IoFormat::Cbor => {
|
||||
let mut res = Vec::new();
|
||||
serde_cbor::ser::into_writer(value, &mut res)
|
||||
.with_kind(crate::ErrorKind::Serialization)?;
|
||||
Ok(res)
|
||||
}
|
||||
IoFormat::Toml => serde_toml::to_vec(
|
||||
&serde_toml::Value::try_from(value).with_kind(crate::ErrorKind::Serialization)?,
|
||||
)
|
||||
@@ -734,7 +738,7 @@ impl IoFormat {
|
||||
serde_yaml::from_reader(reader).with_kind(crate::ErrorKind::Deserialization)
|
||||
}
|
||||
IoFormat::Cbor => {
|
||||
serde_cbor::from_reader(reader).with_kind(crate::ErrorKind::Deserialization)
|
||||
serde_cbor::de::from_reader(reader).with_kind(crate::ErrorKind::Deserialization)
|
||||
}
|
||||
IoFormat::Toml | IoFormat::TomlPretty => {
|
||||
let mut s = String::new();
|
||||
@@ -754,7 +758,7 @@ impl IoFormat {
|
||||
serde_yaml::from_slice(slice).with_kind(crate::ErrorKind::Deserialization)
|
||||
}
|
||||
IoFormat::Cbor => {
|
||||
serde_cbor::from_slice(slice).with_kind(crate::ErrorKind::Deserialization)
|
||||
serde_cbor::de::from_reader(slice).with_kind(crate::ErrorKind::Deserialization)
|
||||
}
|
||||
IoFormat::Toml | IoFormat::TomlPretty => {
|
||||
serde_toml::from_slice(slice).with_kind(crate::ErrorKind::Deserialization)
|
||||
|
||||
Reference in New Issue
Block a user