Skip to content

Commit

Permalink
app/compose: include rpmdb pkglist in compose
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jlebon authored and rh-atomic-bot committed Dec 8, 2017
1 parent 718596e commit 752166c
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/app/rpmostree-compose-builtin-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
5 changes: 5 additions & 0 deletions tests/compose-tests/libbasic-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

0 comments on commit 752166c

Please sign in to comment.