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 5484ee2
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 5 deletions.
21 changes: 21 additions & 0 deletions rpmostree-cxxrs.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2064,6 +2064,11 @@ extern "C"
const ::rpmostreecxx::OstreeRepo &repo,
const ::rpmostreecxx::GCancellable &cancellable) noexcept;

::rust::repr::PtrLen rpmostreecxx$cxxbridge1$compare_local_to_remote_container (
const ::rpmostreecxx::OstreeRepo &repo, const ::rpmostreecxx::GCancellable &cancellable,
::rust::Str imgref, ::rust::Str remote_repo, ::rust::Str remote_imgref,
::rust::String *return$) noexcept;

::rust::repr::PtrLen rpmostreecxx$cxxbridge1$query_container_image_commit (
const ::rpmostreecxx::OstreeRepo &repo, ::rust::Str c,
::rust::Box< ::rpmostreecxx::ContainerImageState> *return$) noexcept;
Expand Down Expand Up @@ -3656,6 +3661,22 @@ container_prune (const ::rpmostreecxx::OstreeRepo &repo,
}
}

::rust::String
compare_local_to_remote_container (const ::rpmostreecxx::OstreeRepo &repo,
const ::rpmostreecxx::GCancellable &cancellable,
::rust::Str imgref, ::rust::Str remote_repo,
::rust::Str remote_imgref)
{
::rust::MaybeUninit< ::rust::String> return$;
::rust::repr::PtrLen error$ = rpmostreecxx$cxxbridge1$compare_local_to_remote_container (
repo, cancellable, imgref, remote_repo, remote_imgref, &return$.value);
if (error$.ptr)
{
throw ::rust::impl< ::rust::Error>::error (error$);
}
return ::std::move (return$.value);
}

::rust::Box< ::rpmostreecxx::ContainerImageState>
query_container_image_commit (const ::rpmostreecxx::OstreeRepo &repo, ::rust::Str c)
{
Expand Down
5 changes: 5 additions & 0 deletions rpmostree-cxxrs.h
Original file line number Diff line number Diff line change
Expand Up @@ -1768,6 +1768,11 @@ pull_container (const ::rpmostreecxx::OstreeRepo &repo,
void container_prune (const ::rpmostreecxx::OstreeRepo &repo,
const ::rpmostreecxx::GCancellable &cancellable);

::rust::String compare_local_to_remote_container (const ::rpmostreecxx::OstreeRepo &repo,
const ::rpmostreecxx::GCancellable &cancellable,
::rust::Str imgref, ::rust::Str remote_repo,
::rust::Str remote_imgref);

::rust::Box< ::rpmostreecxx::ContainerImageState>
query_container_image_commit (const ::rpmostreecxx::OstreeRepo &repo, ::rust::Str c);

Expand Down
7 changes: 7 additions & 0 deletions rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,13 @@ pub mod ffi {
c: &str,
) -> Result<Box<ContainerImageState>>;
fn purge_refspec(repo: &OstreeRepo, refspec: &str) -> Result<()>;
fn compare_local_to_remote_container(
repo: &OstreeRepo,
cancellable: &GCancellable,
imgref: &str,
remote_repo: &str,
remote_imgref: &str,
) -> Result<String>;
}

// core.rs
Expand Down
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())
}
30 changes: 25 additions & 5 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 (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:
Expand Down

0 comments on commit 5484ee2

Please sign in to comment.