Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/subrepo.py @ 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 |
comparison
equal
deleted
inserted
replaced
21886:b9e8fdc35daf | 21887:9aaffb22d7d7 |
---|---|
33 | 33 |
34 def _calcfilehash(filename): | 34 def _calcfilehash(filename): |
35 data = '' | 35 data = '' |
36 if os.path.exists(filename): | 36 if os.path.exists(filename): |
37 fd = open(filename, 'rb') | 37 fd = open(filename, 'rb') |
38 data = fd.read() | 38 try: |
39 fd.close() | 39 data = fd.read() |
40 finally: | |
41 fd.close() | |
40 return util.sha1(data).hexdigest() | 42 return util.sha1(data).hexdigest() |
41 | 43 |
42 class SubrepoAbort(error.Abort): | 44 class SubrepoAbort(error.Abort): |
43 """Exception class used to avoid handling a subrepo error more than once""" | 45 """Exception class used to avoid handling a subrepo error more than once""" |
44 def __init__(self, *args, **kw): | 46 def __init__(self, *args, **kw): |