From dbb73f5fa12b5578e8dcb097358651d4d9fdcee3 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 | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/libdnf/dnf-repo.cpp b/libdnf/dnf-repo.cpp index 48434fd9be..4570c0a955 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(); @@ -1463,6 +1466,7 @@ dnf_repo_check_internal(DnfRepo *repo, error_local->message); return FALSE; } + repoImpl->repomdFn = yum_repo->repomd; /* get timestamp */ ret = lr_result_getinfo(priv->repo_result, &error_local, @@ -1765,8 +1769,10 @@ 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); + repoImpl->addCountmeFlag(priv->repo_handle); /* take lock */ ret = dnf_state_take_lock(state, @@ -1784,6 +1790,24 @@ dnf_repo_update(DnfRepo *repo, if (!ret) goto out; + state_local = dnf_state_get_child(state); + dnf_state_action_start(state_local, + DNF_STATE_ACTION_DOWNLOAD_METADATA, NULL); + + try { + if (repoImpl->isInSync()) { + /* reset timestamp */ + utimes(repoImpl->repomdFn.c_str(), NULL); + ret = dnf_state_done(state, error); + if (!ret) + goto out; + + /* skip check */ + ret = dnf_state_finished(state, error); + goto out; + } + } catch (std::exception & ex) {} + /* remove the temporary space if it already exists */ if (g_file_test(priv->location_tmp, G_FILE_TEST_EXISTS)) { ret = dnf_remove_recursive(priv->location_tmp, error); @@ -1842,7 +1866,7 @@ dnf_repo_update(DnfRepo *repo, goto out; /* Callback to display progress of downloading */ - state_local = updatedata.state = dnf_state_get_child(state); + updatedata.state = state_local; ret = lr_handle_setopt(priv->repo_handle, error, LRO_PROGRESSDATA, &updatedata); if (!ret) @@ -1867,8 +1891,6 @@ dnf_repo_update(DnfRepo *repo, } lr_result_clear(priv->repo_result); - dnf_state_action_start(state_local, - DNF_STATE_ACTION_DOWNLOAD_METADATA, NULL); ret = lr_handle_perform(priv->repo_handle, priv->repo_result, &error_local);