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

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