From 2c0ef6c6164a9d10836e2d11940e8e7b5af6f0d5 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Fri, 22 Sep 2006 20:59:45 +0000 Subject: [PATCH] Use fstat to when retrieve cache timestamps and avoid a race. svn path=/main/trunk/; revision=4501 --- pym/cache/flat_hash.py | 16 +++------------- pym/cache/metadata.py | 4 ++-- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/pym/cache/flat_hash.py b/pym/cache/flat_hash.py index df8043c2d..bf5140c10 100644 --- a/pym/cache/flat_hash.py +++ b/pym/cache/flat_hash.py @@ -23,16 +23,7 @@ class database(fs_template.FsBased): def __getitem__(self, cpv): fp = os.path.join(self.location, cpv) - try: - def curry(*args): - def callit(*args2): - return args[0](*args[1:]+args2) - return callit - return ProtectedDict(LazyLoad(curry(self._pull, fp, cpv), - initial_items=[("_mtime_", long(os.stat(fp).st_mtime))])) - except OSError: - raise KeyError(cpv) - return self._getitem(cpv) + return self._pull(fp, cpv) def _pull(self, fp, cpv): try: @@ -43,6 +34,7 @@ class database(fs_template.FsBased): 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) @@ -50,10 +42,8 @@ class database(fs_template.FsBased): return d - def _parse_data(self, data, cpv, mtime=0): + def _parse_data(self, data, cpv): d = dict(map(lambda x:x.rstrip().split("=", 1), data)) - if mtime != 0: - d["_mtime_"] = long(mtime) if "_eclasses_" in d: d["_eclasses_"] = reconstruct_eclasses(cpv, d["_eclasses_"]) return d diff --git a/pym/cache/metadata.py b/pym/cache/metadata.py index 0d5402342..00a7d4694 100644 --- a/pym/cache/metadata.py +++ b/pym/cache/metadata.py @@ -32,11 +32,11 @@ class database(flat_hash.database): return flat_hash.database.__getitem__(self, cpv) - def _parse_data(self, data, mtime): + def _parse_data(self, data, cpv): # easy attempt first. data = list(data) if len(data) != magic_line_count: - d = flat_hash.database._parse_data(self, data, mtime) + d = flat_hash.database._parse_data(self, data) else: # this one's interesting. d = {} -- 2.26.2