subrepo: ensure "close()" execution at the end of "_calcfilehash()"
authorFUJIWARA Katsunori <foozy@lares.dti.ne.jp>
Fri, 20 Jun 2014 00:21:19 +0900
changeset 21887 9aaffb22d7d7
parent 21886 b9e8fdc35daf
child 21888 dfb8f757750c
subrepo: ensure "close()" execution at the end of "_calcfilehash()" Before this patch, "close()" for the file object opened in "_calcfilehash()" 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 "_calcfilehash()" 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
@@ -35,8 +35,10 @@
     data = ''
     if os.path.exists(filename):
         fd = open(filename, 'rb')
-        data = fd.read()
-        fd.close()
+        try:
+            data = fd.read()
+        finally:
+            fd.close()
     return util.sha1(data).hexdigest()
 
 class SubrepoAbort(error.Abort):