diff options
author | Dan Nicholson <dbn@endlessos.org> | 2023-01-29 22:45:29 -0700 |
---|---|---|
committer | Dan Nicholson <dbn@endlessos.org> | 2023-02-07 22:59:30 -0700 |
commit | b49f93aa951c5a168ccd32908425c670f319a65f (patch) | |
tree | 3f65565353653b2676520b3df1368a5b6d348047 | |
parent | d0f2c5d36105256ba7749da0a5abc04cbb4915f2 (diff) | |
download | ostree-b49f93aa951c5a168ccd32908425c670f319a65f.tar.gz |
bin/summary: Add options to show metadata
-rw-r--r-- | bash/ostree | 2 | ||||
-rw-r--r-- | src/ostree/ot-builtin-summary.c | 49 | ||||
-rwxr-xr-x | tests/test-summary-update.sh | 4 |
3 files changed, 50 insertions, 5 deletions
diff --git a/bash/ostree b/bash/ostree index 76a62c59..0415e225 100644 --- a/bash/ostree +++ b/bash/ostree @@ -1816,6 +1816,7 @@ _ostree_static_delta() { _ostree_summary() { local boolean_options=" $main_boolean_options + --list-metadata-keys --raw --update -u --view -v @@ -1825,6 +1826,7 @@ _ostree_summary() { --add-metadata -m --gpg-homedir --gpg-sign + --print-metadata-key --repo " diff --git a/src/ostree/ot-builtin-summary.c b/src/ostree/ot-builtin-summary.c index 2d6306a4..cdfc11e6 100644 --- a/src/ostree/ot-builtin-summary.c +++ b/src/ostree/ot-builtin-summary.c @@ -28,6 +28,8 @@ #include "ostree-sign.h" static gboolean opt_update, opt_view, opt_raw; +static gboolean opt_list_metadata_keys; +static char *opt_print_metadata_key; static char **opt_gpg_key_ids; static char *opt_gpg_homedir; static char **opt_key_ids; @@ -43,6 +45,8 @@ static GOptionEntry options[] = { { "update", 'u', 0, G_OPTION_ARG_NONE, &opt_update, "Update the summary", NULL }, { "view", 'v', 0, G_OPTION_ARG_NONE, &opt_view, "View the local summary file", NULL }, { "raw", 0, 0, G_OPTION_ARG_NONE, &opt_raw, "View the raw bytes of the summary file", NULL }, + { "list-metadata-keys", 0, 0, G_OPTION_ARG_NONE, &opt_list_metadata_keys, "List the available metadata keys", NULL }, + { "print-metadata-key", 0, 0, G_OPTION_ARG_STRING, &opt_print_metadata_key, "Print string value of metadata key", "KEY" }, { "gpg-sign", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_gpg_key_ids, "GPG Key ID to sign the summary with", "KEY-ID"}, { "gpg-homedir", 0, 0, G_OPTION_ARG_FILENAME, &opt_gpg_homedir, "GPG Homedir to use when looking for keyrings", "HOMEDIR"}, { "sign", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_key_ids, "Key ID to sign the summary with", "KEY-ID"}, @@ -85,6 +89,26 @@ build_additional_metadata (const char * const *args, return g_variant_ref_sink (g_variant_builder_end (builder)); } +static gboolean +get_summary_data (OstreeRepo *repo, + GBytes **out_summary_data, + GError **error) +{ + g_assert (out_summary_data != NULL); + + g_autoptr(GBytes) summary_data = NULL; + glnx_autofd int fd = -1; + if (!glnx_openat_rdonly (repo->repo_dir_fd, "summary", TRUE, &fd, error)) + return FALSE; + summary_data = ot_fd_readall_or_mmap (fd, 0, error); + if (!summary_data) + return FALSE; + + *out_summary_data = g_steal_pointer (&summary_data); + + return TRUE; +} + gboolean ostree_builtin_summary (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { @@ -275,15 +299,30 @@ ostree_builtin_summary (int argc, char **argv, OstreeCommandInvocation *invocati if (opt_raw) flags |= OSTREE_DUMP_RAW; - glnx_autofd int fd = -1; - if (!glnx_openat_rdonly (repo->repo_dir_fd, "summary", TRUE, &fd, error)) - return FALSE; - summary_data = ot_fd_readall_or_mmap (fd, 0, error); - if (!summary_data) + if (!get_summary_data (repo, &summary_data, error)) return FALSE; ot_dump_summary_bytes (summary_data, flags); } + else if (opt_list_metadata_keys) + { + g_autoptr(GBytes) summary_data = NULL; + + if (!get_summary_data (repo, &summary_data, error)) + return FALSE; + + ot_dump_summary_metadata_keys (summary_data); + } + else if (opt_print_metadata_key) + { + g_autoptr(GBytes) summary_data = NULL; + + if (!get_summary_data (repo, &summary_data, error)) + return FALSE; + + if (!ot_dump_summary_metadata_key (summary_data, opt_print_metadata_key, error)) + return FALSE; + } else { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, diff --git a/tests/test-summary-update.sh b/tests/test-summary-update.sh index 74c42d10..d85e9c4b 100755 --- a/tests/test-summary-update.sh +++ b/tests/test-summary-update.sh @@ -59,6 +59,10 @@ ${CMD_PREFIX} ostree --repo=repo summary --update --add-metadata=map='@a{sv} {}' # Check the additional metadata turns up in the output. ${CMD_PREFIX} ostree --repo=repo summary --view > summary assert_file_has_content summary "^map: {}$" +${CMD_PREFIX} ostree --repo=repo summary --list-metadata-keys > metadata +assert_file_has_content metadata "^map$" +${CMD_PREFIX} ostree --repo=repo summary --print-metadata-key=map > metadata +assert_file_has_content metadata "^@a{sv} {}$" echo "ok 1 update summary" |