summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2006-09-22 21:49:22 +0000
committerZac Medico <zmedico@gentoo.org>2006-09-22 21:49:22 +0000
commitc334dbe1e9e64fcb60d7a2721f4288be778c9793 (patch)
treea8d88a7e569ee8577d5aeb3a078fe9de09edd875
parent975e4544a340d267b6e00fc501891dfdc273e70d (diff)
downloadportage-c334dbe1e9e64fcb60d7a2721f4288be778c9793.tar.gz
portage-c334dbe1e9e64fcb60d7a2721f4288be778c9793.tar.bz2
portage-c334dbe1e9e64fcb60d7a2721f4288be778c9793.zip
Use finally: to ensure that the file is closed properly.
svn path=/main/trunk/; revision=4504
-rw-r--r--pym/cache/flat_hash.py17
1 files changed, 9 insertions, 8 deletions
diff --git a/pym/cache/flat_hash.py b/pym/cache/flat_hash.py
index db46b0878..90c785f34 100644
--- a/pym/cache/flat_hash.py
+++ b/pym/cache/flat_hash.py
@@ -22,16 +22,17 @@ class database(fs_template.FsBased):
def __getitem__(self, cpv):
fp = os.path.join(self.location, cpv)
- myf = None
try:
- myf = open(fp,"r")
- d = self._parse_data(myf, cpv)
- d["_mtime_"] = long(os.fstat(myf.fileno()).st_mtime)
- myf.close()
- return d
+ myf = None
+ try:
+ myf = open(fp,"r")
+ d = self._parse_data(myf, cpv)
+ d["_mtime_"] = long(os.fstat(myf.fileno()).st_mtime)
+ return d
+ finally:
+ if myf:
+ myf.close()
except (IOError, OSError), e:
- if myf:
- myf.close()
if e.errno != errno.ENOENT:
raise cache_errors.CacheCorruption(cpv, e)
raise KeyError(cpv)