From 3738c3e2d1bb6c082707393d71240ff351c64987 Mon Sep 17 00:00:00 2001
From: david-sarah <david-sarah@jacaranda.org>
Date: Wed, 16 May 2012 23:08:39 +0000
Subject: [PATCH] fileutil.py: use try/finally to close file in
 write_atomically.

---
 src/allmydata/util/fileutil.py | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/allmydata/util/fileutil.py b/src/allmydata/util/fileutil.py
index d6235509..7add35cb 100644
--- a/src/allmydata/util/fileutil.py
+++ b/src/allmydata/util/fileutil.py
@@ -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):
-- 
2.45.2