Patchwork [5,of,7,STABLE] subrepo: ensure "close()" execution at the end of "_cachestorehash()"

login
register
mail settings
Submitter Katsunori FUJIWARA
Date June 19, 2014, 3:43 p.m.
Message ID <017ffac6f0310a9c5fe8.1403192600@juju>
Download mbox | patch
Permalink /patch/5021/
State Accepted
Commit ee7e8dcffc926c0ce7359267e041d858843dc08a
Headers show

Comments

Katsunori FUJIWARA - June 19, 2014, 3:43 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1403191279 -32400
#      Fri Jun 20 00:21:19 2014 +0900
# Branch stable
# Node ID 017ffac6f0310a9c5fe82d0d33ae98e99ccefc6b
# Parent  ad57f7ad7245023c5ab598e9918c5308ecfb4727
subrepo: ensure "close()" execution at the end of "_cachestorehash()"

Before this patch, "close()" for the file object opened in
"_cachestorehash()" may not be executed, if unexpected exception is
raised, because it isn't executed in "finally" clause.

This patch ensures "close()" execution at the end of
"_cachestorehash()" by moving it into "finally" clause.

Patch

diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py
--- a/mercurial/subrepo.py
+++ b/mercurial/subrepo.py
@@ -592,8 +592,10 @@  class hgsubrepo(abstractsubrepo):
             if not os.path.exists(cachedir):
                 util.makedirs(cachedir, notindexed=True)
             fd = open(cachefile, 'w')
-            fd.writelines(storehash)
-            fd.close()
+            try:
+                fd.writelines(storehash)
+            finally:
+                fd.close()
         finally:
             lock.release()