Skip to content

Commit

Permalink
repo_sack: Clone root metadata when user has not valid cache
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-kolarik authored and kontura committed Dec 7, 2023
1 parent 2c1c2f3 commit d314c5b
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions libdnf5/repo/repo_sack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.
#include "rpm/package_sack_impl.hpp"
#include "solv/solver.hpp"
#include "solv_repo.hpp"
#include "utils/auth.hpp"
#include "utils/fs/utils.hpp"
#include "utils/string.hpp"
#include "utils/url.hpp"
Expand Down Expand Up @@ -377,9 +378,15 @@ void RepoSack::update_and_load_repos(libdnf5::repo::RepoQuery & repos, bool impo
repos_for_processing = std::move(repos_with_bad_signature);
}

std::string prev_repo_id;
bool root_cache_tried = false;
// Prepares repositories that are not expired or have ONLY_CACHE or LAZY SynStrategy.
for (std::size_t idx = 0; idx < repos_for_processing.size();) {
auto * const repo = repos_for_processing[idx];
if (prev_repo_id != repo->get_id()) {
prev_repo_id = repo->get_id();
root_cache_tried = false;
}
catch_thread_sack_loader_exceptions();
try {
bool valid_metadata{false};
Expand All @@ -399,6 +406,12 @@ void RepoSack::update_and_load_repos(libdnf5::repo::RepoQuery & repos, bool impo
logger->debug("Using cache for repo \"{}\"", repo->config.get_id());
send_to_sack_loader(repo);
} else {
// Try reusing the root cache
if (!root_cache_tried && !libdnf5::utils::am_i_root() && repo->clone_root_metadata()) {
root_cache_tried = true;
continue;
}

if (repo->get_sync_strategy() == Repo::SyncStrategy::ONLY_CACHE) {
throw RepoDownloadError(
M_("Cache-only enabled but no cache for repository \"{}\""), repo->config.get_id());
Expand Down

0 comments on commit d314c5b

Please sign in to comment.