From 33ea6fbc96714abca301ff13aed2897975ee43a2 Mon Sep 17 00:00:00 2001 From: Jonathan Lebon Date: Fri, 4 May 2018 08:56:40 -0400 Subject: [PATCH] daemon/upgrader: Reuse sack from core for advisories In #1344, we changed `upgrade` to always write the cached update. One thing I hadn't noticed was that with pkglayering, loading the sack twice meant we printed all that gory repo info twice. Really, the much nicer thing to do is just to make an effort to try to *keep* the original sack that the core used so that we skip all that overhead completely. Closes: #1357 Approved by: cgwalters --- src/daemon/rpmostree-sysroot-upgrader.c | 18 ++++++++++++++++-- src/daemon/rpmostree-sysroot-upgrader.h | 4 ++++ src/daemon/rpmostreed-deployment-utils.c | 2 +- src/daemon/rpmostreed-transaction-types.c | 12 ++---------- 4 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/daemon/rpmostree-sysroot-upgrader.c b/src/daemon/rpmostree-sysroot-upgrader.c index ca4cdbd6..422df17d 100644 --- a/src/daemon/rpmostree-sysroot-upgrader.c +++ b/src/daemon/rpmostree-sysroot-upgrader.c @@ -67,9 +67,10 @@ struct RpmOstreeSysrootUpgrader { /* Used during tree construction */ OstreeRepoDevInoCache *devino_cache; int tmprootfs_dfd; - RpmOstreeRefSack *rsack; + RpmOstreeRefSack *rsack; /* sack of base layer */ GLnxTmpDir metatmpdir; RpmOstreeContext *ctx; + DnfSack *rpmmd_sack; /* sack from core */ GPtrArray *overlay_packages; /* Finalized list of pkgs to overlay */ GPtrArray *override_remove_packages; /* Finalized list of base pkgs to remove */ @@ -200,7 +201,8 @@ rpmostree_sysroot_upgrader_finalize (GObject *object) RpmOstreeSysrootUpgrader *self = RPMOSTREE_SYSROOT_UPGRADER (object); g_clear_pointer (&self->rsack, rpmostree_refsack_unref); - g_clear_object (&self->ctx); + g_clear_object (&self->rpmmd_sack); + g_clear_object (&self->ctx); /* Note this is already cleared in the happy path */ glnx_close_fd (&self->tmprootfs_dfd); (void)glnx_tmpdir_delete (&self->metatmpdir, NULL, NULL); @@ -363,6 +365,14 @@ rpmostree_sysroot_upgrader_get_merge_deployment (RpmOstreeSysrootUpgrader *self) return self->origin_merge_deployment; } +/* Returns DnfSack used, if any. */ +DnfSack* +rpmostree_sysroot_upgrader_get_sack (RpmOstreeSysrootUpgrader *self, + GError **error) +{ + return self->rpmmd_sack; +} + /* * Like ostree_sysroot_upgrader_pull(), but also handles the `baserefspec` we * use when doing layered packages. @@ -891,6 +901,10 @@ prep_local_assembly (RpmOstreeSysrootUpgrader *self, if (!rpmostree_context_prepare (self->ctx, cancellable, error)) return FALSE; self->layering_type = RPMOSTREE_SYSROOT_UPGRADER_LAYERING_RPMMD_REPOS; + + /* keep a ref on it in case the level higher up needs it */ + self->rpmmd_sack = + g_object_ref (dnf_context_get_sack (rpmostree_context_get_dnf (self->ctx))); } else { diff --git a/src/daemon/rpmostree-sysroot-upgrader.h b/src/daemon/rpmostree-sysroot-upgrader.h index b2011e4e..0d71ed16 100644 --- a/src/daemon/rpmostree-sysroot-upgrader.h +++ b/src/daemon/rpmostree-sysroot-upgrader.h @@ -87,6 +87,10 @@ rpmostree_sysroot_upgrader_set_origin (RpmOstreeSysrootUpgrader *self, const char * rpmostree_sysroot_upgrader_get_base (RpmOstreeSysrootUpgrader *self); +DnfSack* +rpmostree_sysroot_upgrader_get_sack (RpmOstreeSysrootUpgrader *self, + GError **error); + gboolean rpmostree_sysroot_upgrader_pull_base (RpmOstreeSysrootUpgrader *self, const char *dir_to_pull, diff --git a/src/daemon/rpmostreed-deployment-utils.c b/src/daemon/rpmostreed-deployment-utils.c index 4c32cf92..6ae1b123 100644 --- a/src/daemon/rpmostreed-deployment-utils.c +++ b/src/daemon/rpmostreed-deployment-utils.c @@ -943,7 +943,7 @@ gboolean rpmostreed_update_generate_variant (OstreeDeployment *booted_deployment, OstreeDeployment *staged_deployment, OstreeRepo *repo, - DnfSack *sack, + DnfSack *sack, /* allow-none */ GVariant **out_update, GCancellable *cancellable, GError **error) diff --git a/src/daemon/rpmostreed-transaction-types.c b/src/daemon/rpmostreed-transaction-types.c index c181dab1..9b5b8d06 100644 --- a/src/daemon/rpmostreed-transaction-types.c +++ b/src/daemon/rpmostreed-transaction-types.c @@ -198,7 +198,7 @@ static gboolean generate_update_variant (OstreeRepo *repo, OstreeDeployment *booted_deployment, OstreeDeployment *staged_deployment, - DnfSack *sack, + DnfSack *sack, /* allow-none */ GCancellable *cancellable, GError **error) { @@ -1189,15 +1189,7 @@ deploy_transaction_execute (RpmostreedTransaction *transaction, OstreeDeployment *booted_deployment = ostree_sysroot_get_booted_deployment (sysroot); - g_autoptr(DnfSack) sack = NULL; - if (g_hash_table_size (rpmostree_origin_get_packages (origin)) > 0) - { - /* don't force a refresh; we want the same sack state used by the core */ - if (!get_sack_for_booted (sysroot, repo, booted_deployment, FALSE, &sack, - cancellable, error)) - return FALSE; - } - + DnfSack *sack = rpmostree_sysroot_upgrader_get_sack (upgrader, error); if (!generate_update_variant (repo, booted_deployment, new_deployment, sack, cancellable, error)) return FALSE;