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

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