From e3f7e857e3a63c3768861bba0ba9c79cd5006dd0 Mon Sep 17 00:00:00 2001 From: Aiden McClelland Date: Wed, 10 Nov 2021 13:22:28 -0700 Subject: [PATCH] eos-version-compat --- appmgr/src/db/model.rs | 8 +------- appmgr/src/install/mod.rs | 16 ++++++++-------- appmgr/src/s9pk/manifest.rs | 9 +++++++-- appmgr/src/version/mod.rs | 1 + appmgr/src/version/v0_3_0.rs | 15 +++++++++++++++ 5 files changed, 32 insertions(+), 17 deletions(-) diff --git a/appmgr/src/db/model.rs b/appmgr/src/db/model.rs index 61667fba9..51f5b1a72 100644 --- a/appmgr/src/db/model.rs +++ b/appmgr/src/db/model.rs @@ -39,13 +39,7 @@ impl Database { id, version: Current::new().semver().into(), last_backup: None, - eos_version_compat: VersionRange::Conj( - Box::new(VersionRange::Anchor( - emver::GTE, - emver::Version::new(0, 3, 0, 0), - )), - Box::new(VersionRange::Anchor(emver::LTE, Current::new().semver())), - ), + eos_version_compat: Current::new().compat().clone(), lan_address: format!("https://{}.local", hostname).parse().unwrap(), tor_address: format!("http://{}", tor_key.public().get_onion_address()) .parse() diff --git a/appmgr/src/install/mod.rs b/appmgr/src/install/mod.rs index 38d731d67..c48613c01 100644 --- a/appmgr/src/install/mod.rs +++ b/appmgr/src/install/mod.rs @@ -84,19 +84,19 @@ pub async fn install( let reg_url = ctx.package_registry_url().await?; let (man_res, s9pk) = tokio::try_join!( reqwest::get(format!( - "{}/package/manifest/{}?version={}&eos-version={}&arch={}", + "{}/package/manifest/{}?version={}&eos-version-compat={}&arch={}", reg_url, pkg_id, version, - Current::new().semver(), + Current::new().compat(), platforms::TARGET_ARCH, )), reqwest::get(format!( - "{}/package/{}.s9pk?version={}&eos-version={}&arch={}", + "{}/package/{}.s9pk?version={}&eos-version-compat={}&arch={}", reg_url, pkg_id, version, - Current::new().semver(), + Current::new().compat(), platforms::TARGET_ARCH, )) ) @@ -395,11 +395,11 @@ pub async fn install_s9pk( let reg_url = ctx.package_registry_url().await?; for (dep, info) in &manifest.dependencies.0 { let manifest: Option = match reqwest::get(format!( - "{}/package/manifest/{}?version={}&eos-version={}&arch={}", + "{}/package/manifest/{}?version={}&eos-version-compat={}&arch={}", reg_url, dep, info.version, - Current::new().semver(), + Current::new().compat(), platforms::TARGET_ARCH, )) .await @@ -425,11 +425,11 @@ pub async fn install_s9pk( if tokio::fs::metadata(&icon_path).await.is_err() { tokio::fs::create_dir_all(&dir).await?; let icon = reqwest::get(format!( - "{}/package/icon/{}?version={}&eos-version={}&arch={}", + "{}/package/icon/{}?version={}&eos-version-compat={}&arch={}", reg_url, dep, info.version, - Current::new().semver(), + Current::new().compat(), platforms::TARGET_ARCH, )) .await diff --git a/appmgr/src/s9pk/manifest.rs b/appmgr/src/s9pk/manifest.rs index a46e8bc90..567ec447d 100644 --- a/appmgr/src/s9pk/manifest.rs +++ b/appmgr/src/s9pk/manifest.rs @@ -15,6 +15,7 @@ use crate::migration::Migrations; use crate::net::interface::Interfaces; use crate::status::health_check::HealthChecks; use crate::util::Version; +use crate::version::{Current, VersionT}; use crate::volume::Volumes; pub const SYSTEM_PACKAGE_ID: PackageId<&'static str> = PackageId(SYSTEM_ID); @@ -97,9 +98,15 @@ where } } +fn current_version() -> Version { + Current::new().semver().into() +} + #[derive(Clone, Debug, Deserialize, Serialize, HasModel)] #[serde(rename_all = "kebab-case")] pub struct Manifest { + #[serde(default = "current_version")] + pub eos_version: Version, pub id: PackageId, pub title: String, #[model] @@ -127,8 +134,6 @@ pub struct Manifest { pub properties: Option, #[model] pub volumes: Volumes, - // #[serde(default = "current_version")] - pub min_os_version: Version, // #[serde(default)] pub interfaces: Interfaces, // #[serde(default)] diff --git a/appmgr/src/version/mod.rs b/appmgr/src/version/mod.rs index 38be443ff..f2fab7272 100644 --- a/appmgr/src/version/mod.rs +++ b/appmgr/src/version/mod.rs @@ -27,6 +27,7 @@ where type Previous: VersionT; fn new() -> Self; fn semver(&self) -> emver::Version; + fn compat(&self) -> &'static emver::VersionRange; async fn up(&self, db: &mut Db) -> Result<(), Error>; async fn down(&self, db: &mut Db) -> Result<(), Error>; async fn commit(&self, db: &mut Db) -> Result<(), Error> { diff --git a/appmgr/src/version/v0_3_0.rs b/appmgr/src/version/v0_3_0.rs index d5b96e694..80b984920 100644 --- a/appmgr/src/version/v0_3_0.rs +++ b/appmgr/src/version/v0_3_0.rs @@ -1,6 +1,18 @@ +use emver::VersionRange; +use lazy_static::lazy_static; + use super::*; const V0_3_0: emver::Version = emver::Version::new(0, 3, 0, 0); +lazy_static! { + static ref V0_3_0_COMPAT: VersionRange = VersionRange::Conj( + Box::new(VersionRange::Anchor( + emver::GTE, + emver::Version::new(0, 3, 0, 0), + )), + Box::new(VersionRange::Anchor(emver::LTE, Current::new().semver())), + ); +} pub struct Version; #[async_trait] @@ -12,6 +24,9 @@ impl VersionT for Version { fn semver(&self) -> emver::Version { V0_3_0 } + fn compat(&self) -> &'static VersionRange { + &*V0_3_0_COMPAT + } async fn up(&self, _db: &mut Db) -> Result<(), Error> { Ok(()) }