Blame SOURCES/0001-Do-a-substitution-of-variables-in-repo_id-RhBug1748841.patch

210fc6
From 8bcd196fd95e70fd1f0be16d2c274e39a1cabe2e Mon Sep 17 00:00:00 2001
210fc6
From: Jaroslav Rohel <jrohel@redhat.com>
210fc6
Date: Thu, 21 Nov 2019 11:45:03 +0100
210fc6
Subject: [PATCH] Do a substitution of variables in repo_id (RhBug:1748841)
210fc6
210fc6
Example of repo file:
210fc6
[test-$basearch-$releasever]
210fc6
Name=Test-$basearch-$releasever
210fc6
baseurl=file:///mnt/
210fc6
gpgcheck=0
210fc6
enabled=1
210fc6
210fc6
https://bugzilla.redhat.com/show_bug.cgi?id=1748841
210fc6
---
210fc6
 dnf/conf/read.py | 40 +++++++++++++++++++++++++++-------------
210fc6
 1 file changed, 27 insertions(+), 13 deletions(-)
210fc6
210fc6
diff --git a/dnf/conf/read.py b/dnf/conf/read.py
210fc6
index a526a71..1efac22 100644
210fc6
--- a/dnf/conf/read.py
210fc6
+++ b/dnf/conf/read.py
210fc6
@@ -43,7 +43,7 @@ class RepoReader(object):
210fc6
 
210fc6
         # read .repo files from directories specified by conf.reposdir
210fc6
         for repofn in (repofn for reposdir in self.conf.reposdir
210fc6
-                       for repofn in sorted(glob.glob('%s/*.repo' % reposdir))):
210fc6
+                       for repofn in sorted(glob.glob('{}/*.repo'.format(reposdir)))):
210fc6
             try:
210fc6
                 for r in self._get_repos(repofn):
210fc6
                     yield r
210fc6
@@ -54,17 +54,38 @@ class RepoReader(object):
210fc6
     def _build_repo(self, parser, id_, repofn):
210fc6
         """Build a repository using the parsed data."""
210fc6
 
210fc6
-        repo = dnf.repo.Repo(id_, self.conf)
210fc6
+        substituted_id = libdnf.conf.ConfigParser.substitute(id_, self.conf.substitutions)
210fc6
+
210fc6
+        # Check the repo.id against the valid chars
210fc6
+        invalid = dnf.repo.repo_id_invalid(substituted_id)
210fc6
+        if invalid is not None:
210fc6
+            if substituted_id != id_:
210fc6
+                msg = _("Bad id for repo: {} ({}), byte = {} {}").format(substituted_id, id_,
210fc6
+                                                                         substituted_id[invalid],
210fc6
+                                                                         invalid)
210fc6
+            else:
210fc6
+                msg = _("Bad id for repo: {}, byte = {} {}").format(id_, id_[invalid], invalid)
210fc6
+            raise dnf.exceptions.ConfigError(msg)
210fc6
+
210fc6
+        repo = dnf.repo.Repo(substituted_id, self.conf)
210fc6
         try:
210fc6
             repo._populate(parser, id_, repofn, dnf.conf.PRIO_REPOCONFIG)
210fc6
         except ValueError as e:
210fc6
-            msg = _("Repository '%s': Error parsing config: %s") % (id_, e)
210fc6
+            if substituted_id != id_:
210fc6
+                msg = _("Repository '{}' ({}): Error parsing config: {}").format(substituted_id,
210fc6
+                                                                                 id_, e)
210fc6
+            else:
210fc6
+                msg = _("Repository '{}': Error parsing config: {}").format(id_, e)
210fc6
             raise dnf.exceptions.ConfigError(msg)
210fc6
 
210fc6
         # Ensure that the repo name is set
210fc6
         if repo._get_priority('name') == dnf.conf.PRIO_DEFAULT:
210fc6
-            msg = _("Repository '%s' is missing name in configuration, using id.")
210fc6
-            logger.warning(msg, id_)
210fc6
+            if substituted_id != id_:
210fc6
+                msg = _("Repository '{}' ({}) is missing name in configuration, using id.").format(
210fc6
+                    substituted_id, id_)
210fc6
+            else:
210fc6
+                msg = _("Repository '{}' is missing name in configuration, using id.").format(id_)
210fc6
+            logger.warning(msg)
210fc6
         repo.name = ucd(repo.name)
210fc6
         repo._substitutions.update(self.conf.substitutions)
210fc6
         repo.cfg = parser
210fc6
@@ -80,23 +101,16 @@ class RepoReader(object):
210fc6
         try:
210fc6
             parser.read(repofn)
210fc6
         except RuntimeError as e:
210fc6
-            raise dnf.exceptions.ConfigError(_('Parsing file "%s" failed: %s') % (repofn, e))
210fc6
+            raise dnf.exceptions.ConfigError(_('Parsing file "{}" failed: {}').format(repofn, e))
210fc6
         except IOError as e:
210fc6
             logger.warning(e)
210fc6
 
210fc6
         # Check sections in the .repo file that was just slurped up
210fc6
         for section in parser.getData():
210fc6
 
210fc6
             if section == 'main':
210fc6
                 continue
210fc6
 
210fc6
-            # Check the repo.id against the valid chars
210fc6
-            invalid = dnf.repo.repo_id_invalid(section)
210fc6
-            if invalid is not None:
210fc6
-                logger.warning(_("Bad id for repo: %s, byte = %s %d"), section,
210fc6
-                               section[invalid], invalid)
210fc6
-                continue
210fc6
-
210fc6
             try:
210fc6
                 thisrepo = self._build_repo(parser, ucd(section), repofn)
210fc6
             except (dnf.exceptions.RepoError, dnf.exceptions.ConfigError) as e:
210fc6
--
210fc6
libgit2 0.28.2
210fc6