From 557134066e5a8e4a1b0522fe94d931a2688f98f7 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Fri, 17 Feb 2012 18:41:27 -0800 Subject: MtimeDB._load: explicitly close file --- pym/portage/util/mtimedb.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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"] -- cgit v1.2.3-1-g7c22