From de7b750728fe455022763171cde06bb5ffb0749f Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Tue, 27 Oct 2015 17:34:39 -0400 Subject: [PATCH] app: Add rpmostree_print_package_diffs() Takes a GVariant returned by the daemon's various "PkgDiff" methods. --- src/app/rpmostree-dbus-helpers.c | 77 ++++++++++++++++++++++++++++++++ src/app/rpmostree-dbus-helpers.h | 3 ++ 2 files changed, 80 insertions(+) diff --git a/src/app/rpmostree-dbus-helpers.c b/src/app/rpmostree-dbus-helpers.c index 5fd6efc7..8be5813a 100644 --- a/src/app/rpmostree-dbus-helpers.c +++ b/src/app/rpmostree-dbus-helpers.c @@ -619,3 +619,80 @@ rpmostree_print_signatures (GVariant *variant, g_print ("%s", sigs_buffer->str); g_string_free (sigs_buffer, TRUE); } + +static gint +pkg_diff_variant_compare (gconstpointer a, + gconstpointer b, + gpointer unused) +{ + const char *pkg_name_a = NULL; + const char *pkg_name_b = NULL; + + g_variant_get_child ((GVariant *) a, 0, "&s", &pkg_name_a); + g_variant_get_child ((GVariant *) b, 0, "&s", &pkg_name_b); + + /* XXX Names should be unique since we're comparing packages + * from two different trees... right? */ + + return g_strcmp0 (pkg_name_a, pkg_name_b); +} + +static void +pkg_diff_variant_print (GVariant *variant) +{ + g_autoptr(GVariant) details = NULL; + const char *old_name, *old_evr, *old_arch; + const char *new_name, *new_evr, *new_arch; + gboolean have_old = FALSE; + gboolean have_new = FALSE; + + details = g_variant_get_child_value (variant, 2); + g_return_if_fail (details != NULL); + + have_old = g_variant_lookup (details, + "PreviousPackage", "(&s&s&s)", + &old_name, &old_evr, &old_arch); + + have_new = g_variant_lookup (details, + "NewPackage", "(&s&s&s)", + &new_name, &new_evr, &new_arch); + + if (have_old && have_new) + { + g_print ("!%s-%s-%s\n", old_name, old_evr, old_arch); + g_print ("=%s-%s-%s\n", new_name, new_evr, new_arch); + } + else if (have_old) + { + g_print ("-%s-%s-%s\n", old_name, old_evr, old_arch); + } + else if (have_new) + { + g_print ("+%s-%s-%s\n", new_name, new_evr, new_arch); + } +} + +void +rpmostree_print_package_diffs (GVariant *variant) +{ + GQueue queue = G_QUEUE_INIT; + GVariantIter iter; + GVariant *child; + + /* GVariant format should be a(sua{sv}) */ + + g_return_if_fail (variant != NULL); + + g_variant_iter_init (&iter, variant); + + /* Queue takes ownership of the child variant. */ + while ((child = g_variant_iter_next_value (&iter)) != NULL) + g_queue_insert_sorted (&queue, child, pkg_diff_variant_compare, NULL); + + while (!g_queue_is_empty (&queue)) + { + child = g_queue_pop_head (&queue); + pkg_diff_variant_print (child); + g_variant_unref (child); + } +} diff --git a/src/app/rpmostree-dbus-helpers.h b/src/app/rpmostree-dbus-helpers.h index f6d1ca02..27e14025 100644 --- a/src/app/rpmostree-dbus-helpers.h +++ b/src/app/rpmostree-dbus-helpers.h @@ -55,3 +55,6 @@ rpmostree_transaction_get_response_sync (RPMOSTreeSysroot *sysroot_proxy, void rpmostree_print_signatures (GVariant *variant, const gchar *sep); + +void +rpmostree_print_package_diffs (GVariant *variant);