Patchwork [4,of,7,STABLE] subrepo: ensure "close()" execution at the end of "_readstorehashcache()"

login
register
mail settings
Submitter Katsunori FUJIWARA
Date June 19, 2014, 3:43 p.m.
Message ID <ad57f7ad7245023c5ab5.1403192599@juju>
Download mbox | patch
Permalink /patch/5019/
State Accepted
Commit dfb8f757750cf75abb2bb1e27514f8c43b66d893
Headers show

Comments

Katsunori FUJIWARA - June 19, 2014, 3:43 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1403191279 -32400
#      Fri Jun 20 00:21:19 2014 +0900
# Branch stable
# Node ID ad57f7ad7245023c5ab598e9918c5308ecfb4727
# Parent  a20591a932b7a3420eb8f0c2cd7549514ea8d734
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.

Patch

diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py
--- a/mercurial/subrepo.py
+++ b/mercurial/subrepo.py
@@ -572,8 +572,10 @@  class hgsubrepo(abstractsubrepo):
         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):