Blame SOURCES/0001-Handle-empty-comps-group-name-RhBug1826198.patch

b57a3b
From 3c758a4ea670fab1f4b55fa878ebf2b2ff4b678b Mon Sep 17 00:00:00 2001
b57a3b
From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Hr=C3=A1zk=C3=BD?= <lhrazky@redhat.com>
b57a3b
Date: Tue, 28 Apr 2020 09:08:05 +0200
b57a3b
Subject: [PATCH] Handle empty comps group name (RhBug:1826198)
b57a3b
b57a3b
Don't crash on empty comps group/environment name. In outputs, use the
b57a3b
"<name-unset>" placeholder instead of the name.
b57a3b
b57a3b
https://bugzilla.redhat.com/show_bug.cgi?id=1826198
b57a3b
---
b57a3b
 dnf/cli/commands/group.py  |  4 ++--
b57a3b
 dnf/cli/output.py          | 16 ++++++++++------
b57a3b
 dnf/comps.py               | 11 ++++++++++-
b57a3b
 dnf/db/group.py            | 12 ++++++++----
b57a3b
 tests/repos/main_comps.xml |  7 +++++++
b57a3b
 tests/support.py           |  2 +-
b57a3b
 tests/test_comps.py        |  6 +++---
b57a3b
 tests/test_groups.py       |  9 +++++++++
b57a3b
 8 files changed, 50 insertions(+), 17 deletions(-)
b57a3b
b57a3b
diff --git a/dnf/cli/commands/group.py b/dnf/cli/commands/group.py
b57a3b
index f535a50980..4ffd3b89c8 100644
b57a3b
--- a/dnf/cli/commands/group.py
b57a3b
+++ b/dnf/cli/commands/group.py
b57a3b
@@ -177,7 +177,7 @@ def _list(self, userlist):
b57a3b
         def _out_grp(sect, group):
b57a3b
             if not done:
b57a3b
                 print(sect)
b57a3b
-            msg = '   %s' % group.ui_name
b57a3b
+            msg = '   %s' % (group.ui_name if group.ui_name is not None else _("<name-unset>"))
b57a3b
             if print_ids:
b57a3b
                 msg += ' (%s)' % group.id
b57a3b
             if group.lang_only:
b57a3b
@@ -188,7 +188,7 @@ def _out_env(sect, envs):
b57a3b
             if envs:
b57a3b
                 print(sect)
b57a3b
             for e in envs:
b57a3b
-                msg = '   %s' % e.ui_name
b57a3b
+                msg = '   %s' % (e.ui_name if e.ui_name is not None else _("<name-unset>"))
b57a3b
                 if print_ids:
b57a3b
                     msg += ' (%s)' % e.id
b57a3b
                 print(msg)
b57a3b
diff --git a/dnf/cli/output.py b/dnf/cli/output.py
b57a3b
index 67eab80b19..2585a5c773 100644
b57a3b
--- a/dnf/cli/output.py
b57a3b
+++ b/dnf/cli/output.py
b57a3b
@@ -1221,47 +1221,51 @@ def _add_line(lines, data, a_wid, po, obsoletes=[]):
b57a3b
                 lines.append((name, "", "", "", "", "", ""))
b57a3b
             pkglist_lines.append((action, lines))
b57a3b
         if self.base._history:
b57a3b
+            def format_line(group):
b57a3b
+                name = group.getName()
b57a3b
+                return (name if name else _("<name-unset>"), "", "", "", "", "", "")
b57a3b
+
b57a3b
             install_env_group = self.base._history.env._installed
b57a3b
             if install_env_group:
b57a3b
                 action = _("Installing Environment Groups")
b57a3b
                 lines = []
b57a3b
                 for group in install_env_group.values():
b57a3b
-                    lines.append((group.getName(), "", "", "", "", "", ""))
b57a3b
+                    lines.append(format_line(group))
b57a3b
                 pkglist_lines.append((action, lines))
b57a3b
             upgrade_env_group = self.base._history.env._upgraded
b57a3b
             if upgrade_env_group:
b57a3b
                 action = _("Upgrading Environment Groups")
b57a3b
                 lines = []
b57a3b
                 for group in upgrade_env_group.values():
b57a3b
-                    lines.append((group.getName(), "", "", "", "", "", ""))
b57a3b
+                    lines.append(format_line(group))
b57a3b
                 pkglist_lines.append((action, lines))
b57a3b
             remove_env_group = self.base._history.env._removed
b57a3b
             if remove_env_group:
b57a3b
                 action = _("Removing Environment Groups")
b57a3b
                 lines = []
b57a3b
                 for group in remove_env_group.values():
