[projects/pld-builder.new] chroot: fail loudly when copying a file out of the chroot fails
arekm
arekm at pld-linux.org
Mon Oct 26 17:15:45 CET 2026
commit 69357f1175552a6b2241d68ccf4c9e10e24a77a4
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date: Sat Oct 24 11:05:46 2026 +0200
chroot: fail loudly when copying a file out of the chroot fails
cp() ignored cat's exit status, so a truncated package went to ftp and
the original was removed anyway. Callers now fail the batch, and
rpm_builder copies a batch out before caching or installing it.
PLD_Builder/chroot.py | 22 +++++++++++-----------
PLD_Builder/rpm_builder.py | 22 +++++++++++++++++-----
PLD_Builder/srpm_builder.py | 11 ++++++++---
3 files changed, 36 insertions(+), 19 deletions(-)
---
diff --git a/PLD_Builder/chroot.py b/PLD_Builder/chroot.py
index 4e6bd3d..2efa731 100644
--- a/PLD_Builder/chroot.py
+++ b/PLD_Builder/chroot.py
@@ -50,16 +50,16 @@ def run(cmd, user = "builder", logfile = None, logstdout = None, nonet=True):
return r
def cp(file, outfile, user="builder", rm=False):
- f_out = open(outfile, 'wb')
cmd = "cat %s" % file
if rm:
- cmd += "; rm %s" % file
- p = subprocess.Popen(command(cmd, user), shell=True, stdout=subprocess.PIPE, close_fds=True)
- f_in = p.stdout
- shutil.copyfileobj(f_in, f_out)
- f_out.close()
- r = f_in.close()
- if r == None:
- return 0
- else:
- return r
+ cmd += " && rm %s" % file
+ with open(outfile, 'wb') as f_out:
+ p = subprocess.Popen(command(cmd, user), shell=True, stdout=subprocess.PIPE, close_fds=True)
+ try:
+ shutil.copyfileobj(p.stdout, f_out)
+ finally:
+ p.stdout.close()
+ r = p.wait()
+ # a failed copy leaves a truncated outfile that callers would upload
+ if r != 0:
+ raise OSError("copying %s out of chroot failed with exit code %d" % (file, r))
diff --git a/PLD_Builder/rpm_builder.py b/PLD_Builder/rpm_builder.py
index 0d661ee..61d3cde 100644
--- a/PLD_Builder/rpm_builder.py
+++ b/PLD_Builder/rpm_builder.py
@@ -279,6 +279,23 @@ def build_rpm(r, b):
def ll(l):
util.append_to(b.logfile, l)
+ # copy out first: a batch that cannot be copied must not reach the rpm
+ # cache or the chroot, and ftp gets every package or none; the topdir goes away below
+ copied = []
+ for f in b.files:
+ local = r.tmp_dir + os.path.basename(f)
+ try:
+ chroot.cp(f, outfile = local)
+ except OSError as e:
+ b.log_line(f"error: {e}")
+ res = "FAIL_COPY"
+ b.files = []
+ break
+ copied.append(local)
+ else:
+ for local in copied:
+ ftp.add(local)
+
if b.files != []:
rpm_cache_dir = config.rpm_cache_dir
if "test-build" not in r.flags:
@@ -298,11 +315,6 @@ def build_rpm(r, b):
ll("not upgrading")
ll("End-PLD-Builder-Info")
- for f in b.files:
- local = r.tmp_dir + os.path.basename(f)
- chroot.cp(f, outfile = local, rm = True)
- ftp.add(local)
-
# cleanup all remains from this build
chroot.run("""
set -ex;
diff --git a/PLD_Builder/srpm_builder.py b/PLD_Builder/srpm_builder.py
index 5c3e88b..8255f28 100644
--- a/PLD_Builder/srpm_builder.py
+++ b/PLD_Builder/srpm_builder.py
@@ -72,7 +72,11 @@ def transfer_file(r, b):
local = path.srpms_dir + '/' + r.id + "/" + b.src_rpm
f = b.src_rpm_file
# export files from chroot
- chroot.cp(f, outfile = local, rm = True)
+ try:
+ chroot.cp(f, outfile = local, rm = True)
+ except OSError as e:
+ util.append_to(b.logfile, f"error: {e}")
+ return False
os.chmod(local, 0o0644)
ftp.add(local)
@@ -82,6 +86,7 @@ def transfer_file(r, b):
f.write("info:build:%s:requester:%s\ninfo:build:%s:requester_email:%s\nfile:SRPMS:%s\nEND\n" % (b.gb_id, b.requester, b.gb_id, b.requester_email, b.src_rpm))
f.close()
ftp.add(fname, "uploadinfo")
+ return True
def build_srpm(r, b):
if len(b.spec) <= len('.spec'):
@@ -122,8 +127,8 @@ def build_srpm(r, b):
util.append_to(b.logfile, "Tagging with prefix: %s" % pref)
res = chroot.run("cd rpm/packages; ./builder -bs %s -r %s -Tp %s -Tv %s %s" % \
(b.bconds_string(), b.branch, pref, b.defines_string(), b.spec), logfile = b.logfile, nonet=False)
- if res == 0:
- transfer_file(r, b)
+ if res == 0 and not transfer_file(r, b):
+ res = "FAIL"
packagename = b.spec[:-5]
packagedir = "rpm/packages/%s" % packagename
================================================================
---- gitweb:
http://git.pld-linux.org/gitweb.cgi/projects/pld-builder.new.git/commitdiff/ce9feb3c796ed049b6dd260a50d94d80feb1656d
More information about the pld-cvs-commit
mailing list