From 6c5eca2313bd1283466d7010b526068a15bef930 Mon Sep 17 00:00:00 2001 From: Alessandro Astone Date: Thu, 28 Sep 2023 14:50:22 +0200 Subject: [PATCH] dnf-repo: Don't download repository if our local cache is up to date Verified by comparing the hash of repomd.xml --- libdnf/dnf-repo.cpp | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/libdnf/dnf-repo.cpp b/libdnf/dnf-repo.cpp index 48434fd9be..16f1b29ee9 100644 --- a/libdnf/dnf-repo.cpp +++ b/libdnf/dnf-repo.cpp @@ -969,6 +969,9 @@ dnf_repo_set_keyfile_data(DnfRepo *repo, gboolean reloadFromGKeyFile, GError **e dnf_repo_apply_setopts(*conf, repoId); } + if (dnf_context_get_cache_dir(priv->context)) + conf->basecachedir().set(libdnf::Option::Priority::REPOCONFIG, dnf_context_get_cache_dir(priv->context)); + /* baseurl is optional; if missing, unset it */ g_auto(GStrv) baseurls = NULL; auto & repoBaseurls = conf->baseurl().getValue(); @@ -1476,6 +1479,8 @@ dnf_repo_check_internal(DnfRepo *repo, return FALSE; } + gboolean too_old = FALSE; + /* check metadata age for non-local repos */ if (priv->kind != DNF_REPO_KIND_LOCAL && permissible_cache_age != G_MAXUINT) { if (!dnf_repo_set_timestamp_modified(repo, error)) @@ -1492,7 +1497,7 @@ dnf_repo_check_internal(DnfRepo *repo, DNF_ERROR_INTERNAL_ERROR, "cache too old: %" G_GINT64_FORMAT" > %i", age_of_data, valid_time_allowed); - return FALSE; + too_old = TRUE; } } @@ -1514,10 +1519,10 @@ dnf_repo_check_internal(DnfRepo *repo, } } /* ensure we reset the values from the keyfile */ - if (!dnf_repo_set_keyfile_data(repo, TRUE, error)) + if (!too_old && !dnf_repo_set_keyfile_data(repo, TRUE, error)) return FALSE; - return TRUE; + return !too_old; } /** @@ -1765,6 +1770,8 @@ dnf_repo_update(DnfRepo *repo, if (!dnf_repo_set_keyfile_data(repo, TRUE, error)) return FALSE; + auto repoImpl = libdnf::repoGetImpl(priv->repo); + /* countme support */ libdnf::repoGetImpl(priv->repo)->addCountmeFlag(priv->repo_handle); @@ -1776,6 +1783,15 @@ dnf_repo_update(DnfRepo *repo, if (!ret) goto out; + try { + if (repoImpl->isInSync()) { + /* reset timestamp */ + utimes(repoImpl->repomdFn.c_str(), NULL); + dnf_state_release_locks(state); + return TRUE; + } + } catch (std::exception & ex) {} + /* set state */ ret = dnf_state_set_steps(state, error, 95, /* download */