Skip to content

Commit

Permalink
dnf-repo: Don't download repository if our local cache is up to date
Browse files Browse the repository at this point in the history
Verified by comparing the hash of repomd.xml
  • Loading branch information
aleasto committed Sep 28, 2023
1 parent 0814e79 commit 6c5eca2
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions libdnf/dnf-repo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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))
Expand All @@ -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;
}
}

Expand All @@ -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;
}

/**
Expand Down Expand Up @@ -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);

Expand All @@ -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 */
Expand Down

0 comments on commit 6c5eca2

Please sign in to comment.