61 lines
1.8 KiB
Diff
61 lines
1.8 KiB
Diff
From f829c16b0677d143ea0ea40a8364b397168292dc Mon Sep 17 00:00:00 2001
|
|
From: Evan Goode <mail@evangoo.de>
|
|
Date: Fri, 7 Feb 2025 18:02:20 +0000
|
|
Subject: [PATCH 4/5] 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 https://github.com/rpm-software-management/libdnf/issues/1690
|
|
---
|
|
libdnf/dnf-repo.cpp | 17 +++++++++++------
|
|
1 file changed, 11 insertions(+), 6 deletions(-)
|
|
|
|
diff --git a/libdnf/dnf-repo.cpp b/libdnf/dnf-repo.cpp
|
|
index b5009758..7b4f83bb 100644
|
|
--- a/libdnf/dnf-repo.cpp
|
|
+++ b/libdnf/dnf-repo.cpp
|
|
@@ -34,6 +34,7 @@
|
|
*/
|
|
|
|
#include "conf/OptionBool.hpp"
|
|
+#include "conf/ConfigParser.hpp"
|
|
|
|
#include "dnf-context.hpp"
|
|
#include "hy-repo-private.hpp"
|
|
@@ -45,6 +46,7 @@
|
|
#include <glib/gstdio.h>
|
|
#include "hy-util.h"
|
|
#include <librepo/librepo.h>
|
|
+#include <librepo/url_substitution.h>
|
|
#include <rpm/rpmts.h>
|
|
#include <librepo/yum.h>
|
|
|
|
@@ -242,14 +244,17 @@ static gchar *
|
|
dnf_repo_substitute(DnfRepo *repo, const gchar *url)
|
|
{
|
|
DnfRepoPrivate *priv = GET_PRIVATE(repo);
|
|
- char *tmp;
|
|
- gchar *substituted;
|
|
|
|
- /* do a little dance so we can use g_free() rather than lr_free() */
|
|
- tmp = lr_url_substitute(url, priv->urlvars);
|
|
- substituted = g_strdup(tmp);
|
|
- lr_free(tmp);
|
|
+ std::map<std::string, std::string> substitutions;
|
|
+ for (LrUrlVars *elem = priv->urlvars; elem; elem = g_slist_next(elem)) {
|
|
+ const auto * pair = static_cast<LrVar*>(elem->data);
|
|
+ substitutions.insert({std::string{pair->var}, std::string{pair->val}});
|
|
+ }
|
|
+
|
|
+ std::string tmp{url};
|
|
+ libdnf::ConfigParser::substitute(tmp, substitutions);
|
|
|
|
+ auto * substituted = g_strdup(tmp.c_str());
|
|
return substituted;
|
|
}
|
|
|
|
--
|
|
2.48.1
|
|
|