]> git.pld-linux.org Git - projects/pld-builder.new.git/commitdiff
dump to temporary file, try to fsync and then rename (all that to avoid queue file...
authorArkadiusz Miśkiewicz <arekm@maven.pl>
Sat, 13 Nov 2010 21:38:07 +0000 (21:38 +0000)
committercvs2git <feedback@pld-linux.org>
Sun, 24 Jun 2012 12:13:13 +0000 (12:13 +0000)
Changed files:
    PLD_Builder/bqueue.py -> 1.18
    PLD_Builder/request_handler.py -> 1.53
    PLD_Builder/srpm_builder.py -> 1.73

PLD_Builder/bqueue.py
PLD_Builder/request_handler.py
PLD_Builder/srpm_builder.py

index 2b5113725c6d54600a739cfd9d5d87b7569e2128..a1a24c36a07741a3fb2a66a5f93aae4c44c5b747 100644 (file)
@@ -7,6 +7,7 @@ import StringIO
 import os
 import fcntl
 import string
+import tempfile
 
 # PLD_Builder:
 import gpg
@@ -20,13 +21,31 @@ class B_Queue:
         self.requests = []
         self.fd = None
 
-    def dump(self, f):
+    def dump(self, fname):
+        (f, tmpfname) = tempfile.mkstemp(dir=os.path.dirname(fname))
+        self.dump_fobj(f)
+        f.flush()
+        os.fsync(f.fileno())
+        f.close()
+        os.chmod(tmpfname, 0644)
+        os.rename(tmpfname, fname)
+
+    def dump_fobj(self, f):
         self.requests.reverse()
         for r in self.requests:
-            r.dump(f)
+            r.dump_fobj(f)
         self.requests.reverse()
 
-    def dump_html(self, f):
+    def dump_html(self, fname):
+        (f, tmpfname) = tempfile.mkstemp(dir=os.path.dirname(fname))
+        self.dump_html_fobj(f)
+        f.flush()
+        os.fsync(f.fileno())
+        f.close()
+        os.chmod(tmpfname, 0644)
+        os.rename(tmpfname, fname)
+
+    def dump_html_fobj(self, f):
         f.write("""
 <html>
     <head>
@@ -39,7 +58,7 @@ class B_Queue:
         )
         self.requests.reverse()
         for r in self.requests:
-            r.dump_html(f)
+            r.dump_html_fobj(f)
         self.requests.reverse()
         f.write("</body></html>\n")
 
@@ -106,14 +125,19 @@ class B_Queue:
         self._write_to(sio)
         sio.seek(0)
         sio.write(gpg.sign(sio.read()))
-        if os.access(name, os.F_OK): os.unlink(name)
+        sio.seek(0)
+        (f, tmpname) = tempfile.mkstemp(dir=os.path.dirname(name))
         if re.search(r"\.gz$", name):
-            f = gzip.open(name, "w", 6)
+            fgz = gzip.GzipFile(filename=name, mode="w", compresslevel=6, fileobj=f)
+            util.sendfile(sio, fgz)
+            fgz.close()
         else:
-            f = open(name, "w")
-        sio.seek(0)
-        util.sendfile(sio, f)
+            util.sendfile(sio, f)
+        f.flush()
+        os.fsync(f.fileno())
         f.close()
+        os.chmod(tmpname, 0644)
+        os.rename(tmpfname, name)
 
     def add(self, req):
         self.requests.append(req)
index ce79965661c1b9340eed0cf480d97c56ad52b5a3..9416809dd385d16387967d19ff7ba5fdc89d8c12 100644 (file)
@@ -149,12 +149,9 @@ def handle_notification(r, user):
         return True
     q.requests = filter(leave_it, q.requests)
     q.write()
-    q.dump(open(path.queue_stats_file, "w"))
-    q.dump_html(open(path.queue_html_stats_file, "w"))
-    os.chmod(path.queue_html_stats_file, 0644)
-    os.chmod(path.queue_stats_file, 0644)
+    q.dump(path.queue_stats_file)
+    q.dump_html(path.queue_html_stats_file)
     q.write_signed(path.req_queue_signed_file)
-    os.chmod(path.req_queue_signed_file, 0644)
     q.unlock()
 
 def handle_request(req, filename = None):
index 64081a490286a33113398cc1a8ec01e16a3cde18..dc50791d882d7f6803fb86f8a274457f40c06f4d 100644 (file)
@@ -58,12 +58,9 @@ def store_binary_request(r):
     q.read()
     q.add(r)
     q.write()
-    q.dump(open(path.queue_stats_file, "w"))
-    q.dump_html(open(path.queue_html_stats_file, "w"))
-    os.chmod(path.queue_stats_file, 0644)
-    os.chmod(path.queue_html_stats_file, 0644)
+    q.dump(path.queue_stats_file)
+    q.dump_html(path.queue_html_stats_file)
     q.write_signed(path.req_queue_signed_file)
-    os.chmod(path.req_queue_signed_file, 0644)
     q.unlock()
     cnt_f.seek(0)
     cnt_f.write("%d\n" % num)
This page took 0.093193 seconds and 4 git commands to generate.