[projects/pld-builder.new] bqueue: render queue.txt and queue.html before making their files

arekm arekm at pld-linux.org
Fri Nov 13 11:26:39 CET 2026


commit d19d8d6b5ef22cdf649c19ae792eefa40e61a5e1
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date:   Fri Nov 13 09:16:45 2026 +0100

    bqueue: render queue.txt and queue.html before making their files
    
    A page that failed to render left a temporary file in www/ behind.

 PLD_Builder/bqueue.py | 33 ++++++++++++++++-----------------
 1 file changed, 16 insertions(+), 17 deletions(-)
---
diff --git a/PLD_Builder/bqueue.py b/PLD_Builder/bqueue.py
index 666a7dc..6b0aa49 100644
--- a/PLD_Builder/bqueue.py
+++ b/PLD_Builder/bqueue.py
@@ -14,6 +14,17 @@ import request
 import util
 
 
+def replace_file(fname, text):
+    """Put text into fname whole; readers see the old file or the new one, never a part"""
+    (fdno, tmpfname) = tempfile.mkstemp(dir=os.path.dirname(fname))
+    with os.fdopen(fdno, "w", encoding="utf-8") as f:
+        f.write(text)
+        f.flush()
+        os.fsync(f.fileno())
+    os.chmod(tmpfname, 0o0644)
+    os.rename(tmpfname, fname)
+
+
 class B_Queue:
     def __init__(self, filename):
         self.name = filename
@@ -21,27 +32,15 @@ class B_Queue:
         self.fd = None
 
     def dump(self, fname):
-        (fdno, tmpfname) = tempfile.mkstemp(dir=os.path.dirname(fname))
-        f = os.fdopen(fdno, "w", encoding="utf-8")
-        self.requests.reverse()
-        for r in self.requests:
+        f = StringIO()
+        for r in reversed(self.requests):
             r.dump(f)
-        self.requests.reverse()
-        f.flush()
-        os.fsync(f.fileno())
-        f.close()
-        os.chmod(tmpfname, 0o0644)
-        os.rename(tmpfname, fname)
+        replace_file(fname, f.getvalue())
 
     def dump_html(self, fname):
-        (fdno, tmpfname) = tempfile.mkstemp(dir=os.path.dirname(fname))
-        f = os.fdopen(fdno, "w", encoding="utf-8")
+        f = StringIO()
         queue_html.write(f, self.requests)
-        f.flush()
-        os.fsync(f.fileno())
-        f.close()
-        os.chmod(tmpfname, 0o0644)
-        os.rename(tmpfname, fname)
+        replace_file(fname, f.getvalue())
 
     # read possibly compressed, signed queue
     def read_signed(self):
================================================================

---- gitweb:

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



More information about the pld-cvs-commit mailing list