From 6bbbf612095b4b72cf267da5f736e2c37540c109 Mon Sep 17 00:00:00 2001 From: Luke Yang Date: Mon, 17 Jul 2023 10:54:39 -0400 Subject: [PATCH] wip --- src/app/rpmostree-builtin-upgrade.cxx | 36 +++- src/app/rpmostree-clientlib.cxx | 86 +++++++++ src/app/rpmostree-clientlib.h | 4 + src/daemon/org.projectatomic.rpmostree1.xml | 1 + src/daemon/rpmostree-sysroot-upgrader.cxx | 172 +++++++++++++++++ src/daemon/rpmostreed-deployment-utils.cxx | 204 +++++++++++++++++--- src/daemon/rpmostreed-deployment-utils.h | 2 +- src/daemon/rpmostreed-os.cxx | 18 +- src/daemon/rpmostreed-transaction-types.cxx | 56 ++++-- src/lib/rpmostree-db.c | 47 +++++ src/lib/rpmostree-db.h | 6 + 11 files changed, 586 insertions(+), 46 deletions(-) diff --git a/src/app/rpmostree-builtin-upgrade.cxx b/src/app/rpmostree-builtin-upgrade.cxx index 6360cbcfc3..1bc3cdb1d7 100644 --- a/src/app/rpmostree-builtin-upgrade.cxx +++ b/src/app/rpmostree-builtin-upgrade.cxx @@ -204,21 +204,43 @@ 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)) { + g_print ("yes rpm diff.\n"); cached_update = rpmostree_os_dup_cached_update (os_proxy); + } - if (!cached_update) - { - g_print ("No updates available.\n"); - invocation->exit_code = RPM_OSTREE_EXIT_UNCHANGED; - } - else + g_autoptr (GVariant) cached_update_container = NULL; + if (rpmostree_os_get_has_cached_update_manifest_diff (os_proxy)) { + g_print ("yes container diff.\n"); + cached_update_container = rpmostree_os_dup_cached_update (os_proxy); + } + + g_print ("exit diff checks\n"); + + // cached_update = rpmostree_os_dup_cached_update (os_proxy); + + if (cached_update) { /* preview --> verbose (i.e. we want the diff) */ + // if (!rpmostree_print_cached_update (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 (cached_update_container) { + if (!rpmostree_print_cached_update_container (cached_update, opt_preview, FALSE, cancellable, + error)) + return FALSE; + } + else + { + g_print ("No updates available.\n"); + invocation->exit_code = RPM_OSTREE_EXIT_UNCHANGED; + } + } else if (!opt_reboot) { diff --git a/src/app/rpmostree-clientlib.cxx b/src/app/rpmostree-clientlib.cxx index 65aa33cf93..cfaefc2b42 100644 --- a/src/app/rpmostree-clientlib.cxx +++ b/src/app/rpmostree-clientlib.cxx @@ -1310,6 +1310,92 @@ rpmostree_print_cached_update (GVariant *cached_update, gboolean verbose, 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_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 (&rpm_diff_dict, "total_size", G_VARIANT_TYPE ("s")); + // if (!total) + // g_print("WE Failed2"); + // 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 diff --git a/src/app/rpmostree-clientlib.h b/src/app/rpmostree-clientlib.h index dd4f22c4c8..08d7a2a5f0 100644 --- a/src/app/rpmostree-clientlib.h +++ b/src/app/rpmostree-clientlib.h @@ -115,6 +115,10 @@ gboolean rpmostree_print_cached_update (GVariant *cached_update, gboolean verbos gboolean verbose_advisories, GCancellable *cancellable, GError **error); +gboolean rpmostree_print_cached_update_container (GVariant *cached_update, gboolean verbose, + gboolean verbose_advisories, GCancellable *cancellable, + GError **error); + void rpmostree_print_advisories (GVariant *advisories, gboolean verbose, guint max_key_len); gboolean get_sd_unit_objpath (GDBusConnection *connection, const char *method_name, diff --git a/src/daemon/org.projectatomic.rpmostree1.xml b/src/daemon/org.projectatomic.rpmostree1.xml index 7765b3fe54..f888bf4cd1 100644 --- a/src/daemon/org.projectatomic.rpmostree1.xml +++ b/src/daemon/org.projectatomic.rpmostree1.xml @@ -106,6 +106,7 @@ +