From: david-sarah Date: Wed, 16 May 2012 23:08:39 +0000 (+0000) Subject: fileutil.py: use try/finally to close file in write_atomically. X-Git-Url: https://git.rkrishnan.org/%5B/frontends//%22file:/%22?a=commitdiff_plain;h=3738c3e2d1bb6c082707393d71240ff351c64987;p=tahoe-lafs%2Ftahoe-lafs.git fileutil.py: use try/finally to close file in write_atomically. --- 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):