]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blobdiff - src/allmydata/util/fileutil.py
write node.url and portnum files atomically, to fix race in test_runner
[tahoe-lafs/tahoe-lafs.git] / src / allmydata / util / fileutil.py
index bfcffd8f9932df2b665e32f45357b6166245e62b..d6235509848cf53fc3928da9044b57a6175476dd 100644 (file)
@@ -247,6 +247,12 @@ def move_into_place(source, dest):
         remove_if_possible(dest)
     os.rename(source, dest)
 
+def write_atomically(target, contents, mode="b"):
+    f = open(target+".tmp", "w"+mode)
+    f.write(contents)
+    f.close()
+    move_into_place(target+".tmp", target)
+
 def write(path, data):
     wf = open(path, "wb")
     try: