Blob Blame History Raw
From e289904dcd9c93ad8e1c3b01878599e9d65fa2cc Mon Sep 17 00:00:00 2001
From: Nicola Sella <nsella@redhat.com>
Date: Mon, 1 Nov 2021 18:29:40 +0100
Subject: [PATCH] [versionlock] fix multi pkg lock (RhBug:2013324)

= changelog =
msg: [versionlock] Fix: Multiple package-name-spec arguments don't lock
correctly (RhBug:2001039)
type: bugfix
resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2013324
---
 plugins/versionlock.py | 57 +++++++++++++++++++++++++++++++++------------------------
 1 file changed, 33 insertions(+), 24 deletions(-)

diff --git a/plugins/versionlock.py b/plugins/versionlock.py
index 19fbd8c..32c51da 100644
--- a/plugins/versionlock.py
+++ b/plugins/versionlock.py
@@ -171,25 +171,27 @@ class VersionLockCommand(dnf.cli.Command):
                 cmd = self.opts.subcommand
 
         if cmd == 'add':
-            (entry, entry_cmd) = _search_locklist(self.opts.package)
-            if entry == '':
-                _write_locklist(self.base, self.opts.package, self.opts.raw, True,
-                                "\n# Added lock on %s\n" % time.ctime(),
-                                ADDING_SPEC, '')
-            elif cmd != entry_cmd:
-                raise dnf.exceptions.Error(ALREADY_EXCLUDED.format(entry))
-            else:
-                logger.info("%s %s", EXISTING_SPEC, entry)
+            results = _search_locklist(self.opts.package)
+            for entry, entry_cmd in results:
+                if entry_cmd == '':
+                    _write_locklist(self.base, [entry], self.opts.raw, True,
+                                    "\n# Added lock on %s\n" % time.ctime(),
+                                    ADDING_SPEC, '')
+                elif cmd != entry_cmd:
+                    raise dnf.exceptions.Error(ALREADY_EXCLUDED.format(entry))
+                else:
+                    logger.info("%s %s", EXISTING_SPEC, entry)
         elif cmd == 'exclude':
-            (entry, entry_cmd) = _search_locklist(self.opts.package)
-            if entry == '':
-                _write_locklist(self.base, self.opts.package, self.opts.raw, False,
-                                "\n# Added exclude on %s\n" % time.ctime(),
-                                EXCLUDING_SPEC, '!')
-            elif cmd != entry_cmd:
-                raise dnf.exceptions.Error(ALREADY_LOCKED.format(entry))
-            else:
-                logger.info("%s %s", EXISTING_SPEC, entry)
+            results = _search_locklist(self.opts.package)
+            for entry, entry_cmd in results:
+                if entry_cmd == '':
+                    _write_locklist(self.base, [entry], self.opts.raw, False,
+                                    "\n# Added exclude on %s\n" % time.ctime(),
+                                    EXCLUDING_SPEC, '!')
+                elif cmd != entry_cmd:
+                    raise dnf.exceptions.Error(ALREADY_LOCKED.format(entry))
+                else:
+                    logger.info("%s %s", EXISTING_SPEC, entry)
         elif cmd == 'list':
             for pat in _read_locklist():
                 print(pat)
@@ -237,14 +239,21 @@ def _read_locklist():
 
 
 def _search_locklist(package):
+    results = []
     found = action = ''
     locked_specs = _read_locklist()
-    for ent in locked_specs:
-        if _match(ent, package):
-            found = ent
-            action = 'exclude' if ent.startswith('!') else 'add'
-            break
-    return (found, action)
+    for pkg in package:
+        match = False
+        for ent in locked_specs:
+            found = action = ''
+            if _match(ent, [pkg]):
+                found = ent
+                action = 'exclude' if ent.startswith('!') else 'add'
+                results.append((found, action))
+                match = True
+        if not match:
+            results.append((pkg, action))
+    return results
 
 
 def _write_locklist(base, args, raw, try_installed, comment, info, prefix):
--
libgit2 1.1.0