From 7241c170b7ae03b8c509f041159d619b6c400040 Mon Sep 17 00:00:00 2001 From: J H Date: Mon, 4 Nov 2024 13:29:53 -0700 Subject: [PATCH] wip: Change to just using the archive to not use the manifest parsing. --- core/startos/src/s9pk/v2/mod.rs | 15 ++++++++---- core/startos/src/version/v0_3_6_alpha_8.rs | 27 ++++++++++++++++++---- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/core/startos/src/s9pk/v2/mod.rs b/core/startos/src/s9pk/v2/mod.rs index 0c4db695b..7a94c0d79 100644 --- a/core/startos/src/s9pk/v2/mod.rs +++ b/core/startos/src/s9pk/v2/mod.rs @@ -276,10 +276,10 @@ impl> + FileSource + Clone> S9pk { impl S9pk> { #[instrument(skip_all)] - pub async fn deserialize( + pub async fn archive( source: &S, commitment: Option<&MerkleArchiveCommitment>, - ) -> Result { + ) -> Result>, Error> { use tokio::io::AsyncReadExt; let mut header = source @@ -296,9 +296,14 @@ impl S9pk> { ErrorKind::ParseS9pk, "Invalid Magic or Unexpected Version" ); - - let mut archive = - MerkleArchive::deserialize(source, SIG_CONTEXT, &mut header, commitment).await?; + MerkleArchive::deserialize(source, SIG_CONTEXT, &mut header, commitment).await + } + #[instrument(skip_all)] + pub async fn deserialize( + source: &S, + commitment: Option<&MerkleArchiveCommitment>, + ) -> Result { + let mut archive = Self::archive(source, commitment).await?; archive.sort_by(|a, b| match (priority(a), priority(b)) { (Some(a), Some(b)) => a.cmp(&b), diff --git a/core/startos/src/version/v0_3_6_alpha_8.rs b/core/startos/src/version/v0_3_6_alpha_8.rs index 740126ed1..43f45eedb 100644 --- a/core/startos/src/version/v0_3_6_alpha_8.rs +++ b/core/startos/src/version/v0_3_6_alpha_8.rs @@ -1,10 +1,9 @@ use exver::{PreReleaseSegment, VersionRange}; use imbl_value::{json, InOMap}; -use tokio::process::Command; +use tokio::{fs::File, process::Command}; use super::v0_3_5::V0_3_0_COMPAT; use super::{v0_3_6_alpha_7, VersionT}; -use crate::install::PKG_ARCHIVE_DIR; use crate::prelude::*; use crate::s9pk::manifest::{DeviceFilter, Manifest}; use crate::s9pk::merkle_archive::{Entry, MerkleArchive}; @@ -12,6 +11,9 @@ use crate::s9pk::v2::SIG_CONTEXT; use crate::s9pk::{manifest, S9pk}; use crate::util::io::create_file; use crate::util::Invoke; +use crate::{ + install::PKG_ARCHIVE_DIR, s9pk::merkle_archive::source::multi_cursor_file::MultiCursorFile, +}; lazy_static::lazy_static! { static ref V0_3_6_alpha_8: exver::Version = exver::Version::new( @@ -48,7 +50,14 @@ impl VersionT for Version { continue; } - let original_pack = match S9pk::open(&s9pk_path, None).await { + let get_archive = async { + let multi_cursor = MultiCursorFile::from(File::open(&s9pk_path).await?); + Ok::<_, Error>(S9pk::archive(&multi_cursor, None).await?) + }; + + let archive: MerkleArchive< + crate::s9pk::merkle_archive::source::Section, + > = match get_archive.await { Ok(a) => a, Err(e) => { tracing::error!("Error opening s9pk for install: {e}"); @@ -56,7 +65,15 @@ impl VersionT for Version { continue; } }; - let archive = original_pack.as_archive(); + // let original_pack = match S9pk::open(&s9pk_path, None).await { + // Ok(a) => a, + // Err(e) => { + // tracing::error!("Error opening s9pk for install: {e}"); + // tracing::debug!("{e:?}"); + // continue; + // } + // }; + // let archive = original_pack.as_archive(); let previous_manifest: Value = serde_json::from_slice::( &archive @@ -97,7 +114,7 @@ impl VersionT for Version { let mut tmp_file = create_file(&tmp_path).await?; // TODO, wouldn't this break in the later versions of the manifest that would need changes, this doesn't seem to be a good way to handle this let manifest: Manifest = from_value(manifest.clone())?; - let mut s9pk: S9pk<_> = S9pk::new_with_manifest(archive.clone(), None, manifest); + let mut s9pk: S9pk<_> = S9pk::new_with_manifest(archive, None, manifest); let s9pk_compat_key = ctx.account.read().await.compat_s9pk_key.clone(); s9pk.as_archive_mut() .set_signer(s9pk_compat_key, SIG_CONTEXT);