bmstore: close file in a finally block in _writerepo
authorAugie Fackler <augie@google.com>
Wed, 11 Nov 2015 21:03:48 -0500
changeset 27188 6a1301e22bd7
parent 27187 d9dcc5c09d77
child 27189 7b6cb7c15109
bmstore: close file in a finally block in _writerepo Also rename the variable to file_ to avoid shadowing a builtin.
mercurial/bookmarks.py
--- a/mercurial/bookmarks.py	Wed Nov 11 21:01:23 2015 -0500
+++ b/mercurial/bookmarks.py	Wed Nov 11 21:03:48 2015 -0500
@@ -132,9 +132,14 @@
         wlock = repo.wlock()
         try:
 
-            file = repo.vfs('bookmarks', 'w', atomictemp=True)
-            self._write(file)
-            file.close()
+            file_ = repo.vfs('bookmarks', 'w', atomictemp=True)
+            try:
+                self._write(file_)
+            except: # re-raises
+                file_.discard()
+                raise
+            finally:
+                file_.close()
 
         finally:
             wlock.release()