summaryrefslogtreecommitdiffstats
path: root/pym/cache
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2006-09-22 21:17:19 +0000
committerZac Medico <zmedico@gentoo.org>2006-09-22 21:17:19 +0000
commit825444337b4a8d61b94eda8923851e31e6389bc1 (patch)
tree1a166728803a0adfe2c866e31e7646bbff4cb96c /pym/cache
parent2c0ef6c6164a9d10836e2d11940e8e7b5af6f0d5 (diff)
downloadportage-825444337b4a8d61b94eda8923851e31e6389bc1.tar.gz
portage-825444337b4a8d61b94eda8923851e31e6389bc1.tar.bz2
portage-825444337b4a8d61b94eda8923851e31e6389bc1.zip
Improve and simplify __getitem__ error handling.
svn path=/main/trunk/; revision=4502
Diffstat (limited to 'pym/cache')
-rw-r--r--pym/cache/flat_hash.py22
1 files changed, 8 insertions, 14 deletions
diff --git a/pym/cache/flat_hash.py b/pym/cache/flat_hash.py
index bf5140c10..db46b0878 100644
--- a/pym/cache/flat_hash.py
+++ b/pym/cache/flat_hash.py
@@ -6,7 +6,6 @@
from cache import fs_template
from cache import cache_errors
import errno, os, stat
-from cache.mappings import LazyLoad, ProtectedDict
from cache.template import reconstruct_eclasses
# store the current key order *here*.
class database(fs_template.FsBased):
@@ -23,24 +22,19 @@ class database(fs_template.FsBased):
def __getitem__(self, cpv):
fp = os.path.join(self.location, cpv)
- return self._pull(fp, cpv)
-
- def _pull(self, fp, cpv):
+ myf = None
try:
myf = open(fp,"r")
- except IOError:
- raise KeyError(cpv)
- except OSError, e:
- raise cache_errors.CacheCorruption(cpv, e)
- try:
d = self._parse_data(myf, cpv)
d["_mtime_"] = long(os.fstat(myf.fileno()).st_mtime)
- except (OSError, ValueError), e:
myf.close()
- raise cache_errors.CacheCorruption(cpv, e)
- myf.close()
- return d
-
+ return d
+ except (IOError, OSError), e:
+ if myf:
+ myf.close()
+ if e.errno != errno.ENOENT:
+ raise cache_errors.CacheCorruption(cpv, e)
+ raise KeyError(cpv)
def _parse_data(self, data, cpv):
d = dict(map(lambda x:x.rstrip().split("=", 1), data))