subrepo: ensure "close()" execution at the end of "_cachestorehash()"
authorFUJIWARA Katsunori <foozy@lares.dti.ne.jp>
Fri, 20 Jun 2014 00:21:19 +0900
changeset 21889 ee7e8dcffc92
parent 21888 dfb8f757750c
child 21890 0f916db7f297
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.
mercurial/subrepo.py
--- a/mercurial/subrepo.py	Fri Jun 20 00:21:19 2014 +0900
+++ b/mercurial/subrepo.py	Fri Jun 20 00:21:19 2014 +0900
@@ -596,8 +596,10 @@
             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()