Skip to content

Commit f829c16

Browse files
evan-goodekontura
authored andcommitted
C API: support shell-style variable substitution
Rework `dnf_repo_substitute` to call the C++ API's ConfigParser::substitute instead of librepo's lr_url_substitute. Resolves #1690
1 parent e3f6174 commit f829c16

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

libdnf/dnf-repo.cpp

+11-6
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
*/
3535

3636
#include "conf/OptionBool.hpp"
37+
#include "conf/ConfigParser.hpp"
3738

3839
#include "dnf-context.hpp"
3940
#include "hy-repo-private.hpp"
@@ -45,6 +46,7 @@
4546
#include <glib/gstdio.h>
4647
#include "hy-util.h"
4748
#include <librepo/librepo.h>
49+
#include <librepo/url_substitution.h>
4850
#include <rpm/rpmts.h>
4951
#include <librepo/yum.h>
5052

@@ -242,14 +244,17 @@ static gchar *
242244
dnf_repo_substitute(DnfRepo *repo, const gchar *url)
243245
{
244246
DnfRepoPrivate *priv = GET_PRIVATE(repo);
245-
char *tmp;
246-
gchar *substituted;
247247

248-
/* do a little dance so we can use g_free() rather than lr_free() */
249-
tmp = lr_url_substitute(url, priv->urlvars);
250-
substituted = g_strdup(tmp);
251-
lr_free(tmp);
248+
std::map<std::string, std::string> substitutions;
249+
for (LrUrlVars *elem = priv->urlvars; elem; elem = g_slist_next(elem)) {
250+
const auto * pair = static_cast<LrVar*>(elem->data);
251+
substitutions.insert({std::string{pair->var}, std::string{pair->val}});
252+
}
253+
254+
std::string tmp{url};
255+
libdnf::ConfigParser::substitute(tmp, substitutions);
252256

257+
auto * substituted = g_strdup(tmp.c_str());
253258
return substituted;
254259
}
255260

0 commit comments

Comments
 (0)