b57a3b
-                    lines.append((group.getName(), "", "", "", "", "", ""))
b57a3b
+                    lines.append(format_line(group))
b57a3b
                 pkglist_lines.append((action, lines))
b57a3b
             install_group = self.base._history.group._installed
b57a3b
             if install_group:
b57a3b
                 action = _("Installing Groups")
b57a3b
                 lines = []
b57a3b
                 for group in install_group.values():
b57a3b
-                    lines.append((group.getName(), "", "", "", "", "", ""))
b57a3b
+                    lines.append(format_line(group))
b57a3b
                 pkglist_lines.append((action, lines))
b57a3b
             upgrade_group = self.base._history.group._upgraded
b57a3b
             if upgrade_group:
b57a3b
                 action = _("Upgrading Groups")
b57a3b
                 lines = []
b57a3b
                 for group in upgrade_group.values():
b57a3b
-                    lines.append((group.getName(), "", "", "", "", "", ""))
b57a3b
+                    lines.append(format_line(group))
b57a3b
                 pkglist_lines.append((action, lines))
b57a3b
             remove_group = self.base._history.group._removed
b57a3b
             if remove_group:
b57a3b
                 action = _("Removing Groups")
b57a3b
                 lines = []
b57a3b
                 for group in remove_group.values():
b57a3b
-                    lines.append((group.getName(), "", "", "", "", "", ""))
b57a3b
+                    lines.append(format_line(group))
b57a3b
                 pkglist_lines.append((action, lines))
b57a3b
         # show skipped conflicting packages
b57a3b
         if not self.conf.best and self.base._goal.actions & forward_actions:
b57a3b
diff --git a/dnf/comps.py b/dnf/comps.py
b57a3b
index 316d647087..4ca15b1e07 100644
b57a3b
--- a/dnf/comps.py
b57a3b
+++ b/dnf/comps.py
b57a3b
@@ -75,7 +75,16 @@ def _by_pattern(pattern, case_sensitive, sqn):
b57a3b
     else:
b57a3b
         match = re.compile(fnmatch.translate(pattern), flags=re.I).match
b57a3b
 
b57a3b
-    return {g for g in sqn if match(g.name) or match(g.id) or match(g.ui_name)}
b57a3b
+    ret = set()
b57a3b
+    for g in sqn:
b57a3b
+        if match(g.id):
b57a3b
+            ret.add(g)
b57a3b
+        elif g.name is not None and match(g.name):
b57a3b
+            ret.add(g)
b57a3b
+        elif g.ui_name is not None and match(g.ui_name):
b57a3b
+            ret.add(g)
b57a3b
+
b57a3b
+    return ret
b57a3b
 
b57a3b
 
b57a3b
 def _fn_display_order(group):
b57a3b
diff --git a/dnf/db/group.py b/dnf/db/group.py
b57a3b
index e3a087760b..5d7e18d1a8 100644
b57a3b
--- a/dnf/db/group.py
b57a3b
+++ b/dnf/db/group.py
b57a3b
@@ -78,8 +78,10 @@ def _get_obj_id(self, obj):
b57a3b
     def new(self, obj_id, name, translated_name, pkg_types):
b57a3b
         swdb_group = self.history.swdb.createCompsGroupItem()
b57a3b
         swdb_group.setGroupId(obj_id)
b57a3b
-        swdb_group.setName(name)
b57a3b
-        swdb_group.setTranslatedName(translated_name)
b57a3b
+        if name is not None:
b57a3b
+            swdb_group.setName(name)
b57a3b
+        if translated_name is not None:
b57a3b
+            swdb_group.setTranslatedName(translated_name)
b57a3b
         swdb_group.setPackageTypes(pkg_types)
b57a3b
         return swdb_group
b57a3b
 
b57a3b
@@ -136,8 +138,10 @@ def _get_obj_id(self, obj):
b57a3b
     def new(self, obj_id, name, translated_name, pkg_types):
b57a3b
         swdb_env = self.history.swdb.createCompsEnvironmentItem()
b57a3b
         swdb_env.setEnvironmentId(obj_id)
b57a3b
-        swdb_env.setName(name)
b57a3b
-        swdb_env.setTranslatedName(translated_name)
b57a3b
+        if name is not None:
b57a3b
+            swdb_env.setName(name)
b57a3b
+        if translated_name is not None:
b57a3b
+            swdb_env.setTranslatedName(translated_name)
b57a3b
         swdb_env.setPackageTypes(pkg_types)
b57a3b
         return swdb_env
b57a3b
 
