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

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Thu Jun 19 10:43:20 CDT 2014


# HG changeset patch
# User FUJIWARA Katsunori <foozy at 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.

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()
 


More information about the Mercurial-devel mailing list