subrepo: ensure "close()" execution at the end of "_readstorehashcache()"
authorFUJIWARA Katsunori <foozy@lares.dti.ne.jp>
Fri, 20 Jun 2014 00:21:19 +0900
changeset 21888 dfb8f757750c
parent 21887 9aaffb22d7d7
child 21889 ee7e8dcffc92
subrepo: ensure "close()" execution at the end of "_readstorehashcache()" Before this patch, "close()" for the file object opened in "_readstorehashcache()" 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 "_readstorehashcache()" 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
@@ -576,8 +576,10 @@
         if not os.path.exists(cachefile):
             return ''
         fd = open(cachefile, 'r')
-        pullstate = fd.readlines()
-        fd.close()
+        try:
+            pullstate = fd.readlines()
+        finally:
+            fd.close()
         return pullstate
 
     def _cachestorehash(self, remotepath):