dcavalca / rpms / dnf

Forked from rpms/dnf 2 years ago
Clone

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

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