Skip to content

Commit

Permalink
wip: Change to just using the archive to not use the manifest parsing.
Browse files Browse the repository at this point in the history
  • Loading branch information
Blu-J committed Nov 4, 2024
1 parent 74c37fb commit 7241c17
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
15 changes: 10 additions & 5 deletions core/startos/src/s9pk/v2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,10 @@ impl<S: From<TmpSource<PackSource>> + FileSource + Clone> S9pk<S> {

impl<S: ArchiveSource + Clone> S9pk<Section<S>> {
#[instrument(skip_all)]
pub async fn deserialize(
pub async fn archive(
source: &S,
commitment: Option<&MerkleArchiveCommitment>,
) -> Result<Self, Error> {
) -> Result<MerkleArchive<Section<S>>, Error> {
use tokio::io::AsyncReadExt;

let mut header = source
Expand All @@ -296,9 +296,14 @@ impl<S: ArchiveSource + Clone> S9pk<Section<S>> {
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<Self, Error> {
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),
Expand Down
27 changes: 22 additions & 5 deletions core/startos/src/version/v0_3_6_alpha_8.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
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};
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(
Expand Down Expand Up @@ -48,15 +50,30 @@ 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<MultiCursorFile>,
> = match get_archive.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 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::<serde_json::Value>(
&archive
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 7241c17

Please sign in to comment.