b57a3b
diff --git a/tests/repos/main_comps.xml b/tests/repos/main_comps.xml
b57a3b
index 9e694d13a5..584bb25b3a 100644
b57a3b
--- a/tests/repos/main_comps.xml
b57a3b
+++ b/tests/repos/main_comps.xml
b57a3b
@@ -49,6 +49,13 @@
b57a3b
       <packagereq type="optional">brokendeps</packagereq>
b57a3b
     </packagelist>
b57a3b
   </group>
b57a3b
+  <group>
b57a3b
+    <id>missing-name-group</id>
b57a3b
+    <name></name>
b57a3b
+    <packagelist>
b57a3b
+      <packagereq type="mandatory">meaning-of-life</packagereq>
b57a3b
+    </packagelist>
b57a3b
+  </group>
b57a3b
   <category>
b57a3b
    <id>base-system</id>
b57a3b
    <display_order>99</display_order>
b57a3b
diff --git a/tests/support.py b/tests/support.py
b57a3b
index e549ba5b95..a7d6a8542c 100644
b57a3b
--- a/tests/support.py
b57a3b
+++ b/tests/support.py
b57a3b
@@ -94,7 +94,7 @@ def mock_open(mock=None, data=None):
b57a3b
 MAIN_NSOLVABLES = 9
b57a3b
 UPDATES_NSOLVABLES = 4
b57a3b
 AVAILABLE_NSOLVABLES = MAIN_NSOLVABLES + UPDATES_NSOLVABLES
b57a3b
-TOTAL_GROUPS = 4
b57a3b
+TOTAL_GROUPS = 5
b57a3b
 TOTAL_NSOLVABLES = SYSTEM_NSOLVABLES + AVAILABLE_NSOLVABLES
b57a3b
 
b57a3b
 
b57a3b
diff --git a/tests/test_comps.py b/tests/test_comps.py
b57a3b
index 30d468e3af..763218587f 100644
b57a3b
--- a/tests/test_comps.py
b57a3b
+++ b/tests/test_comps.py
b57a3b
@@ -107,7 +107,7 @@ def test_group_packages(self):
b57a3b
     def test_iteration(self):
b57a3b
         comps = self.comps
b57a3b
         self.assertEqual([g.name for g in comps.groups_iter()],
b57a3b
-                         ['Base', 'Solid Ground', "Pepper's", "Broken Group"])
b57a3b
+                         ['Base', 'Solid Ground', "Pepper's", "Broken Group", None])
b57a3b
         self.assertEqual([c.name for c in comps.categories_iter()],
b57a3b
                          ['Base System'])
b57a3b
         g = dnf.util.first(comps.groups_iter())
b57a3b
@@ -115,7 +115,7 @@ def test_iteration(self):
b57a3b
 
b57a3b
     def test_group_display_order(self):
b57a3b
         self.assertEqual([g.name for g in self.comps.groups],
b57a3b
-                         ["Pepper's", 'Base', 'Solid Ground', 'Broken Group'])
b57a3b
+                         ["Pepper's", 'Base', 'Solid Ground', 'Broken Group', None])
b57a3b
 
b57a3b
     def test_packages(self):
b57a3b
         comps = self.comps
b57a3b
@@ -127,7 +127,7 @@ def test_packages(self):
b57a3b
 
b57a3b
     def test_size(self):
b57a3b
         comps = self.comps
b57a3b
-        self.assertLength(comps, 6)
b57a3b
+        self.assertLength(comps, 7)
b57a3b
         self.assertLength(comps.groups, tests.support.TOTAL_GROUPS)
b57a3b
         self.assertLength(comps.categories, 1)
b57a3b
         self.assertLength(comps.environments, 1)
b57a3b
diff --git a/tests/test_groups.py b/tests/test_groups.py
b57a3b
index fe388f96c0..8972da687e 100644
b57a3b
--- a/tests/test_groups.py
b57a3b
+++ b/tests/test_groups.py
b57a3b
@@ -295,6 +295,15 @@ def test_group_install_broken_optional_nonstrict(self):
b57a3b
         self.assertLength(inst, 1)
b57a3b
         self.assertEmpty(removed)
b57a3b
 
b57a3b
+    def test_group_install_missing_name(self):
b57a3b
+        comps_group = self.base.comps.group_by_pattern('missing-name-group')
b57a3b
+
b57a3b
+        cnt = self.base.group_install(comps_group.id, ('mandatory', 'default', 'optional'),
b57a3b
+                                      strict=False)
b57a3b
+        self._swdb_commit()
b57a3b
+        self.base.resolve()
b57a3b
+        self.assertEqual(cnt, 1)
b57a3b
+
b57a3b
 
b57a3b
 class EnvironmentInstallTest(tests.support.ResultTestCase):
b57a3b
     """Set up a test where sugar is considered not installed."""