[projects/pld-builder.new] bqueue: replace queue.gz atomically
arekm
arekm at pld-linux.org
Mon Oct 26 17:15:40 CET 2026
commit f1c9d15462daf5afcff5c7d88b7f4648ae9a3799
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date: Sat Oct 24 11:05:21 2026 +0200
bqueue: replace queue.gz atomically
Bin builders could fetch a half-written queue.gz.
PLD_Builder/bqueue.py | 35 ++++++++++++++---------------------
1 file changed, 14 insertions(+), 21 deletions(-)
---
diff --git a/PLD_Builder/bqueue.py b/PLD_Builder/bqueue.py
index ecbf75c..c4d57c3 100644
--- a/PLD_Builder/bqueue.py
+++ b/PLD_Builder/bqueue.py
@@ -6,7 +6,6 @@ from io import StringIO
import os
import fcntl
import tempfile
-import shutil
# PLD_Builder:
import gpg
@@ -125,27 +124,21 @@ class B_Queue:
def write_signed(self, name):
sio = StringIO()
self._write_to(sio)
- sio.seek(0)
- sio.write(util.to_str(gpg.sign(sio.read())))
- sio.seek(0)
+ body = sio.getvalue()
+ # the plain copy in front is read by make-request.sh --skip; gpg skips it
+ signed = util.to_bytes(body) + gpg.sign(body)
+ # bin builders poll this file over http; replace it atomically
(fdno, tmpname) = tempfile.mkstemp(dir=os.path.dirname(name))
- f = os.fdopen(fdno, "w")
- shutil.copyfileobj(sio, f)
- f.flush()
- os.fsync(f.fileno())
- f.close()
- if re.search(r"\.gz$", name):
- f_in = open(tmpname, 'rb')
- f_out = gzip.open(name, 'wb')
- shutil.copyfileobj(f_in, f_out)
- f_in.close();
- f_out.flush();
- os.fsync(f_out.fileno())
- f_out.close();
- os.remove(tmpname)
- else:
- os.rename(tmpname, name)
- os.chmod(name, 0o0644)
+ with os.fdopen(fdno, "wb") as f:
+ if name.endswith(".gz"):
+ with gzip.GzipFile(fileobj=f, mode="wb") as gz:
+ gz.write(signed)
+ else:
+ f.write(signed)
+ f.flush()
+ os.fsync(f.fileno())
+ os.chmod(tmpname, 0o0644)
+ os.rename(tmpname, name)
def add(self, req):
self.requests.append(req)
================================================================
---- gitweb:
http://git.pld-linux.org/gitweb.cgi/projects/pld-builder.new.git/commitdiff/ce9feb3c796ed049b6dd260a50d94d80feb1656d
More information about the pld-cvs-commit
mailing list