Patchwork [4,of,6,v2] bmstore: close file in a finally block in _writerepo

login
register
mail settings
Submitter Augie Fackler
Date Dec. 2, 2015, 4:58 p.m.
Message ID <4600ce9ad6ec0bd96c34.1449075523@imladris.local>
Download mbox | patch
Permalink /patch/11759/
State Accepted
Headers show

Comments

Augie Fackler - Dec. 2, 2015, 4:58 p.m.
# HG changeset patch
# User Augie Fackler <augie@google.com>
# Date 1447293828 18000
#      Wed Nov 11 21:03:48 2015 -0500
# Node ID 4600ce9ad6ec0bd96c34d28b7c61ebe4926f5c2e
# Parent  6a78f21222c1cee841367433bd354ec0402b6346
bmstore: close file in a finally block in _writerepo

Also rename the variable to file_ to avoid shadowing a builtin.
Pierre-Yves David - Dec. 2, 2015, 6:59 p.m.
On 12/02/2015 08:58 AM, Augie Fackler wrote:
> # HG changeset patch
> # User Augie Fackler <augie@google.com>
> # Date 1447293828 18000
> #      Wed Nov 11 21:03:48 2015 -0500
> # Node ID 4600ce9ad6ec0bd96c34d28b7c61ebe4926f5c2e
> # Parent  6a78f21222c1cee841367433bd354ec0402b6346
> bmstore: close file in a finally block in _writerepo

patch up to 4 are pushed. Please see feedback on patch 5.

Patch

diff --git a/mercurial/bookmarks.py b/mercurial/bookmarks.py
--- a/mercurial/bookmarks.py
+++ b/mercurial/bookmarks.py
@@ -132,9 +132,14 @@  class bmstore(dict):
         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()