From: Zac Medico Date: Sat, 18 Feb 2012 02:41:27 +0000 (-0800) Subject: MtimeDB._load: explicitly close file X-Git-Tag: v2.2.0_alpha87~2 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=557134066e5a8e4a1b0522fe94d931a2688f98f7;p=portage.git MtimeDB._load: explicitly close file --- diff --git a/pym/portage/util/mtimedb.py b/pym/portage/util/mtimedb.py index 8079aa9ea..0a2716693 100644 --- a/pym/portage/util/mtimedb.py +++ b/pym/portage/util/mtimedb.py @@ -1,4 +1,4 @@ -# Copyright 2010-2011 Gentoo Foundation +# Copyright 2010-2012 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 __all__ = ['MtimeDB'] @@ -23,6 +23,7 @@ class MtimeDB(dict): self._load(filename) def _load(self, filename): + f = None try: f = open(_unicode_encode(filename), 'rb') mypickle = pickle.Unpickler(f) @@ -32,8 +33,6 @@ class MtimeDB(dict): # TODO: If py3k, override Unpickler.find_class(). pass d = mypickle.load() - f.close() - del f except (AttributeError, EOFError, EnvironmentError, ValueError, pickle.UnpicklingError) as e: if isinstance(e, EnvironmentError) and \ getattr(e, 'errno', None) in (errno.ENOENT, errno.EACCES): @@ -43,6 +42,9 @@ class MtimeDB(dict): (filename, str(e)), noiselevel=-1) del e d = {} + finally: + if f is not None: + f.close() if "old" in d: d["updates"] = d["old"]