[projects/pld-builder.new] install: return the killset from close_killset() instead of mutating it

arekm arekm at pld-linux.org
Wed Aug 12 11:46:01 CEST 2026


commit 1df1101c12905ff3450491f31ca2da747c869970
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date:   Wed Aug 12 09:41:20 2026 +0200

    install: return the killset from close_killset() instead of mutating it
    
    It edited the caller's dict in place and returned an error string - one answer
    over two channels, which is how the empty-killset path drifted into returning
    True (f98592f). It now takes names and returns (killset, errors). Probe and
    erase order becomes alphabetical, which rpm does not care about.

 PLD_Builder/install.py | 72 ++++++++++++++++++++++++++------------------------
 1 file changed, 38 insertions(+), 34 deletions(-)
---
diff --git a/PLD_Builder/install.py b/PLD_Builder/install.py
index c735d97..ccd561a 100644
--- a/PLD_Builder/install.py
+++ b/PLD_Builder/install.py
@@ -20,33 +20,37 @@ hold = [
 def rpm_remove(pkgs, b):
     return chroot.run("rpm --allmatches -e %s" % pkgs, logfile = b.logfile, user = "root")
 
-def close_killset(killset):
+def close_killset(names):
+    """Return (packages to erase, errors) for names and whatever must go with them.
+
+    poldek reports the whole removal cascade for a package, so one probe per
+    name is enough.  errors is empty when nothing crucial blocks the removal.
+    """
     rx = re.compile(r'^.* marks (?P<name>[^\s]+?)-[^-]+-[^-]+\s.*$')
+    killset = set()
     errors = ""
-    for p in list(killset):
+    for p in sorted(names):
         if p in hold:
-            del killset[p]
             errors += "cannot remove %s because it's crucial\n" % p
-        else:
-            f = chroot.popen("poldek --noask --test --test --erase %s" % p, user = "root", encoding = "utf-8")
-            crucial = 0
-            e = []
-            for l in f:
-                m = rx.search(l)
-                if m:
-                    pkg = m.group('name')
-                    if pkg in hold:
-                        errors += "cannot remove %s because it's required " \
-                                  "by %s, that is crucial\n" % (p, pkg)
-                        crucial = 1
-                    e.append(pkg)
-            f.close()
-            if crucial:
-                del killset[p]
-            else:
-                for p in e:
-                    killset[p] = 2
-    return errors
+            continue
+        f = chroot.popen("poldek --noask --test --test --erase %s" % p, user = "root", encoding = "utf-8")
+        crucial = 0
+        e = []
+        for l in f:
+            m = rx.search(l)
+            if m:
+                pkg = m.group('name')
+                if pkg in hold:
+                    errors += "cannot remove %s because it's required " \
+                              "by %s, that is crucial\n" % (p, pkg)
+                    crucial = 1
+                e.append(pkg)
+        f.close()
+        if crucial:
+            continue
+        killset.add(p)
+        killset.update(e)
+    return killset, errors
 
 def upgrade_from_batch(r, b):
     f = chroot.popen("rpm --test -F %s 2>&1" % ' '.join(b.files), user = "root", encoding = "utf-8")
@@ -56,13 +60,13 @@ def upgrade_from_batch(r, b):
         m = rx.search(l)
         if m: killset[m.group('name')] = 1
     f.close()
-    if len(killset) != 0:
-        err = close_killset(killset)
-        if err != "":
-            util.append_to(b.logfile, err)
-            log.notice("cannot upgrade rpms")
-            return False
-        k = ' '.join(killset.keys())
+    killset, err = close_killset(killset)
+    if err:
+        util.append_to(b.logfile, err)
+        log.notice("cannot upgrade rpms")
+        return False
+    if killset:
+        k = ' '.join(sorted(killset))
         if True:
             b.log_line("upgrade requires removal of %s" % k)
             res = rpm_remove(k, b)
@@ -86,14 +90,14 @@ def upgrade_from_batch(r, b):
 
 def uninstall(conflicting, b):
     b.log_line("uninstalling conflicting packages")
-    err = close_killset(conflicting)
-    if err != "":
+    killset, err = close_killset(conflicting)
+    if err:
         util.append_to(b.logfile, err)
         b.log_line("error: conflicting packages uninstallation failed")
         return False
-    if not conflicting:
+    if not killset:
         return True
-    pkgs = ' '.join(sorted(conflicting.keys()))
+    pkgs = ' '.join(sorted(killset))
     b.log_line("removing: %s" % pkgs)
     res = chroot.run("poldek --noask --erase %s" % pkgs, logfile = b.logfile, user = "root")
     if res != 0:
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/projects/pld-builder.new.git/commitdiff/44916a7a9112928736ec2b65b4fa58a90bc5828c



More information about the pld-cvs-commit mailing list