diff --git a/src/app/rpmostree-compose-builtin-tree.c b/src/app/rpmostree-compose-builtin-tree.c index 823a59da98..28b693aa93 100644 --- a/src/app/rpmostree-compose-builtin-tree.c +++ b/src/app/rpmostree-compose-builtin-tree.c @@ -1090,6 +1090,37 @@ impl_install_tree (RpmOstreeTreeComposeContext *self, return TRUE; } +static gboolean +create_rpmdb_pkglist_variant (int rootfs_dfd, + GVariant **out_variant, + GCancellable *cancellable, + GError **error) +{ + g_autoptr(GPtrArray) pkglist = NULL; + g_autoptr(RpmOstreeRefSack) refsack = NULL; + if (!rpmostree_get_pkglist_for_root (rootfs_dfd, ".", &refsack, + &pkglist, cancellable, error)) + return FALSE; + + GVariantBuilder pkglist_v_builder; + g_variant_builder_init (&pkglist_v_builder, (GVariantType*)"a(stsss)"); + + const guint n = pkglist->len; + for (guint i = 0; i < n; i++) + { + DnfPackage *pkg = pkglist->pdata[i]; + g_variant_builder_add (&pkglist_v_builder, "(stsss)", + dnf_package_get_name (pkg), + dnf_package_get_epoch (pkg), + dnf_package_get_version (pkg), + dnf_package_get_release (pkg), + dnf_package_get_arch (pkg)); + } + + *out_variant = g_variant_builder_end (&pkglist_v_builder); + return TRUE; +} + static gboolean impl_commit_tree (RpmOstreeTreeComposeContext *self, GCancellable *cancellable, @@ -1109,6 +1140,15 @@ impl_commit_tree (RpmOstreeTreeComposeContext *self, GLNX_HASH_TABLE_FOREACH_KV (self->metadata, const char*, strkey, GVariant*, v) g_variant_builder_add (metadata_builder, "{sv}", strkey, v); + /* include list of packages in rpmdb; this is used client-side for easily previewing + * pending updates. once we only support unified core composes, this can easily be much + * more readily injected during assembly */ + g_autoptr(GVariant) rpmdb_v = NULL; + if (!create_rpmdb_pkglist_variant (self->rootfs_dfd, &rpmdb_v, cancellable, error)) + return FALSE; + g_variant_builder_add (metadata_builder, "{sv}", "rpmostree.rpmdb.pkglist", + g_steal_pointer (&rpmdb_v)); + metadata = g_variant_ref_sink (g_variant_builder_end (metadata_builder)); /* Canonicalize to big endian, like OSTree does. Without this, any numbers * we place in the metadata will be unreadable since clients won't know diff --git a/tests/compose-tests/libbasic-test.sh b/tests/compose-tests/libbasic-test.sh index 61d3250361..aae606dfda 100644 --- a/tests/compose-tests/libbasic-test.sh +++ b/tests/compose-tests/libbasic-test.sh @@ -39,4 +39,9 @@ assert_not_file_has_content ls.txt '__db' 'lock' ostree --repo=${repobuild} ls -R ${treeref} /usr/etc/selinux > ls.txt assert_not_file_has_content ls.txt 'LOCK' echo "ok no leftover files" + +ostree --repo=${repobuild} show ${treeref} \ + --print-metadata-key rpmostree.rpmdb.pkglist > pkglist.txt +assert_file_has_content pkglist.txt 'systemd' +echo "ok pkglist" }