|
|
00273d |
From 7d8f9cfcdf7725fef2c99ecb2dedcdff1e9506d7 Mon Sep 17 00:00:00 2001
|
|
|
00273d |
From: Jaroslav Rohel <jrohel@redhat.com>
|
|
|
00273d |
Date: Wed, 13 Apr 2022 12:26:10 +0200
|
|
|
00273d |
Subject: [PATCH 26/34] context: Substitute all repository config options
|
|
|
00273d |
(RhBug:2076853)
|
|
|
00273d |
|
|
|
00273d |
It also solves the problem: Substitution of variables in `baseurl`
|
|
|
00273d |
does not work in microdnf and PackageKit unless `metalink` or `mirrorlist`
|
|
|
00273d |
is set at the same time.
|
|
|
00273d |
---
|
|
|
00273d |
libdnf/dnf-repo.cpp | 34 +++++++++++++++++++++++++---------
|
|
|
00273d |
1 file changed, 25 insertions(+), 9 deletions(-)
|
|
|
00273d |
|
|
|
00273d |
diff --git a/libdnf/dnf-repo.cpp b/libdnf/dnf-repo.cpp
|
|
|
00273d |
index 710045fb..9d42e3e3 100644
|
|
|
00273d |
--- a/libdnf/dnf-repo.cpp
|
|
|
00273d |
+++ b/libdnf/dnf-repo.cpp
|
|
|
00273d |
@@ -83,6 +83,7 @@ typedef struct
|
|
|
00273d |
LrHandle *repo_handle;
|
|
|
00273d |
LrResult *repo_result;
|
|
|
00273d |
LrUrlVars *urlvars;
|
|
|
00273d |
+ bool unit_test_mode; /* ugly hack for unit tests */
|
|
|
00273d |
} DnfRepoPrivate;
|
|
|
00273d |
|
|
|
00273d |
G_DEFINE_TYPE_WITH_PRIVATE(DnfRepo, dnf_repo, G_TYPE_OBJECT)
|
|
|
00273d |
@@ -847,8 +848,11 @@ dnf_repo_conf_reset(libdnf::ConfigRepo &config)
|
|
|
00273d |
|
|
|
00273d |
/* Loads repository configuration from GKeyFile */
|
|
|
00273d |
static void
|
|
|
00273d |
-dnf_repo_conf_from_gkeyfile(libdnf::ConfigRepo &config, const char *repoId, GKeyFile *gkeyFile)
|
|
|
00273d |
+dnf_repo_conf_from_gkeyfile(DnfRepo *repo, const char *repoId, GKeyFile *gkeyFile)
|
|
|
00273d |
{
|
|
|
00273d |
+ DnfRepoPrivate *priv = GET_PRIVATE(repo);
|
|
|
00273d |
+ auto & config = *priv->repo->getConfig();
|
|
|
00273d |
+
|
|
|
00273d |
// Reset to the initial state before reloading the configuration.
|
|
|
00273d |
dnf_repo_conf_reset(config);
|
|
|
00273d |
|
|
|
00273d |
@@ -883,20 +887,31 @@ dnf_repo_conf_from_gkeyfile(libdnf::ConfigRepo &config, const char *repoId, GKey
|
|
|
00273d |
// list can be ['value1', 'value2, value3'] therefore we first join
|
|
|
00273d |
// to have 'value1, value2, value3'
|
|
|
00273d |
g_autofree gchar * tmp_strval = g_strjoinv(",", list);
|
|
|
00273d |
+
|
|
|
00273d |
+ // Substitute vars.
|
|
|
00273d |
+ g_autofree gchar *subst_value = dnf_repo_substitute(repo, tmp_strval);
|
|
|
00273d |
+
|
|
|
00273d |
+ if (strcmp(key, "baseurl") == 0 && strstr(tmp_strval, "file://$testdatadir") != NULL) {
|
|
|
00273d |
+ priv->unit_test_mode = true;
|
|
|
00273d |
+ }
|
|
|
00273d |
+
|
|
|
00273d |
try {
|
|
|
00273d |
- optionItem.newString(libdnf::Option::Priority::REPOCONFIG, tmp_strval);
|
|
|
00273d |
+ optionItem.newString(libdnf::Option::Priority::REPOCONFIG, subst_value);
|
|
|
00273d |
} catch (const std::exception & ex) {
|
|
|
00273d |
- g_debug("Invalid configuration value: %s = %s in %s; %s", key, value.c_str(), repoId, ex.what());
|
|
|
00273d |
+ g_debug("Invalid configuration value: %s = %s in %s; %s", key, subst_value, repoId, ex.what());
|
|
|
00273d |
}
|
|
|
00273d |
}
|
|
|
00273d |
|
|
|
00273d |
} else {
|
|
|
00273d |
-
|
|
|
00273d |
// process other (non list) options
|
|
|
00273d |
+
|
|
|
00273d |
+ // Substitute vars.
|
|
|
00273d |
+ g_autofree gchar *subst_value = dnf_repo_substitute(repo, value.c_str());
|
|
|
00273d |
+
|
|
|
00273d |
try {
|
|
|
00273d |
- optionItem.newString(libdnf::Option::Priority::REPOCONFIG, value);
|
|
|
00273d |
+ optionItem.newString(libdnf::Option::Priority::REPOCONFIG, subst_value);
|
|
|
00273d |
} catch (const std::exception & ex) {
|
|
|
00273d |
- g_debug("Invalid configuration value: %s = %s in %s; %s", key, value.c_str(), repoId, ex.what());
|
|
|
00273d |
+ g_debug("Invalid configuration value: %s = %s in %s; %s", key, subst_value, repoId, ex.what());
|
|
|
00273d |
}
|
|
|
00273d |
|
|
|
00273d |
}
|
|
|
00273d |
@@ -950,7 +965,7 @@ dnf_repo_set_keyfile_data(DnfRepo *repo, gboolean reloadFromGKeyFile, GError **e
|
|
|
00273d |
|
|
|
00273d |
// Reload repository configuration from keyfile.
|
|
|
00273d |
if (reloadFromGKeyFile) {
|
|
|
00273d |
- dnf_repo_conf_from_gkeyfile(*conf, repoId, priv->keyfile);
|
|
|
00273d |
+ dnf_repo_conf_from_gkeyfile(repo, repoId, priv->keyfile);
|
|
|
00273d |
dnf_repo_apply_setopts(*conf, repoId);
|
|
|
00273d |
}
|
|
|
00273d |
|
|
|
00273d |
@@ -996,8 +1011,9 @@ dnf_repo_set_keyfile_data(DnfRepo *repo, gboolean reloadFromGKeyFile, GError **e
|
|
|
00273d |
g_autofree gchar *url = NULL;
|
|
|
00273d |
url = lr_prepend_url_protocol(baseurls[0]);
|
|
|
00273d |
if (url != NULL && strncasecmp(url, "file://", 7) == 0) {
|
|
|
00273d |
- if (g_strstr_len(url, -1, "$testdatadir") == NULL)
|
|
|
00273d |
+ if (!priv->unit_test_mode) {
|
|
|
00273d |
priv->kind = DNF_REPO_KIND_LOCAL;
|
|
|
00273d |
+ }
|
|
|
00273d |
g_free(priv->location);
|
|
|
00273d |
g_free(priv->keyring);
|
|
|
00273d |
priv->location = dnf_repo_substitute(repo, url + 7);
|
|
|
00273d |
@@ -1224,7 +1240,7 @@ dnf_repo_setup(DnfRepo *repo, GError **error) try
|
|
|
00273d |
auto repoId = priv->repo->getId().c_str();
|
|
|
00273d |
|
|
|
00273d |
auto conf = priv->repo->getConfig();
|
|
|
00273d |
- dnf_repo_conf_from_gkeyfile(*conf, repoId, priv->keyfile);
|
|
|
00273d |
+ dnf_repo_conf_from_gkeyfile(repo, repoId, priv->keyfile);
|
|
|
00273d |
dnf_repo_apply_setopts(*conf, repoId);
|
|
|
00273d |
|
|
|
00273d |
auto sslverify = conf->sslverify().getValue();
|
|
|
00273d |
--
|
|
|
00273d |
2.31.1
|
|
|
00273d |
|