]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
fileutil.py: use try/finally to close file in write_atomically.
authordavid-sarah <david-sarah@jacaranda.org>
Wed, 16 May 2012 23:08:39 +0000 (23:08 +0000)
committerdavid-sarah <david-sarah@jacaranda.org>
Wed, 16 May 2012 23:08:39 +0000 (23:08 +0000)
src/allmydata/util/fileutil.py

index d6235509848cf53fc3928da9044b57a6175476dd..7add35cb41a968c2952c17e159b00eca149cde00 100644 (file)
@@ -249,8 +249,10 @@ def move_into_place(source, dest):
 
 def write_atomically(target, contents, mode="b"):
     f = open(target+".tmp", "w"+mode)
-    f.write(contents)
-    f.close()
+    try:
+        f.write(contents)
+    finally:
+        f.close()
     move_into_place(target+".tmp", target)
 
 def write(path, data):