diff --git a/src/app/rpmostree-compose-builtin-tree.c b/src/app/rpmostree-compose-builtin-tree.c index 1582a661..d415899a 100644 --- a/src/app/rpmostree-compose-builtin-tree.c +++ b/src/app/rpmostree-compose-builtin-tree.c @@ -934,6 +934,13 @@ impl_install_tree (RpmOstreeTreeComposeContext *self, } } + /* Bind metadata from the libdnf context */ + if (!g_hash_table_contains (self->metadata, "rpmostree.rpmmd-repos")) + { + g_hash_table_insert (self->metadata, g_strdup ("rpmostree.rpmmd-repos"), + rpmostree_context_get_rpmmd_repo_commit_metadata (self->corectx)); + } + /* Destroy this now so the libdnf stack won't have any references * into the filesystem before we manipulate it. */ diff --git a/src/libpriv/rpmostree-core.c b/src/libpriv/rpmostree-core.c index 6e23e4fd..187244b2 100644 --- a/src/libpriv/rpmostree-core.c +++ b/src/libpriv/rpmostree-core.c @@ -476,6 +476,35 @@ rpmostree_context_get_hif (RpmOstreeContext *self) return self->hifctx; } +/* Add rpmmd repo information, since it's very useful for determining + * state. See also: + * + * - https://github.com/projectatomic/rpm-ostree/issues/774 + * - The repo_metadata_for_package() function in rpmostree-unpacker.c + + * This returns a value of key of type aa{sv} - the key should be + * `rpmostree.rpmmd-repos`. + */ +GVariant * +rpmostree_context_get_rpmmd_repo_commit_metadata (RpmOstreeContext *self) +{ + g_auto(GVariantBuilder) repo_list_builder; + g_variant_builder_init (&repo_list_builder, (GVariantType*)"aa{sv}"); + g_autoptr(GPtrArray) repos = get_enabled_rpmmd_repos (self->hifctx, DNF_REPO_ENABLED_PACKAGES); + for (guint i = 0; i < repos->len; i++) + { + g_auto(GVariantBuilder) repo_builder; + g_variant_builder_init (&repo_builder, (GVariantType*)"a{sv}"); + DnfRepo *repo = repos->pdata[i]; + const char *id = dnf_repo_get_id (repo); + g_variant_builder_add (&repo_builder, "{sv}", "id", g_variant_new_string (id)); + guint64 ts = dnf_repo_get_timestamp_generated (repo); + g_variant_builder_add (&repo_builder, "{sv}", "timestamp", g_variant_new_uint64 (ts)); + g_variant_builder_add (&repo_list_builder, "@a{sv}", g_variant_builder_end (&repo_builder)); + } + return g_variant_ref_sink (g_variant_builder_end (&repo_list_builder)); +} + GHashTable * rpmostree_dnfcontext_get_varsubsts (DnfContext *context) { diff --git a/src/libpriv/rpmostree-core.h b/src/libpriv/rpmostree-core.h index 9268e7f5..2a05b99f 100644 --- a/src/libpriv/rpmostree-core.h +++ b/src/libpriv/rpmostree-core.h @@ -55,6 +55,8 @@ RpmOstreeTreespec *rpmostree_treespec_new (GVariant *variant); GHashTable *rpmostree_dnfcontext_get_varsubsts (DnfContext *context); +GVariant *rpmostree_context_get_rpmmd_repo_commit_metadata (RpmOstreeContext *self); + GVariant *rpmostree_treespec_to_variant (RpmOstreeTreespec *spec); const char *rpmostree_treespec_get_ref (RpmOstreeTreespec *spec); diff --git a/tests/compose-tests/test-basic.sh b/tests/compose-tests/test-basic.sh index 05d51e89..bb2f27a3 100755 --- a/tests/compose-tests/test-basic.sh +++ b/tests/compose-tests/test-basic.sh @@ -28,6 +28,8 @@ assert_file_has_content meta.txt 'rev.*97ec21c614689e533d294cdae464df607b526ab9' assert_file_has_content meta.txt 'src.*https://gitlab.com/exampleos/custom-atomic-host' ostree --repo=${repobuild} show --print-metadata-key exampleos.tests ${treeref} > meta.txt assert_file_has_content meta.txt 'smoketested.*e2e' +ostree --repo=${repobuild} show --print-metadata-key rpmostree.rpmmd-repos ${treeref} > meta.txt +assert_file_has_content meta.txt 'id.*fedora.*timestamp' echo "ok metadata" for path in /boot /usr/lib/ostree-boot; do