summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Nicholson <dbn@endlessos.org>2023-01-29 22:41:52 -0700
committerDan Nicholson <dbn@endlessos.org>2023-02-07 22:59:30 -0700
commitd0f2c5d36105256ba7749da0a5abc04cbb4915f2 (patch)
tree8ab185bb0053d7376c93346127f374c629838aff
parent86701f0f848dde51352d760872d4e0d821a9fc21 (diff)
downloadostree-d0f2c5d36105256ba7749da0a5abc04cbb4915f2.tar.gz
ostree/dump: Add support for summary metadata keys
Like with commit metadata, it's useful to list and print metadata keys are in a summary file. This adds helpers to do that.
-rw-r--r--src/ostree/ot-dump.c60
-rw-r--r--src/ostree/ot-dump.h6
2 files changed, 66 insertions, 0 deletions
diff --git a/src/ostree/ot-dump.c b/src/ostree/ot-dump.c
index 509eb792..4cfac811 100644
--- a/src/ostree/ot-dump.c
+++ b/src/ostree/ot-dump.c
@@ -407,6 +407,66 @@ ot_dump_summary_bytes (GBytes *summary_bytes,
}
}
+static gint
+strptr_cmp (gconstpointer a,
+ gconstpointer b)
+{
+ const char *a_str = *((const char **) a);
+ const char *b_str = *((const char **) b);
+
+ return g_strcmp0 (a_str, b_str);
+}
+
+void
+ot_dump_summary_metadata_keys (GBytes *summary_bytes)
+{
+ g_autoptr(GVariant) summary = NULL;
+ g_autoptr(GVariant) metadata = NULL;
+
+ summary = g_variant_new_from_bytes (OSTREE_SUMMARY_GVARIANT_FORMAT,
+ summary_bytes, FALSE);
+ metadata = g_variant_get_child_value (summary, 1);
+
+ GVariantIter iter;
+ const char *key = NULL;
+ g_autoptr(GPtrArray) keys = g_ptr_array_new ();
+ g_variant_iter_init (&iter, metadata);
+ while (g_variant_iter_loop (&iter, "{&s@v}", &key, NULL))
+ g_ptr_array_add (keys, (gpointer) key);
+
+ g_ptr_array_sort (keys, strptr_cmp);
+ for (guint i = 0; i < keys-> len; i++)
+ {
+ key = keys->pdata[i];
+ g_print ("%s\n", key);
+ }
+}
+
+gboolean
+ot_dump_summary_metadata_key (GBytes *summary_bytes,
+ const char *key,
+ GError **error)
+{
+ g_autoptr(GVariant) summary = NULL;
+ g_autoptr(GVariant) metadata = NULL;
+ g_autoptr(GVariant) value = NULL;
+
+ summary = g_variant_new_from_bytes (OSTREE_SUMMARY_GVARIANT_FORMAT,
+ summary_bytes, FALSE);
+ metadata = g_variant_get_child_value (summary, 1);
+ value = g_variant_lookup_value (metadata, key, NULL);
+ if (!value)
+ {
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
+ "No such metadata key '%s'", key);
+ return FALSE;
+ }
+
+ ot_dump_variant (value);
+
+ return TRUE;
+}
+
static gboolean
dump_gpg_subkey (GVariant *subkey,
gboolean primary,
diff --git a/src/ostree/ot-dump.h b/src/ostree/ot-dump.h
index 217a3964..da1a2cb2 100644
--- a/src/ostree/ot-dump.h
+++ b/src/ostree/ot-dump.h
@@ -41,5 +41,11 @@ void ot_dump_object (OstreeObjectType objtype,
void ot_dump_summary_bytes (GBytes *summary_bytes,
OstreeDumpFlags flags);
+void ot_dump_summary_metadata_keys (GBytes *summary_bytes);
+
+gboolean ot_dump_summary_metadata_key (GBytes *summary_bytes,
+ const char *key,
+ GError **error);
+
gboolean ot_dump_gpg_key (GVariant *key,
GError **error);