[projects/pld-builder.new] util: add write_atomic(), from buildlogs' .desc writing

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


commit 1125a55cf472e67254950e88fc66d7db7a9e096d
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date:   Sat Oct 24 14:44:02 2026 +0200

    util: add write_atomic(), from buildlogs' .desc writing
    
    No behaviour change.

 PLD_Builder/buildlogs.py | 5 +----
 PLD_Builder/util.py      | 6 ++++++
 2 files changed, 7 insertions(+), 4 deletions(-)
---
diff --git a/PLD_Builder/buildlogs.py b/PLD_Builder/buildlogs.py
index 823bbdd..130150c 100644
--- a/PLD_Builder/buildlogs.py
+++ b/PLD_Builder/buildlogs.py
@@ -68,10 +68,7 @@ END
 
         q = self.queue[:]
         for l in q:
-            f = open(path.buildlogs_queue_dir + '/' + l['id'] + ".desc.tmp", "w")
-            f.write(desc(l))
-            f.close()
-            os.rename(path.buildlogs_queue_dir + '/' + l['id'] + ".desc.tmp", path.buildlogs_queue_dir + '/' + l['id'] + ".desc")
+            util.write_atomic(path.buildlogs_queue_dir + '/' + l['id'] + ".desc", desc(l))
             self.queue.remove(l)
 
 queue = Buildlogs_Queue()
diff --git a/PLD_Builder/util.py b/PLD_Builder/util.py
index 1f27885..ca79f2f 100644
--- a/PLD_Builder/util.py
+++ b/PLD_Builder/util.py
@@ -17,6 +17,12 @@ def append_to(logfile, msg):
     f.write("%s\n" % msg)
     f.close()
 
+def write_atomic(name, text):
+    """Write a file that readers never see half-written."""
+    with open(name + ".tmp", "w") as f:
+        f.write(text)
+    os.rename(name + ".tmp", name)
+
 def clean_tmp(dir):
     # FIXME: use python
     os.system("rm -f %s/* 2>/dev/null; rmdir %s 2>/dev/null" % (dir, dir))
================================================================

---- gitweb:

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



More information about the pld-cvs-commit mailing list