changeset 21887:9aaffb22d7d7

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.
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
date Fri, 20 Jun 2014 00:21:19 +0900
parents b9e8fdc35daf
children dfb8f757750c
files mercurial/subrepo.py
diffstat 1 files changed, 4 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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):