Blame SOURCES/0002-versionlock-fix-multi-pkg-lock-RhBug2013324.patch

67fe31
From e289904dcd9c93ad8e1c3b01878599e9d65fa2cc Mon Sep 17 00:00:00 2001
67fe31
From: Nicola Sella <nsella@redhat.com>
67fe31
Date: Mon, 1 Nov 2021 18:29:40 +0100
67fe31
Subject: [PATCH] [versionlock] fix multi pkg lock (RhBug:2013324)
67fe31
67fe31
= changelog =
67fe31
msg: [versionlock] Fix: Multiple package-name-spec arguments don't lock
67fe31
correctly (RhBug:2001039)
67fe31
type: bugfix
67fe31
resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2013324
67fe31
---
67fe31
 plugins/versionlock.py | 57 +++++++++++++++++++++++++++++++++------------------------
67fe31
 1 file changed, 33 insertions(+), 24 deletions(-)
67fe31
67fe31
diff --git a/plugins/versionlock.py b/plugins/versionlock.py
67fe31
index 19fbd8c..32c51da 100644
67fe31
--- a/plugins/versionlock.py
67fe31
+++ b/plugins/versionlock.py
67fe31
@@ -171,25 +171,27 @@ class VersionLockCommand(dnf.cli.Command):
67fe31
                 cmd = self.opts.subcommand
67fe31
 
67fe31
         if cmd == 'add':
67fe31
-            (entry, entry_cmd) = _search_locklist(self.opts.package)
67fe31
-            if entry == '':
67fe31
-                _write_locklist(self.base, self.opts.package, self.opts.raw, True,
67fe31
-                                "\n# Added lock on %s\n" % time.ctime(),
67fe31
-                                ADDING_SPEC, '')
67fe31
-            elif cmd != entry_cmd:
67fe31
-                raise dnf.exceptions.Error(ALREADY_EXCLUDED.format(entry))
67fe31
-            else:
67fe31
-                logger.info("%s %s", EXISTING_SPEC, entry)
67fe31
+            results = _search_locklist(self.opts.package)
67fe31
+            for entry, entry_cmd in results:
67fe31
+                if entry_cmd == '':
67fe31
+                    _write_locklist(self.base, [entry], self.opts.raw, True,
67fe31
+                                    "\n# Added lock on %s\n" % time.ctime(),
67fe31
+                                    ADDING_SPEC, '')
67fe31
+                elif cmd != entry_cmd:
67fe31
+                    raise dnf.exceptions.Error(ALREADY_EXCLUDED.format(entry))
67fe31
+                else:
67fe31
+                    logger.info("%s %s", EXISTING_SPEC, entry)
67fe31
         elif cmd == 'exclude':
67fe31
-            (entry, entry_cmd) = _search_locklist(self.opts.package)
67fe31
-            if entry == '':
67fe31
-                _write_locklist(self.base, self.opts.package, self.opts.raw, False,
67fe31
-                                "\n# Added exclude on %s\n" % time.ctime(),
67fe31
-                                EXCLUDING_SPEC, '!')
67fe31
-            elif cmd != entry_cmd:
67fe31
-                raise dnf.exceptions.Error(ALREADY_LOCKED.format(entry))
67fe31
-            else:
67fe31
-                logger.info("%s %s", EXISTING_SPEC, entry)
67fe31
+            results = _search_locklist(self.opts.package)
67fe31
+            for entry, entry_cmd in results:
67fe31
+                if entry_cmd == '':
67fe31
+                    _write_locklist(self.base, [entry], self.opts.raw, False,
67fe31
+                                    "\n# Added exclude on %s\n" % time.ctime(),
67fe31
+                                    EXCLUDING_SPEC, '!')
67fe31
+                elif cmd != entry_cmd:
67fe31
+                    raise dnf.exceptions.Error(ALREADY_LOCKED.format(entry))
67fe31
+                else:
67fe31
+                    logger.info("%s %s", EXISTING_SPEC, entry)
67fe31
         elif cmd == 'list':
67fe31
             for pat in _read_locklist():
67fe31
                 print(pat)
67fe31
@@ -237,14 +239,21 @@ def _read_locklist():
67fe31
 
67fe31
 
67fe31
 def _search_locklist(package):
67fe31
+    results = []
67fe31
     found = action = ''
67fe31
     locked_specs = _read_locklist()
67fe31
-    for ent in locked_specs:
67fe31
-        if _match(ent, package):
67fe31
-            found = ent
67fe31
-            action = 'exclude' if ent.startswith('!') else 'add'
67fe31
-            break
67fe31
-    return (found, action)
67fe31
+    for pkg in package:
67fe31
+        match = False
67fe31
+        for ent in locked_specs:
67fe31
+            found = action = ''
67fe31
+            if _match(ent, [pkg]):
67fe31
+                found = ent
67fe31
+                action = 'exclude' if ent.startswith('!') else 'add'
67fe31
+                results.append((found, action))
67fe31
+                match = True
67fe31
+        if not match:
67fe31
+            results.append((pkg, action))
67fe31
+    return results
67fe31
 
67fe31
 
67fe31
 def _write_locklist(base, args, raw, try_installed, comment, info, prefix):
67fe31
--
67fe31
libgit2 1.1.0
67fe31