diff --git a/appmgr/src/db/model.rs b/appmgr/src/db/model.rs index 0869f2dcf..c9bbdd1e8 100644 --- a/appmgr/src/db/model.rs +++ b/appmgr/src/db/model.rs @@ -51,6 +51,7 @@ impl Database { clearnet: Vec::new(), }, share_stats: false, + update_progress: None, }, package_data: AllPackageData::default(), broken_packages: Vec::new(), @@ -71,7 +72,6 @@ pub struct ServerInfo { pub version: Version, pub lan_address: Url, pub tor_address: Url, - #[serde(flatten)] pub status: ServerStatus, pub eos_marketplace: Url, pub package_marketplace: Option, // None implies use eos_marketplace @@ -79,18 +79,15 @@ pub struct ServerInfo { pub unread_notification_count: u64, pub connection_addresses: ConnectionAddresses, pub share_stats: bool, + pub update_progress: Option, } #[derive(Debug, Deserialize, Serialize)] #[serde(rename_all = "kebab-case")] -#[serde(tag = "status")] pub enum ServerStatus { - Running {}, - #[serde(rename_all = "kebab-case")] - Updating { - update_progress: UpdateProgress, - }, - BackingUp {}, + Running, + Updating, + BackingUp, } #[derive(Debug, Deserialize, Serialize)] diff --git a/appmgr/src/update/mod.rs b/appmgr/src/update/mod.rs index ed329027e..899b9450d 100644 --- a/appmgr/src/update/mod.rs +++ b/appmgr/src/update/mod.rs @@ -165,12 +165,11 @@ async fn maybe_do_update(ctx: RpcContext) -> Result>, Error } let mut db = ctx.db.handle(); let mut tx = db.begin().await?; - let mut status = crate::db::DatabaseModel::new() + let mut info = crate::db::DatabaseModel::new() .server_info() - .status() .get_mut(&mut tx) .await?; - match &*status { + match &info.status { ServerStatus::Updating { .. } => { return Err(Error::new( anyhow!("Server is already updating!"), @@ -197,13 +196,12 @@ async fn maybe_do_update(ctx: RpcContext) -> Result>, Error new_label, ) .await?; - *status = ServerStatus::Updating { - update_progress: UpdateProgress { - size, - downloaded: 0, - }, - }; - status.save(&mut tx).await?; + info.status = ServerStatus::Updating; + info.update_progress = Some(UpdateProgress { + size, + downloaded: 0, + }); + info.save(&mut tx).await?; let rev = tx.commit(None).await?; tokio::spawn(async move { @@ -211,19 +209,14 @@ async fn maybe_do_update(ctx: RpcContext) -> Result>, Error Ok(()) => todo!("issue notification"), Err(e) => { let mut db = ctx.db.handle(); - let mut status = crate::db::DatabaseModel::new() + let mut info = crate::db::DatabaseModel::new() .server_info() - .status() .get_mut(&mut db) .await .expect("could not access status"); - *status = ServerStatus::Updating { - update_progress: UpdateProgress { - size, - downloaded: 0, - }, - }; - status.save(&mut db).await.expect("could not save status"); + info.status = ServerStatus::Running; + info.update_progress = None; + info.save(&mut db).await.expect("could not save status"); todo!("{}, issue notification", e) }