From d7a6f257a0bb214e38a207554da2c7aefe8f905c Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Mon, 13 Apr 2015 20:26:21 -0400 Subject: [PATCH] pull: Print GPG signature status as soon as its known --- src/ostree/ot-builtin-pull.c | 23 ++++++++++++++++++++++- src/ostree/ot-main.c | 24 ++++++++++++++++++++++++ src/ostree/ot-main.h | 2 ++ 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/src/ostree/ot-builtin-pull.c b/src/ostree/ot-builtin-pull.c index 91db17d1..5d9eac42 100644 --- a/src/ostree/ot-builtin-pull.c +++ b/src/ostree/ot-builtin-pull.c @@ -40,6 +40,20 @@ static int opt_depth = 0; { NULL } }; +static void +gpg_verify_result_cb (OstreeRepo *repo, + const char *checksum, + OstreeGpgVerifyResult *result, + GSConsole *console) +{ + /* Temporarily place the GSConsole stream (which is just stdout) + * back in normal mode before printing GPG verification results. */ + gs_console_end_status_line (console, NULL, NULL); + + g_print ("\n"); + ostree_print_gpg_verify_result (result); +} + gboolean ostree_builtin_pull (int argc, char **argv, GCancellable *cancellable, GError **error) { @@ -51,6 +65,7 @@ ostree_builtin_pull (int argc, char **argv, GCancellable *cancellable, GError ** GSConsole *console = NULL; gs_unref_ptrarray GPtrArray *refs_to_fetch = NULL; gs_unref_object OstreeAsyncProgress *progress = NULL; + gulong signal_handler_id = 0; context = g_option_context_new ("REMOTE [BRANCH...] - Download data from remote repository"); @@ -100,6 +115,9 @@ ostree_builtin_pull (int argc, char **argv, GCancellable *cancellable, GError ** { gs_console_begin_status_line (console, "", NULL, NULL); progress = ostree_async_progress_new_and_connect (ostree_repo_pull_default_console_progress_changed, console); + signal_handler_id = g_signal_connect (repo, "gpg-verify-result", + G_CALLBACK (gpg_verify_result_cb), + console); } { @@ -116,7 +134,7 @@ ostree_builtin_pull (int argc, char **argv, GCancellable *cancellable, GError ** g_variant_new_variant (g_variant_new_strv ((const char *const*) refs_to_fetch->pdata, -1))); g_variant_builder_add (&builder, "{s@v}", "depth", g_variant_new_variant (g_variant_new_int32 (opt_depth))); - + if (!ostree_repo_pull_with_options (repo, remote, g_variant_builder_end (&builder), progress, cancellable, error)) goto out; @@ -127,6 +145,9 @@ ostree_builtin_pull (int argc, char **argv, GCancellable *cancellable, GError ** ret = TRUE; out: + if (signal_handler_id > 0) + g_signal_handler_disconnect (repo, signal_handler_id); + if (console) gs_console_end_status_line (console, NULL, NULL); diff --git a/src/ostree/ot-main.c b/src/ostree/ot-main.c index 76dbb5c8..457aa3c4 100644 --- a/src/ostree/ot-main.c +++ b/src/ostree/ot-main.c @@ -385,3 +385,27 @@ ostree_ensure_repo_writable (OstreeRepo *repo, return ret; } + +void +ostree_print_gpg_verify_result (OstreeGpgVerifyResult *result) +{ + GString *buffer; + guint n_sigs, ii; + + n_sigs = ostree_gpg_verify_result_count_all (result); + + /* XXX If we ever add internationalization, use ngettext() here. */ + g_print ("Found %u signature%s:\n", n_sigs, n_sigs == 1 ? "" : "s"); + + buffer = g_string_sized_new (256); + + for (ii = 0; ii < n_sigs; ii++) + { + g_string_append_c (buffer, '\n'); + ostree_gpg_verify_result_describe (result, ii, buffer, " ", + OSTREE_GPG_SIGNATURE_FORMAT_DEFAULT); + } + + g_print ("%s", buffer->str); + g_string_free (buffer, TRUE); +} diff --git a/src/ostree/ot-main.h b/src/ostree/ot-main.h index 2ea57552..60ddb36a 100644 --- a/src/ostree/ot-main.h +++ b/src/ostree/ot-main.h @@ -59,3 +59,5 @@ gboolean ostree_admin_option_context_parse (GOptionContext *context, GCancellable *cancellable, GError **error); gboolean ostree_ensure_repo_writable (OstreeRepo *repo, GError **error); + +void ostree_print_gpg_verify_result (OstreeGpgVerifyResult *result);