Skip to content

Commit

Permalink
Basic functionality implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
lukewarmtemp committed Jul 11, 2023
1 parent 7ad41b6 commit 72723d9
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 6 deletions.
56 changes: 56 additions & 0 deletions rust/src/sysroot_upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> {
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<String> {
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())
}
32 changes: 26 additions & 6 deletions src/daemon/rpmostree-sysroot-upgrader.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
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);

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 ());
new_base_rev = g_strdup (import->merge_commit.c_str ());
}
break;
}
case rpmostreecxx::RefspecType::Checksum:
Expand Down Expand Up @@ -522,7 +542,7 @@ rpmostree_sysroot_upgrader_pull_base (RpmOstreeSysrootUpgrader *self, const char
g_free (self->base_revision);
self->base_revision = util::move_nullify (new_base_rev);
}

*out_changed = changed;
return TRUE;
}
Expand Down

0 comments on commit 72723d9

Please sign in to comment.