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 dbb73f5
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 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 @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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);
Expand Down Expand Up @@ -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)
Expand All @@ -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);
Expand Down

0 comments on commit dbb73f5

Please sign in to comment.