From d9e870be8813c17b7cdfe5ec2cd8f261e24ee246 Mon Sep 17 00:00:00 2001 From: Jonathan Lebon Date: Fri, 15 Dec 2017 14:42:10 +0000 Subject: [PATCH] libpriv/core: include pkglist for client commits The new `rpmdb.pkglist` metadata is a cheap way of retrieving the set of packages in a commit. I'd like to make use of it as much as possible vs. checking out the rpmdb and setting up a DnfSack. Of course, in the case of layered commits, it doesn't matter *as* much, because a layered commit being present in the repo should mean that a deployment is currently using it, and we should learn to reuse the rpmdb checkout of that deployment. Though keeping it consistent across both server and client commits makes implementing `OstreeDeployment`-agnostic things like `db diff` more efficient too. I also plan to use this in the upcoming auto-update code. Closes: #1158 Approved by: cgwalters --- src/app/rpmostree-compose-builtin-tree.c | 37 ++---------------------- src/libpriv/rpmostree-core.c | 9 +++++- src/libpriv/rpmostree-rpm-util.c | 31 ++++++++++++++++++++ src/libpriv/rpmostree-rpm-util.h | 6 ++++ tests/compose-tests/libbasic-test.sh | 2 +- tests/vmcheck/test-layering-basic.sh | 7 ++++- 6 files changed, 55 insertions(+), 37 deletions(-) diff --git a/src/app/rpmostree-compose-builtin-tree.c b/src/app/rpmostree-compose-builtin-tree.c index 77291cd1..89d54ad9 100644 --- a/src/app/rpmostree-compose-builtin-tree.c +++ b/src/app/rpmostree-compose-builtin-tree.c @@ -1091,37 +1091,6 @@ 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, @@ -1145,10 +1114,10 @@ impl_commit_tree (RpmOstreeTreeComposeContext *self, * 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)) + if (!rpmostree_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)); + g_variant_builder_add (metadata_builder, "{sv}", "rpmostree.rpmdb.pkglist", rpmdb_v); metadata = g_variant_ref_sink (g_variant_builder_end (metadata_builder)); /* Canonicalize to big endian, like OSTree does. Without this, any numbers diff --git a/src/libpriv/rpmostree-core.c b/src/libpriv/rpmostree-core.c index a5bdb78a..7e205916 100644 --- a/src/libpriv/rpmostree-core.c +++ b/src/libpriv/rpmostree-core.c @@ -3753,10 +3753,17 @@ rpmostree_context_commit (RpmOstreeContext *self, g_variant_builder_add (&metadata_builder, "{sv}", "rpmostree.replaced-base-packages", g_variant_builder_end (&replaced_base_pkgs)); + /* this is used by the db commands, and auto updates to diff against the base */ + g_autoptr(GVariant) rpmdb = NULL; + if (!rpmostree_create_rpmdb_pkglist_variant (self->tmprootfs_dfd, &rpmdb, + cancellable, error)) + return FALSE; + g_variant_builder_add (&metadata_builder, "{sv}", "rpmostree.rpmdb.pkglist", rpmdb); + /* be nice to our future selves */ g_variant_builder_add (&metadata_builder, "{sv}", "rpmostree.clientlayer_version", - g_variant_new_uint32 (2)); + g_variant_new_uint32 (3)); } else if (assemble_type == RPMOSTREE_ASSEMBLE_TYPE_SERVER_BASE) { diff --git a/src/libpriv/rpmostree-rpm-util.c b/src/libpriv/rpmostree-rpm-util.c index e93d688e..02482092 100644 --- a/src/libpriv/rpmostree-rpm-util.c +++ b/src/libpriv/rpmostree-rpm-util.c @@ -1128,3 +1128,34 @@ rpmostree_sack_get_by_pkgname (DnfSack *sack, *out_pkg = g_steal_pointer (&ret_pkg); return TRUE; } + +gboolean +rpmostree_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_ref_sink (g_variant_builder_end (&pkglist_v_builder)); + return TRUE; +} diff --git a/src/libpriv/rpmostree-rpm-util.h b/src/libpriv/rpmostree-rpm-util.h index 85948f0b..96b5b81f 100644 --- a/src/libpriv/rpmostree-rpm-util.h +++ b/src/libpriv/rpmostree-rpm-util.h @@ -181,3 +181,9 @@ rpmostree_sack_get_by_pkgname (DnfSack *sack, const char *pkgname, DnfPackage **out_pkg, GError **error); + +gboolean +rpmostree_create_rpmdb_pkglist_variant (int rootfs_dfd, + GVariant **out_variant, + GCancellable *cancellable, + GError **error); diff --git a/tests/compose-tests/libbasic-test.sh b/tests/compose-tests/libbasic-test.sh index e3364326..b0d6f11e 100644 --- a/tests/compose-tests/libbasic-test.sh +++ b/tests/compose-tests/libbasic-test.sh @@ -60,5 +60,5 @@ 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" +echo "ok compose pkglist" } diff --git a/tests/vmcheck/test-layering-basic.sh b/tests/vmcheck/test-layering-basic.sh index 2cc55895..53498f7e 100755 --- a/tests/vmcheck/test-layering-basic.sh +++ b/tests/vmcheck/test-layering-basic.sh @@ -78,7 +78,7 @@ vm_assert_status_jq \ '.deployments[0]["base-checksum"]' \ '.deployments[0]["pending-base-checksum"]|not' \ '.deployments[0]["base-commit-meta"]' \ - '.deployments[0]["layered-commit-meta"]["rpmostree.clientlayer_version"] == 2' + '.deployments[0]["layered-commit-meta"]["rpmostree.clientlayer_version"] > 1' vm_assert_layered_pkg foo-1.0 present echo "ok pkg foo added" @@ -190,3 +190,8 @@ for ref in rpmostree/pkg/test-pkgcache-migrate-pkg{1,2}/1.0-1.x86__64; do done vm_cmd test -L ${OLD_PKGCACHE_DIR} echo "ok migrate pkgcache" + +vm_cmd ostree show --print-metadata-key rpmostree.rpmdb.pkglist \ + $(vm_get_deployment_info 0 checksum) > pkglist.txt +assert_file_has_content pkglist.txt 'test-pkgcache-migrate-pkg' +echo "ok layered pkglist"