mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 20:14:49 +00:00
cleanup wip; change cbor lib
This commit is contained in:
18
appmgr/Cargo.lock
generated
18
appmgr/Cargo.lock
generated
@@ -370,6 +370,16 @@ dependencies = [
|
|||||||
"winapi",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ciborium"
|
||||||
|
version = "0.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "de6836a1b6197d8acdaac74a01af077a26aa6953d2e9251eef061c646b0d432c"
|
||||||
|
dependencies = [
|
||||||
|
"half",
|
||||||
|
"serde",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "clang-sys"
|
name = "clang-sys"
|
||||||
version = "1.2.0"
|
version = "1.2.0"
|
||||||
@@ -789,6 +799,7 @@ dependencies = [
|
|||||||
"basic-cookies",
|
"basic-cookies",
|
||||||
"bollard",
|
"bollard",
|
||||||
"chrono",
|
"chrono",
|
||||||
|
"ciborium",
|
||||||
"clap",
|
"clap",
|
||||||
"cookie_store 0.15.0",
|
"cookie_store 0.15.0",
|
||||||
"digest 0.9.0",
|
"digest 0.9.0",
|
||||||
@@ -825,7 +836,6 @@ dependencies = [
|
|||||||
"rust-argon2",
|
"rust-argon2",
|
||||||
"scopeguard",
|
"scopeguard",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_cbor 0.11.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"serde_yaml",
|
"serde_yaml",
|
||||||
"sha2 0.9.5",
|
"sha2 0.9.5",
|
||||||
@@ -2392,7 +2402,7 @@ dependencies = [
|
|||||||
"reqwest",
|
"reqwest",
|
||||||
"rpc-toolkit-macro",
|
"rpc-toolkit-macro",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_cbor 0.11.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"serde_cbor 0.11.2",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"tokio 1.9.0",
|
"tokio 1.9.0",
|
||||||
@@ -2574,9 +2584,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_cbor"
|
name = "serde_cbor"
|
||||||
version = "0.11.1"
|
version = "0.11.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1e18acfa2f90e8b735b2836ab8d538de304cbb6729a7360729ea5a895d15a622"
|
checksum = "2bef2ebfde456fb76bbcf9f59315333decc4fda0b2b44b420243c11e0f5ec1f5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"half",
|
"half",
|
||||||
"serde",
|
"serde",
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ rpc-toolkit = { version = "*", path = "../../rpc-toolkit/rpc-toolkit" }
|
|||||||
rust-argon2 = "0.8.3"
|
rust-argon2 = "0.8.3"
|
||||||
scopeguard = "1.1" # because avahi-sys fucks your shit up
|
scopeguard = "1.1" # because avahi-sys fucks your shit up
|
||||||
serde = { version = "1.0.118", features = ["derive", "rc"] }
|
serde = { version = "1.0.118", features = ["derive", "rc"] }
|
||||||
serde_cbor = "0.11.1"
|
serde_cbor = { package = "ciborium", version = "0.1.0" }
|
||||||
serde_json = "1.0.59"
|
serde_json = "1.0.59"
|
||||||
serde_toml = { package = "toml", version = "0.5.8" }
|
serde_toml = { package = "toml", version = "0.5.8" }
|
||||||
serde_yaml = "0.8.14"
|
serde_yaml = "0.8.14"
|
||||||
|
|||||||
14
appmgr/embassyd.service
Normal file
14
appmgr/embassyd.service
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Embassy Daemon
|
||||||
|
After=network.target systemd-time-wait-sync.service
|
||||||
|
Requires=network.target
|
||||||
|
Wants=avahi-daemon.service
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
ExecStart=/usr/local/bin/embassyd -vvv
|
||||||
|
Restart=always
|
||||||
|
RestartSec=3
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
@@ -1,11 +1,13 @@
|
|||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
use bollard::Docker;
|
use bollard::Docker;
|
||||||
use patch_db::DbHandle;
|
use patch_db::DbHandle;
|
||||||
|
|
||||||
|
use super::PKG_PUBLIC_DIR;
|
||||||
use crate::context::RpcContext;
|
use crate::context::RpcContext;
|
||||||
use crate::db::model::InstalledPackageDataEntry;
|
use crate::db::model::{InstalledPackageDataEntry, PackageDataEntry};
|
||||||
use crate::dependencies::DependencyError;
|
use crate::dependencies::DependencyError;
|
||||||
use crate::s9pk::manifest::{Manifest, PackageId};
|
use crate::s9pk::manifest::{Manifest, PackageId};
|
||||||
use crate::util::Version;
|
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>(
|
pub async fn cleanup<Db: DbHandle>(
|
||||||
ctx: &RpcContext,
|
ctx: &RpcContext,
|
||||||
db: &mut Db,
|
db: &mut Db,
|
||||||
info: Result<InstalledPackageDataEntry, &Manifest>,
|
id: &PackageId,
|
||||||
|
version: &Version,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let man = match info {
|
let pde = crate::db::DatabaseModel::new()
|
||||||
Ok(pde) => {
|
.package_data()
|
||||||
// TODO
|
.idx_model(id)
|
||||||
|
.expect(db)
|
||||||
Cow::Owned(pde.manifest)
|
.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),
|
_ => {
|
||||||
};
|
log::warn!("{}: Nothing to clean up!", id);
|
||||||
ctx.managers
|
None
|
||||||
.remove(&(man.id.clone(), man.version.clone()))
|
}
|
||||||
.await;
|
} {
|
||||||
// docker images start9/$APP_ID/*:$VERSION -q | xargs docker rmi
|
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
|
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,
|
StaticFiles,
|
||||||
};
|
};
|
||||||
use crate::dependencies::update_current_dependents;
|
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::manifest::{Manifest, PackageId};
|
||||||
use crate::s9pk::reader::S9pkReader;
|
use crate::s9pk::reader::S9pkReader;
|
||||||
use crate::status::{DependencyErrors, MainStatus, Status};
|
use crate::status::{DependencyErrors, MainStatus, Status};
|
||||||
@@ -240,7 +240,9 @@ pub async fn download_install_s9pk(
|
|||||||
|
|
||||||
if let Err(e) = res {
|
if let Err(e) = res {
|
||||||
let mut handle = ctx.db.handle();
|
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!(
|
log::error!(
|
||||||
"Failed to clean up {}@{}: {}: Adding to broken packages",
|
"Failed to clean up {}@{}: {}: Adding to broken packages",
|
||||||
pkg_id,
|
pkg_id,
|
||||||
@@ -563,7 +565,9 @@ pub async fn install_s9pk<R: AsyncRead + AsyncSeek + Unpin>(
|
|||||||
{
|
{
|
||||||
configured &= res.configured;
|
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
|
if let Some(res) = manifest
|
||||||
.migrations
|
.migrations
|
||||||
.from(&prev_manifest.version, pkg_id, version, &manifest.volumes)
|
.from(&prev_manifest.version, pkg_id, version, &manifest.volumes)
|
||||||
|
|||||||
@@ -68,9 +68,9 @@ impl ManagerMap {
|
|||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let mut lock = self.0.write().await;
|
let mut lock = self.0.write().await;
|
||||||
let id = (manifest.id.clone(), manifest.version.clone());
|
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 {
|
if !man.thread.is_empty().await {
|
||||||
return Ok(());
|
man.exit().await?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lock.insert(
|
lock.insert(
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ impl<
|
|||||||
|
|
||||||
let mut writer = HashWriter::new(Sha512::new(), &mut self.writer);
|
let mut writer = HashWriter::new(Sha512::new(), &mut self.writer);
|
||||||
// manifest
|
// 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,
|
crate::ErrorKind::Serialization,
|
||||||
"Serializing Manifest (CBOR)",
|
"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> {
|
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)"))
|
.with_ctx(|_| (crate::ErrorKind::ParseS9pk, "Deserializing Manifest (CBOR)"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -178,7 +178,7 @@ where
|
|||||||
{
|
{
|
||||||
let mut buffer = Vec::new();
|
let mut buffer = Vec::new();
|
||||||
reader.read_to_end(&mut buffer).await?;
|
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)
|
.map_err(anyhow::Error::from)
|
||||||
.with_kind(crate::ErrorKind::Deserialization)
|
.with_kind(crate::ErrorKind::Deserialization)
|
||||||
}
|
}
|
||||||
@@ -678,9 +678,8 @@ impl IoFormat {
|
|||||||
IoFormat::Yaml => {
|
IoFormat::Yaml => {
|
||||||
serde_yaml::to_writer(writer, value).with_kind(crate::ErrorKind::Serialization)
|
serde_yaml::to_writer(writer, value).with_kind(crate::ErrorKind::Serialization)
|
||||||
}
|
}
|
||||||
IoFormat::Cbor => {
|
IoFormat::Cbor => serde_cbor::ser::into_writer(value, writer)
|
||||||
serde_cbor::to_writer(writer, value).with_kind(crate::ErrorKind::Serialization)
|
.with_kind(crate::ErrorKind::Serialization),
|
||||||
}
|
|
||||||
IoFormat::Toml => writer
|
IoFormat::Toml => writer
|
||||||
.write_all(
|
.write_all(
|
||||||
&serde_toml::to_vec(
|
&serde_toml::to_vec(
|
||||||
@@ -709,7 +708,12 @@ impl IoFormat {
|
|||||||
serde_json::to_vec_pretty(value).with_kind(crate::ErrorKind::Serialization)
|
serde_json::to_vec_pretty(value).with_kind(crate::ErrorKind::Serialization)
|
||||||
}
|
}
|
||||||
IoFormat::Yaml => serde_yaml::to_vec(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(
|
IoFormat::Toml => serde_toml::to_vec(
|
||||||
&serde_toml::Value::try_from(value).with_kind(crate::ErrorKind::Serialization)?,
|
&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)
|
serde_yaml::from_reader(reader).with_kind(crate::ErrorKind::Deserialization)
|
||||||
}
|
}
|
||||||
IoFormat::Cbor => {
|
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 => {
|
IoFormat::Toml | IoFormat::TomlPretty => {
|
||||||
let mut s = String::new();
|
let mut s = String::new();
|
||||||
@@ -754,7 +758,7 @@ impl IoFormat {
|
|||||||
serde_yaml::from_slice(slice).with_kind(crate::ErrorKind::Deserialization)
|
serde_yaml::from_slice(slice).with_kind(crate::ErrorKind::Deserialization)
|
||||||
}
|
}
|
||||||
IoFormat::Cbor => {
|
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 => {
|
IoFormat::Toml | IoFormat::TomlPretty => {
|
||||||
serde_toml::from_slice(slice).with_kind(crate::ErrorKind::Deserialization)
|
serde_toml::from_slice(slice).with_kind(crate::ErrorKind::Deserialization)
|
||||||
|
|||||||
Reference in New Issue
Block a user