Skip to content

Commit

Permalink
Basic functionality complete
Browse files Browse the repository at this point in the history
  • Loading branch information
lukewarmtemp committed Jul 18, 2023
1 parent 7ed27b8 commit ba53c46
Show file tree
Hide file tree
Showing 10 changed files with 517 additions and 355 deletions.
41 changes: 26 additions & 15 deletions rust/src/sysroot_upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,20 @@ async fn layer_progress_print(mut r: Receiver<ImportProgress>) {
}
}

fn default_container_pull_config() -> Result<ImageProxyConfig> {
fn default_container_pull_config(imgref: &OstreeImageReference) -> Result<ImageProxyConfig> {
let mut cfg = ImageProxyConfig::default();
let isolation_systemd = crate::utils::running_in_systemd().then(|| "rpm-ostree");
let isolation_default = rustix::process::getuid().is_root().then(|| "nobody");
let isolation_user = isolation_systemd.or(isolation_default);
ostree_container::merge_default_container_proxy_opts_with_isolation(&mut cfg, isolation_user)?;
if imgref.imgref.transport == ostree_container::Transport::ContainerStorage {
// Fetching from containers-storage, may require privileges to read files
ostree_container::merge_default_container_proxy_opts_with_isolation(&mut cfg, None)?;
} else {
let isolation_systemd = crate::utils::running_in_systemd().then(|| "rpm-ostree");
let isolation_default = rustix::process::getuid().is_root().then(|| "nobody");
let isolation_user = isolation_systemd.or(isolation_default);
ostree_container::merge_default_container_proxy_opts_with_isolation(
&mut cfg,
isolation_user,
)?;
}
Ok(cfg)
}

Expand All @@ -70,7 +78,7 @@ async fn pull_container_async(
imgref: &OstreeImageReference,
) -> Result<ContainerImageState> {
output_message(&format!("Pulling manifest: {}", &imgref));
let config = default_container_pull_config()?;
let config = default_container_pull_config(imgref)?;
let mut imp = ImageImporter::new(repo, imgref, config).await?;
let layer_progress = imp.request_progress();
let prep = match imp.prepare().await? {
Expand Down Expand Up @@ -220,14 +228,15 @@ pub async fn get_container_manifest_diff(
) -> 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 previous_state =
if let Some(r) = ostree_ext::container::store::query_image_ref(&repo, &imgref.imgref)? {
r
} else {
return Ok("".to_string())
};

let sigverify = SignatureSource::OstreeRemote(String::from(remote_repo));
let transport = Transport::Registry;
Expand All @@ -239,11 +248,13 @@ pub async fn get_container_manifest_diff(
sigverify,
imgref: new_imgref,
};
let manifest = ostree_ext::container::fetch_manifest(&container)
.await
.unwrap();
let (manifest, _) = if let r = ostree_ext::container::fetch_manifest(&container).await? {
r
} else {
return Ok("".to_string())
};

let diff = ManifestDiff::new(&previous_state.manifest, &manifest.0);
let diff = ManifestDiff::new(&previous_state.manifest, &manifest);

Ok(diff.export_as_string())
}
60 changes: 5 additions & 55 deletions src/app/rpmostree-builtin-upgrade.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,9 @@ rpmostree_builtin_upgrade (int argc, char **argv, RpmOstreeCommandInvocation *in
g_print ("Note: --check and --preview may be unreliable. See "
"https://github.com/coreos/rpm-ostree/issues/1579\n");
g_autoptr (GVariant) cached_update = NULL;
if (rpmostree_os_get_has_cached_update_rpm_diff (os_proxy))
if (rpmostree_os_get_has_cached_update_rpm_diff (os_proxy)) {
cached_update = rpmostree_os_dup_cached_update (os_proxy);

gboolean manifest_diff = FALSE;
// if (rpmostree_os_get_has_cached_update_manifest_diff (os_proxy)) {
manifest_diff = TRUE;
cached_update = rpmostree_os_dup_cached_update (os_proxy);
// }
}

if (!cached_update)
{
Expand All @@ -222,54 +217,9 @@ rpmostree_builtin_upgrade (int argc, char **argv, RpmOstreeCommandInvocation *in
else
{
/* preview --> verbose (i.e. we want the diff) */
if (!manifest_diff) {
if (!rpmostree_print_cached_update (cached_update, opt_preview, FALSE, cancellable,
error))
return FALSE;
}
else {
std::string test = "total:51,total_size:714.8 MB,total_removed:0,removed_size:0 bytes,total_added:0,added_size:0 bytes";
manifest_diff_add_db_diff (test, cancellable, error);



glnx_autofd int fd = -1;
g_autoptr (GError) local_error = NULL;
if (!glnx_openat_rdonly (AT_FDCWD, RPMOSTREE_AUTOUPDATES_CACHE_FILE, TRUE, &fd, &local_error))
{
if (!g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
return g_propagate_error (error, util::move_nullify (local_error)), FALSE;
return TRUE; /* Note early return */
}

/* sanity check there isn't something fishy going on before even reading it in */
struct stat stbuf;
if (!glnx_fstat (fd, &stbuf, error))
return FALSE;

if (!rpmostree_check_size_within_limit (stbuf.st_size, OSTREE_MAX_METADATA_SIZE,
RPMOSTREE_AUTOUPDATES_CACHE_FILE, error))
return FALSE;

g_autoptr (GBytes) data = glnx_fd_readall_bytes (fd, NULL, error);
if (!data)
return FALSE;

cached_update
= g_variant_ref_sink (g_variant_new_from_bytes (G_VARIANT_TYPE_VARDICT, data, FALSE));




// cached_update = rpmostree_os_dup_cached_update (os_proxy);
if (!rpmostree_print_cached_update_container (cached_update, opt_preview, FALSE, cancellable,
error))
{
return FALSE;
}

}

if (!rpmostree_print_cached_update (cached_update, opt_preview, FALSE, cancellable,
error))
return FALSE;
}
}
else if (!opt_reboot)
Expand Down
192 changes: 76 additions & 116 deletions src/app/rpmostree-clientlib.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1243,6 +1243,77 @@ rpmostree_print_diff_advisories (GVariant *rpm_diff, GVariant *advisories, gbool
return TRUE;
}

/* print "manifest-diff" */
gboolean
rpmostree_print_manifest_diff (GVariant *manifest_diff, guint maxkeylen, GError **error)
{
const gchar *total_str;
const gchar *total_size_str;
const gchar *total_removed_str;
const gchar *removed_size_str;
const gchar *total_added_str;
const gchar *added_size_str;

g_auto (GVariantDict) manifest_diff_dict;
g_variant_dict_init (&manifest_diff_dict, manifest_diff);

g_autoptr (GVariant) total
= g_variant_dict_lookup_value (&manifest_diff_dict, "total", G_VARIANT_TYPE ("s"));
if (!total)
return FALSE;

g_variant_get (total, "s", &total_str);
printf (" %*s%s %s", maxkeylen, "Total layers", strlen ("Total layers") ? ":" : " ", total_str);
printf("\n");

g_autoptr (GVariant) total_size
= g_variant_dict_lookup_value (&manifest_diff_dict, "total_size", G_VARIANT_TYPE ("s"));
if (!total_size)
return FALSE;

g_variant_get (total_size, "s", &total_size_str);
printf (" %*s%s %s", maxkeylen, "Size", strlen ("Size") ? ":" : " ", total_size_str);
printf("\n");

g_autoptr (GVariant) total_removed
= g_variant_dict_lookup_value (&manifest_diff_dict, "total_removed", G_VARIANT_TYPE ("s"));
if (!total_removed)
return FALSE;

g_variant_get (total_removed, "s", &total_removed_str);
printf (" %*s%s %s", maxkeylen, "Removed layers", strlen ("Removed layers") ? ":" : " ", total_removed_str);
printf("\n");

g_autoptr (GVariant) removed_size
= g_variant_dict_lookup_value (&manifest_diff_dict, "removed_size", G_VARIANT_TYPE ("s"));
if (!removed_size)
return FALSE;

g_variant_get (removed_size, "s", &removed_size_str);
printf (" %*s%s %s", maxkeylen, "Size", strlen ("Size") ? ":" : " ", removed_size_str);
printf("\n");

g_autoptr (GVariant) total_added
= g_variant_dict_lookup_value (&manifest_diff_dict, "total_added", G_VARIANT_TYPE ("s"));
if (!total_added)
return FALSE;

g_variant_get (total_added, "s", &total_added_str);
printf (" %*s%s %s", maxkeylen, "Added layers", strlen ("Added layers") ? ":" : " ", total_added_str);
printf("\n");

g_autoptr (GVariant) added_size
= g_variant_dict_lookup_value (&manifest_diff_dict, "added_size", G_VARIANT_TYPE ("s"));
if (!added_size)
return FALSE;

g_variant_get (added_size, "s", &added_size_str);
printf (" %*s%s %s", maxkeylen, "Size", strlen ("Size") ? ":" : " ", added_size_str);
printf("\n");

return TRUE;
}

/* this is used by both `status` and `upgrade --check/--preview` */
gboolean
rpmostree_print_cached_update (GVariant *cached_update, gboolean verbose,
Expand Down Expand Up @@ -1285,6 +1356,9 @@ rpmostree_print_cached_update (GVariant *cached_update, gboolean verbose,
g_autoptr (GVariant) rpm_diff
= g_variant_dict_lookup_value (&dict, "rpm-diff", G_VARIANT_TYPE ("a{sv}"));

g_autoptr (GVariant) manifest_diff
= g_variant_dict_lookup_value (&dict, "manifest-diff", G_VARIANT_TYPE ("a{sv}"));

g_autoptr (GVariant) advisories
= g_variant_dict_lookup_value (&dict, "advisories", G_VARIANT_TYPE ("a(suuasa{sv})"));

Expand All @@ -1306,128 +1380,14 @@ rpmostree_print_cached_update (GVariant *cached_update, gboolean verbose,
if (!rpmostree_print_diff_advisories (rpm_diff, advisories, verbose, verbose_advisories,
max_key_len, error))
return FALSE;

return TRUE;
}

gboolean
rpmostree_print_cached_update_container (GVariant *cached_update, gboolean verbose,
gboolean verbose_advisories, GCancellable *cancellable,
GError **error)
{
GLNX_AUTO_PREFIX_ERROR ("Retrieving cached update", error);
g_print("Enter Print Func\n");

g_auto (GVariantDict) dict;
g_variant_dict_init (&dict, cached_update);
if (cached_update == NULL)
g_print("Failure\n");
g_print("Not failure\n");

/* let's just extract 📤 all the info ahead of time */

// const char *total;
// if (!g_variant_dict_lookup (&dict, "total", "&s", &total))
// return glnx_throw (error, "Missing \"total\" key");

if (!g_variant_dict_lookup_value (&dict, "manifest-diff", G_VARIANT_TYPE ("a{sv}")))
return glnx_throw (error, "Missing \"manifest-diff\" key");

g_autoptr (GVariant) mainfest_diff
= g_variant_dict_lookup_value (&dict, "manifest-diff", G_VARIANT_TYPE ("a{sv}"));

g_auto (GVariantDict) manifest_diff_dict;
g_variant_dict_init (&manifest_diff_dict, mainfest_diff);

g_autoptr (GVariant) total
= g_variant_dict_lookup_value (&manifest_diff_dict, "total", G_VARIANT_TYPE ("s"));
if (!total)
if (!rpmostree_print_manifest_diff (manifest_diff, max_key_len, error))
return FALSE;

const gchar *tmp1;
g_variant_get (total, "s", &tmp1);
g_print("%s\n", tmp1);

// g_auto (GVariantDict) dict;
// g_variant_dict_init (&dict, cached_update);

// /* let's just extract 📤 all the info ahead of time */

// g_autoptr (GVariant) manifest_diff
// = g_variant_dict_lookup_value (&dict, "manifest-diff", G_VARIANT_TYPE ("a{sv}"));

// g_autoptr (GVariantIter) iter1 = NULL;
// g_variant_get (manifest_diff, "a{sv}", &iter1);

// if (!manifest_diff)
// g_print("WE Failed");

// const gchar *key;
// const gchar *value;
// while (g_variant_iter_loop (iter1, "{sv}", &key, &value))
// {
// g_print("%s", key);
// }

// g_auto (GVariantDict) rpm_diff_dict;
// g_variant_dict_init (&rpm_diff_dict, rpm_diff);

// g_autoptr (GVariant) total
// = g_variant_dict_lookup_value (manifest_diff, "total", G_VARIANT_TYPE ("s"));
// if (!total) {
// g_print("WE Failed");
// return FALSE;
// }

// g_autoptr (GVariant) total_size = _rpmostree_vardict_lookup_value_required (
// &rpm_diff_dict, "total_size", RPMOSTREE_DIFF_MODIFIED_GVARIANT_FORMAT, error);
// if (!total_size)
// return FALSE;

// g_autoptr (GVariant) total_removed = _rpmostree_vardict_lookup_value_required (
// &rpm_diff_dict, "total_removed", RPMOSTREE_DIFF_MODIFIED_GVARIANT_FORMAT, error);
// if (!total_removed)
// return FALSE;

// g_autoptr (GVariant) removed_size = _rpmostree_vardict_lookup_value_required (
// &rpm_diff_dict, "removed_size", RPMOSTREE_DIFF_MODIFIED_GVARIANT_FORMAT, error);
// if (!removed_size)
// return FALSE;

// g_autoptr (GVariant) total_added = _rpmostree_vardict_lookup_value_required (
// &rpm_diff_dict, "total_added", RPMOSTREE_DIFF_MODIFIED_GVARIANT_FORMAT, error);
// if (!total_added)
// return FALSE;

// g_autoptr (GVariant) added_size = _rpmostree_vardict_lookup_value_required (
// &rpm_diff_dict, "added_size", RPMOSTREE_DIFF_MODIFIED_GVARIANT_FORMAT, error);
// if (!added_size)
// return FALSE;

// const gchar *tmp1;
// const gchar *tmp2;
// const gchar *tmp3;
// const gchar *tmp4;
// const gchar *tmp5;
// const gchar *tmp6;

// g_variant_get (total, "s", &tmp1);
// g_variant_get (total_size, "s", &tmp2);
// g_variant_get (total_removed, "s", &tmp3);
// g_variant_get (removed_size, "s", &tmp4);
// g_variant_get (total_added, "s", &tmp5);
// g_variant_get (added_size, "s", &tmp6);

// g_print("%s", tmp1);
// g_print("%s", tmp2);
// g_print("%s", tmp3);
// g_print("%s", tmp4);
// g_print("%s", tmp5);
// g_print("%s", tmp6);

return TRUE;
}


/* Query systemd for systemd unit's object path using method_name provided with
* parameters. The reply_type of method_name must be G_VARIANT_TYPE_TUPLE. */
gboolean
Expand Down
6 changes: 2 additions & 4 deletions src/app/rpmostree-clientlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,9 @@ gboolean rpmostree_print_diff_advisories (GVariant *rpm_diff, GVariant *advisori
gboolean verbose, gboolean verbose_advisories,
guint max_key_len, GError **error);

gboolean rpmostree_print_cached_update (GVariant *cached_update, gboolean verbose,
gboolean verbose_advisories, GCancellable *cancellable,
GError **error);
gboolean rpmostree_print_manifest_diff (GVariant *manifest_diff, guint maxkeylen, GError **error);

gboolean rpmostree_print_cached_update_container (GVariant *cached_update, gboolean verbose,
gboolean rpmostree_print_cached_update (GVariant *cached_update, gboolean verbose,
gboolean verbose_advisories, GCancellable *cancellable,
GError **error);

Expand Down
1 change: 0 additions & 1 deletion src/daemon/org.projectatomic.rpmostree1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@
<annotation name="org.qtproject.QtDBus.QtTypeName" value="QVariantMap"/>
</property>
<property name="HasCachedUpdateRpmDiff" type="b" access="read"/>
<property name="HasCachedUpdateManifestDiff" type="b" access="read"/>

<!-- Available options:
"mode" (type 's')
Expand Down
Loading

0 comments on commit ba53c46

Please sign in to comment.