Use finally: to ensure that the file is closed properly.
authorZac Medico <zmedico@gentoo.org>
Fri, 22 Sep 2006 21:49:22 +0000 (21:49 -0000)
committerZac Medico <zmedico@gentoo.org>
Fri, 22 Sep 2006 21:49:22 +0000 (21:49 -0000)
svn path=/main/trunk/; revision=4504

pym/cache/flat_hash.py

index db46b087897be63753d2e61b4c3045748861b1e8..90c785f3451c23b16043afcd2566be4a38831e71 100644 (file)
@@ -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)