From: Marcin Krol Date: Sun, 2 May 2021 13:43:39 +0000 (+0200) Subject: - drop util.sendfile, use shutil.copyfileobj instead X-Git-Url: https://git.tld-linux.org/?a=commitdiff_plain;h=a68953c88fba6e657febf9cb06273f44288f759c;p=tld-builder.git - drop util.sendfile, use shutil.copyfileobj instead --- diff --git a/TLD_Builder/bqueue.py b/TLD_Builder/bqueue.py index 131b911..f90de62 100644 --- a/TLD_Builder/bqueue.py +++ b/TLD_Builder/bqueue.py @@ -133,7 +133,7 @@ class B_Queue: sio.seek(0) (fdno, tmpname) = tempfile.mkstemp(dir=os.path.dirname(name)) f = os.fdopen(fdno, "w") - util.sendfile(sio, f) + shutil.copyfileobj(sio, f) f.flush() os.fsync(f.fileno()) f.close() diff --git a/TLD_Builder/mailer.py b/TLD_Builder/mailer.py index f76a8bd..764bdf4 100644 --- a/TLD_Builder/mailer.py +++ b/TLD_Builder/mailer.py @@ -5,7 +5,7 @@ import os import sys from io import StringIO from config import config -import util +import shutil import log def recode(s): @@ -58,7 +58,7 @@ class Message: self.body.write("\n\n[...]\n\n") line += 1 else: - util.sendfile(open(log), self.body) + shutil.copyfileobj(open(log), self.body) def set_std_headers(self): self.headers["Date"] = time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime()) @@ -73,7 +73,7 @@ class Message: f.write("%s: %s\n" % (k, v)) f.write("\n") self.body.seek(0) - util.sendfile(self.body, f) + shutil.copyfileobj(self.body, f) def send(self): if not os.path.exists("/usr/lib/sendmail"): diff --git a/TLD_Builder/request_fetcher.py b/TLD_Builder/request_fetcher.py index 9a1caa5..ae237a2 100644 --- a/TLD_Builder/request_fetcher.py +++ b/TLD_Builder/request_fetcher.py @@ -12,6 +12,7 @@ import log import status import lock import util +import shutil import gpg import request import loop @@ -69,7 +70,7 @@ def fetch_queue(control_url): log.error("can't fetch %s: %s" % (control_url + "/queue.gz", e)) sys.exit(1) sio = BytesIO() - util.sendfile(f, sio) + shutil.copyfileobj(f, sio) f.close() sio.seek(0) f = gzip.GzipFile(fileobj = sio) diff --git a/TLD_Builder/rpm_builder.py b/TLD_Builder/rpm_builder.py index d8fdb9c..c2ac363 100644 --- a/TLD_Builder/rpm_builder.py +++ b/TLD_Builder/rpm_builder.py @@ -14,6 +14,7 @@ from config import config, init_conf from bqueue import B_Queue import lock import util +import shutil import loop import path import status @@ -128,11 +129,12 @@ def fetch_src(r, b): o = chroot.popen("cat > %s" % b.src_rpm, mode = "w") try: - bytes = util.sendfile(f, o) + shutil.copyfileobj(f, o) except IOError as e: b.log_line("error: unable to write to `%s': %s" % (b.src_rpm, e)) raise + bytes = f.tell() f.close() o.close() t = time.time() - start diff --git a/TLD_Builder/util.py b/TLD_Builder/util.py index 602bad1..af6b8f1 100644 --- a/TLD_Builder/util.py +++ b/TLD_Builder/util.py @@ -32,15 +32,6 @@ def pkg_name(nvr): def msg(m): sys.stderr.write(m) -def sendfile(src, dst): - cnt = 0 - while 1: - s = src.read(10000) - if s == "" or s == b"": break - cnt += len(s) - dst.write(s) - return cnt - def append_to(log, msg): f = open(log, "a") f.write("%s\n" % msg)