Fix cache_age handling for compose and client-side

PR: https://github.com/projectatomic/rpm-ostree/pull/1562
AKA commit: a7bbf5bc14
introduced two regressions.  First one for `compose tree`.  The intention is
the default there is to *always* immediately check for updated
rpm-md - a bit like `yum clean expire-cache`.  However due
to bugs in the stack we end up downloading it again anyways, but
that's not the topic here.

When we made that change we basically stopped using `DnfContext`'s
`cache_age`, which is what `compose tree` was setting.

Introduce a new explicit API to do what we want for `compose tree`.

Secondly, we were mistakenly always caching on the client
side.

This also fixes an issue that `--cache-only` didn't work, it basically
just made `compose tree` use the default `metadata_expire`.  Now we
really don't expire it.

Closes: #1587
Approved by: jlebon
This commit is contained in:
Colin Walters 2018-09-26 19:16:53 -04:00 committed by Atomic Bot
parent 096f8dec65
commit aa485b7625
4 changed files with 44 additions and 7 deletions

View File

@ -269,13 +269,13 @@ install_packages_in_root (RpmOstreeTreeComposeContext *self,
if (opt_cachedir && !opt_unified_core)
dnf_context_set_keep_cache (dnfctx, TRUE);
/* For compose, always try to refresh metadata; we're used in build servers
* where fetching should be cheap. Otherwise, if --cache-only is set, it's
* likely an offline developer laptop case, so never refresh.
* where fetching should be cheap. We also have --cache-only which is
* used by coreos-assembler. Today we don't expose the default, but we
* could add --cache-default or something if someone wanted it.
*/
if (!opt_cache_only)
dnf_context_set_cache_age (dnfctx, 0);
else
dnf_context_set_cache_age (dnfctx, G_MAXUINT);
rpmostree_context_set_dnf_caching (self->corectx,
opt_cache_only ? RPMOSTREE_CONTEXT_DNF_CACHE_FOREVER :
RPMOSTREE_CONTEXT_DNF_CACHE_NEVER);
/* Without specifying --cachedir we'd just toss the data we download, so let's
* catch that.
*/

View File

@ -39,6 +39,7 @@ struct _RpmOstreeContext {
gboolean pkgcache_only;
DnfContext *dnfctx;
RpmOstreeContextDnfCachePolicy dnf_cache_policy;
OstreeRepo *ostreerepo;
OstreeRepo *pkgcache_repo;
OstreeRepoDevInoCache *devino_cache;

View File

@ -380,6 +380,7 @@ static void
rpmostree_context_init (RpmOstreeContext *self)
{
self->tmprootfs_dfd = -1;
self->dnf_cache_policy = RPMOSTREE_CONTEXT_DNF_CACHE_DEFAULT;
}
static void
@ -489,6 +490,13 @@ rpmostree_context_set_pkgcache_only (RpmOstreeContext *self,
self->pkgcache_only = pkgcache_only;
}
void
rpmostree_context_set_dnf_caching (RpmOstreeContext *self,
RpmOstreeContextDnfCachePolicy policy)
{
self->dnf_cache_policy = policy;
}
/* Pick up repos dir and passwd from @cfg_deployment. */
void
rpmostree_context_configure_from_deployment (RpmOstreeContext *self,
@ -1029,9 +1037,28 @@ rpmostree_context_download_metadata (RpmOstreeContext *self,
if (g_cancellable_set_error_if_cancelled (cancellable, error))
return FALSE;
/* For the cache_age bits, see https://github.com/projectatomic/rpm-ostree/pull/1562
* AKA a7bbf5bc142d9dac5b1bfb86d0466944d38baa24
* We have our own cache age as we want to default to G_MAXUINT so we
* respect the repo's metadata_expire if set. But the compose tree path
* also sets this to 0 to force expiry.
*/
guint cache_age = G_MAXUINT-1;
switch (self->dnf_cache_policy)
{
case RPMOSTREE_CONTEXT_DNF_CACHE_FOREVER:
cache_age = G_MAXUINT;
break;
case RPMOSTREE_CONTEXT_DNF_CACHE_DEFAULT:
/* Handled above */
break;
case RPMOSTREE_CONTEXT_DNF_CACHE_NEVER:
cache_age = 0;
break;
}
gboolean did_update = FALSE;
if (!dnf_repo_check(repo,
G_MAXUINT,
cache_age,
hifstate,
NULL))
{

View File

@ -80,6 +80,15 @@ RpmOstreeContext *rpmostree_context_new_tree (int basedir_dfd,
void rpmostree_context_set_pkgcache_only (RpmOstreeContext *self,
gboolean pkgcache_only);
typedef enum {
RPMOSTREE_CONTEXT_DNF_CACHE_FOREVER,
RPMOSTREE_CONTEXT_DNF_CACHE_DEFAULT,
RPMOSTREE_CONTEXT_DNF_CACHE_NEVER,
} RpmOstreeContextDnfCachePolicy;
void rpmostree_context_set_dnf_caching (RpmOstreeContext *self,
RpmOstreeContextDnfCachePolicy policy);
DnfContext * rpmostree_context_get_dnf (RpmOstreeContext *self);
RpmOstreeTreespec *rpmostree_treespec_new_from_keyfile (GKeyFile *keyfile, GError **error);