app/compose: include rpmdb pkglist in compose

We don't want to have to download all of `/usr/share/rpm` just to get
the list of packages used to compose the tree. This is fundamental
information that needs to be easier to discover. So let's stick it right
in the commit metadata. There's various use cases for this information,
including easily checking for and displaying updates and a pkglist-aware
version of `ostree log`.

Closes: #1134
Approved by: cgwalters
This commit is contained in:
Jonathan Lebon 2017-12-05 19:51:26 +00:00 committed by Atomic Bot
parent 718596eace
commit 752166ce3b
2 changed files with 45 additions and 0 deletions

View File

@ -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

View File

@ -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"
}