From f817e1d4470b27c056dbc9d90e6e8d32cafe92e6 Mon Sep 17 00:00:00 2001 From: Luke Yang Date: Wed, 28 Jun 2023 14:34:48 -0400 Subject: [PATCH] Basic functionality implemented --- rust/src/sysroot_upgrade.rs | 56 +++++++++++++++++++++++ src/daemon/rpmostree-sysroot-upgrader.cxx | 30 ++++++++++-- 2 files changed, 81 insertions(+), 5 deletions(-) diff --git a/rust/src/sysroot_upgrade.rs b/rust/src/sysroot_upgrade.rs index 8699156ea9..0985ca38fb 100644 --- a/rust/src/sysroot_upgrade.rs +++ b/rust/src/sysroot_upgrade.rs @@ -191,3 +191,59 @@ pub(crate) fn purge_refspec(repo: &crate::FFIOstreeRepo, imgref: &str) -> CxxRes } Ok(()) } + +pub(crate) fn compare_local_to_remote_container( + repo: &crate::FFIOstreeRepo, + cancellable: &crate::FFIGCancellable, + imgref: &str, + remote_repo: &str, + remote_imgref: &str, +) -> Result { + let repo = &repo.glib_reborrow(); + let cancellable = cancellable.glib_reborrow(); + let imgref = &OstreeImageReference::try_from(imgref)?; + let r = Handle::current().block_on(async { + crate::utils::run_with_cancellable( + async { get_container_manifest_diff(repo, imgref, remote_repo, remote_imgref).await }, + &cancellable, + ) + .await + })?; + Ok(r) +} + +pub async fn get_container_manifest_diff( + repo: &ostree::Repo, + imgref: &OstreeImageReference, + remote_repo: &str, + remote_imgref: &str, +) -> Result { + use ostree_ext::container::ImageReference; + use ostree_ext::container::ManifestDiff; + use ostree_ext::container::OstreeImageReference; + use ostree_ext::container::SignatureSource; + use ostree_ext::container::Transport; + use ostree_ext::oci_spec::image::ImageManifest; + + let previous_state = ostree_ext::container::store::query_image_ref(&repo, &imgref.imgref) + .unwrap() + .unwrap(); + + let sigverify = SignatureSource::OstreeRemote(String::from(remote_repo)); + let transport = Transport::Registry; + let new_imgref = ImageReference { + transport, + name: String::from(remote_imgref), + }; + let container = OstreeImageReference { + sigverify, + imgref: new_imgref, + }; + let manifest = ostree_ext::container::fetch_manifest(&container) + .await + .unwrap(); + + let diff = ManifestDiff::new(&previous_state.manifest, &manifest.0); + + Ok(diff.export_as_string()) +} diff --git a/src/daemon/rpmostree-sysroot-upgrader.cxx b/src/daemon/rpmostree-sysroot-upgrader.cxx index 2beb3aee3b..88b4a0933f 100644 --- a/src/daemon/rpmostree-sysroot-upgrader.cxx +++ b/src/daemon/rpmostree-sysroot-upgrader.cxx @@ -433,13 +433,33 @@ rpmostree_sysroot_upgrader_pull_base (RpmOstreeSysrootUpgrader *self, const char if (override_commit) return glnx_throw (error, "Specifying commit overrides for container-image-reference " "type refspecs is not supported"); + if (check) - return glnx_throw (error, "Cannot currently check for updates without downloading"); + { + g_autofree char *origin_remote = NULL; + g_autofree char *origin_ref = NULL; + if (!ostree_parse_refspec (r.refspec.c_str (), &origin_remote, &origin_ref, error)) + return FALSE; - CXX_TRY_VAR (import, - rpmostreecxx::pull_container (*self->repo, *cancellable, r.refspec.c_str ()), - error); - new_base_rev = g_strdup (import->merge_commit.c_str ()); + CXX_TRY_VAR ( + res, + rpmostreecxx::compare_local_to_remote_container ( + *self->repo, *cancellable, r.refspec.c_str (), origin_remote, origin_ref), + error); + + rpmostree_output_message ("%s", res.c_str ()); + *out_changed = TRUE; + return TRUE; + } + else + { + CXX_TRY_VAR ( + import, + rpmostreecxx::pull_container (*self->repo, *cancellable, r.refspec.c_str ()), + error); + + new_base_rev = g_strdup (import->merge_commit.c_str ()); + } break; } case rpmostreecxx::RefspecType::Checksum: