move manifest to parent

This commit is contained in:
Aiden McClelland
2021-07-12 15:29:31 -06:00
parent d26e08014f
commit 36275f4a81
2 changed files with 31 additions and 17 deletions

View File

@@ -3,7 +3,7 @@ use std::sync::Arc;
use indexmap::{IndexMap, IndexSet}; use indexmap::{IndexMap, IndexSet};
use patch_db::json_ptr::JsonPointer; use patch_db::json_ptr::JsonPointer;
use patch_db::{HasModel, Map, MapModel, OptionModel}; use patch_db::{DbHandle, HasModel, Map, MapModel, OptionModel};
use reqwest::Url; use reqwest::Url;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_json::Value; use serde_json::Value;
@@ -12,7 +12,7 @@ use crate::config::spec::{PackagePointerSpecVariant, SystemPointerSpec};
use crate::install::progress::InstallProgress; use crate::install::progress::InstallProgress;
use crate::net::interface::InterfaceId; use crate::net::interface::InterfaceId;
use crate::net::Network; use crate::net::Network;
use crate::s9pk::manifest::{Manifest, PackageId}; use crate::s9pk::manifest::{Manifest, ManifestModel, PackageId};
use crate::status::health_check::HealthCheckId; use crate::status::health_check::HealthCheckId;
use crate::status::Status; use crate::status::Status;
use crate::util::Version; use crate::util::Version;
@@ -115,24 +115,25 @@ pub enum PackageDataEntry {
#[serde(rename_all = "kebab-case")] #[serde(rename_all = "kebab-case")]
Installing { Installing {
static_files: StaticFiles, static_files: StaticFiles,
temp_manifest: Manifest, manifest: Manifest,
install_progress: Arc<InstallProgress>, install_progress: Arc<InstallProgress>,
}, // { state: "installing", 'install-progress': InstallProgress } }, // { state: "installing", 'install-progress': InstallProgress }
#[serde(rename_all = "kebab-case")] #[serde(rename_all = "kebab-case")]
Updating { Updating {
static_files: StaticFiles, static_files: StaticFiles,
temp_manifest: Manifest, manifest: Manifest,
installed: InstalledPackageDataEntry, installed: InstalledPackageDataEntry,
install_progress: Arc<InstallProgress>, install_progress: Arc<InstallProgress>,
}, },
#[serde(rename_all = "kebab-case")] #[serde(rename_all = "kebab-case")]
Removing { Removing {
static_files: StaticFiles, static_files: StaticFiles,
temp_manifest: Manifest, manifest: Manifest,
}, },
#[serde(rename_all = "kebab-case")] #[serde(rename_all = "kebab-case")]
Installed { Installed {
static_files: StaticFiles, static_files: StaticFiles,
manifest: Manifest,
installed: InstalledPackageDataEntry, installed: InstalledPackageDataEntry,
}, },
} }
@@ -143,13 +144,14 @@ impl PackageDataEntryModel {
pub fn install_progress(self) -> OptionModel<InstallProgress> { pub fn install_progress(self) -> OptionModel<InstallProgress> {
self.0.child("install-progress").into() self.0.child("install-progress").into()
} }
pub fn manifest(self) -> ManifestModel {
self.0.child("manifest").into()
}
} }
#[derive(Debug, Deserialize, Serialize, HasModel)] #[derive(Debug, Deserialize, Serialize, HasModel)]
#[serde(rename_all = "kebab-case")] #[serde(rename_all = "kebab-case")]
pub struct InstalledPackageDataEntry { pub struct InstalledPackageDataEntry {
#[model]
pub manifest: Manifest,
#[model] #[model]
pub status: Status, pub status: Status,
pub system_pointers: Vec<SystemPointerSpec>, pub system_pointers: Vec<SystemPointerSpec>,
@@ -160,6 +162,13 @@ pub struct InstalledPackageDataEntry {
#[model] #[model]
pub interface_info: InterfaceInfo, pub interface_info: InterfaceInfo,
} }
impl InstalledPackageDataEntryModel {
pub fn manifest(self) -> ManifestModel {
let mut ptr = JsonPointer::from(self);
ptr.pop_end();
PackageDataEntryModel::from(ptr).manifest()
}
}
#[derive(Clone, Debug, Default, Deserialize, Serialize, HasModel)] #[derive(Clone, Debug, Default, Deserialize, Serialize, HasModel)]
#[serde(rename_all = "kebab-case")] #[serde(rename_all = "kebab-case")]

View File

@@ -89,19 +89,23 @@ pub async fn download_install_s9pk(
let static_files = StaticFiles::remote(pkg_id, version, temp_manifest.assets.icon_type()); let static_files = StaticFiles::remote(pkg_id, version, temp_manifest.assets.icon_type());
let mut pde = pkg_data_entry.get_mut(&mut db).await?; let mut pde = pkg_data_entry.get_mut(&mut db).await?;
match pde.take() { match pde.take() {
Some(PackageDataEntry::Installed { installed, .. }) => { Some(PackageDataEntry::Installed {
installed,
manifest,
static_files,
}) => {
*pde = Some(PackageDataEntry::Updating { *pde = Some(PackageDataEntry::Updating {
install_progress: progress.clone(), install_progress: progress.clone(),
static_files, static_files,
installed, installed,
temp_manifest: temp_manifest.clone(), manifest,
}) })
} }
None => { None => {
*pde = Some(PackageDataEntry::Installing { *pde = Some(PackageDataEntry::Installing {
install_progress: progress.clone(), install_progress: progress.clone(),
static_files, static_files,
temp_manifest: temp_manifest.clone(), manifest: temp_manifest.clone(),
}) })
} }
_ => { _ => {
@@ -393,7 +397,6 @@ pub async fn install_s9pk<R: AsyncRead + AsyncSeek + Unpin>(
}) })
.collect(); .collect();
let installed = InstalledPackageDataEntry { let installed = InstalledPackageDataEntry {
manifest: manifest.clone(),
status: Status { status: Status {
configured: manifest.config.is_none(), configured: manifest.config.is_none(),
main: MainStatus::Stopped, main: MainStatus::Stopped,
@@ -433,23 +436,25 @@ pub async fn install_s9pk<R: AsyncRead + AsyncSeek + Unpin>(
&mut *pde, &mut *pde,
PackageDataEntry::Installed { PackageDataEntry::Installed {
installed, installed,
manifest: manifest.clone(),
static_files, static_files,
}, },
); );
pde.save(&mut tx).await?; pde.save(&mut tx).await?;
if let PackageDataEntry::Updating { if let PackageDataEntry::Updating {
installed: prev, .. installed: prev,
manifest: prev_manifest,
..
} = prev } = prev
{ {
let mut configured = prev.status.configured; let mut configured = prev.status.configured;
if let Some(res) = prev if let Some(res) = prev_manifest
.manifest
.migrations .migrations
.to( .to(
version, version,
pkg_id, pkg_id,
&prev.manifest.version, &prev_manifest.version,
&prev.manifest.volumes, &prev_manifest.volumes,
&hosts, &hosts,
) )
.await? .await?
@@ -460,7 +465,7 @@ pub async fn install_s9pk<R: AsyncRead + AsyncSeek + Unpin>(
if let Some(res) = manifest if let Some(res) = manifest
.migrations .migrations
.from( .from(
&prev.manifest.version, &prev_manifest.version,
pkg_id, pkg_id,
version, version,
&manifest.volumes, &manifest.volumes,