[projects/pld-builder.new] rpm_builder: fail the build when the src.rpm is gone

arekm arekm at pld-linux.org
Mon Oct 26 17:16:20 CET 2026


commit e054a13259469594460ef32fc0786979c55c9835
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date:   Sat Oct 24 11:31:52 2026 +0200

    rpm_builder: fail the build when the src.rpm is gone
    
    A src.rpm that 404s for over 6 hours was reported as FAIL_SRPM_INSTALL.
    Also check the chroot cat's exit code, count the copied bytes instead
    of trusting Content-Length, and log fetch errors to the build log.

 PLD_Builder/rpm_builder.py | 70 +++++++++++++++++++++++++---------------------
 1 file changed, 38 insertions(+), 32 deletions(-)
---
diff --git a/PLD_Builder/rpm_builder.py b/PLD_Builder/rpm_builder.py
index 61d3cde..28fbad4 100644
--- a/PLD_Builder/rpm_builder.py
+++ b/PLD_Builder/rpm_builder.py
@@ -1,6 +1,7 @@
 # vi: encoding=utf-8 ts=8 sts=4 sw=4 et
 
 
+import contextlib
 import sys
 import os
 import time
@@ -13,7 +14,6 @@ from config import config, init_conf
 from bqueue import B_Queue
 import lock
 import util
-import shutil
 import loop
 import path
 import status
@@ -85,6 +85,7 @@ def check_skip_build(r, b):
     return False
 
 def fetch_src(r, b):
+    """Copy the src.rpm into the chroot.  False when it is gone for good."""
     src_url = config.control_url + "/srpms/" + r.id + "/" + urllib.parse.quote(b.src_rpm)
     b.log_line("fetching %s" % src_url)
     start = time.time()
@@ -117,32 +118,35 @@ def fetch_src(r, b):
                 time.sleep(retry_delay)
                 continue
             else:
-                try:
-                    print("error.errno: %s" % str(error.errno))
-                except Exception as e:
-                    print("error.errno: exception %s" % e)
-                try:
-                    print("error.reason %s" % str(error.reason))
-                except Exception as e:
-                    print("error.reason exception %s" % e)
+                b.log_line("error: unable to fetch %s: %s" % (src_url, error.reason))
                 raise
 
+    size = 0
     o = chroot.popen("cat > %s" % b.src_rpm, mode = "w")
 
     try:
-        shutil.copyfileobj(f, o)
+        while chunk := f.read(65536):
+            o.write(chunk)
+            size += len(chunk)
+        rc = o.close()
     except IOError as e:
         b.log_line("error: unable to write to `%s': %s" % (b.src_rpm, e))
+        with contextlib.suppress(OSError):
+            o.close()
         raise
+    finally:
+        f.close()
+    if rc != 0:
+        msg = f"error: writing `{b.src_rpm}' into the chroot failed with exit code {rc}"
+        b.log_line(msg)
+        raise OSError(msg)
 
-    bytes = float(f.headers['content-length'])
-    f.close()
-    o.close()
     t = time.time() - start
     if t == 0:
-        b.log_line("fetched %d bytes" % bytes)
+        b.log_line("fetched %d bytes" % size)
     else:
-        b.log_line("fetched %d bytes, %.1f K/s" % (bytes, bytes / 1024.0 / t))
+        b.log_line("fetched %d bytes, %.1f K/s" % (size, size / 1024.0 / t))
+    return True
 
 def prepare_env(logfile = None):
     chroot.run("""
@@ -190,26 +194,28 @@ def build_rpm(r, b):
     b.log_line("cleaning up /tmp")
     chroot.run("rm -rf /tmp/B.*", logfile = b.logfile)
 
-    fetch_src(r, b)
-    b.log_line("installing srpm: %s" % b.src_rpm)
-    res = chroot.run("""
-        set -ex;
-        install -d %(topdir)s/{BUILD,RPMS};
-        LC_ALL=en_US.UTF-8 rpm -qp --changelog %(src_rpm)s;
-        rpm -Uhv --nodeps %(rpmdefs)s %(src_rpm)s;
-        rm -f %(src_rpm)s;
-    """ % {
-        'topdir' : b.get_topdir(),
-        'rpmdefs' : b.rpmbuild_opts(),
-        'src_rpm' : b.src_rpm
-    }, logfile = b.logfile)
+    if not fetch_src(r, b):
+        res = "FAIL_SRPM_FETCH"
+    else:
+        b.log_line("installing srpm: %s" % b.src_rpm)
+        res = chroot.run("""
+            set -ex;
+            install -d %(topdir)s/{BUILD,RPMS};
+            LC_ALL=en_US.UTF-8 rpm -qp --changelog %(src_rpm)s;
+            rpm -Uhv --nodeps %(rpmdefs)s %(src_rpm)s;
+            rm -f %(src_rpm)s;
+        """ % {
+            'topdir' : b.get_topdir(),
+            'rpmdefs' : b.rpmbuild_opts(),
+            'src_rpm' : b.src_rpm
+        }, logfile = b.logfile)
+        if res:
+            b.log_line("error: installing src rpm failed")
+            res = "FAIL_SRPM_INSTALL"
     b.files = []
 
     tmpdir = b.tmpdir()
-    if res:
-        b.log_line("error: installing src rpm failed")
-        res = "FAIL_SRPM_INSTALL"
-    else:
+    if not res:
         prepare_env()
         chroot.run("set -x; install -m 700 -d %s" % tmpdir, logfile=b.logfile)
         b.default_target(config.arch)
================================================================

---- gitweb:

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



More information about the pld-cvs-commit mailing list