Use fstat to when retrieve cache timestamps and avoid a race.
authorZac Medico <zmedico@gentoo.org>
Fri, 22 Sep 2006 20:59:45 +0000 (20:59 -0000)
committerZac Medico <zmedico@gentoo.org>
Fri, 22 Sep 2006 20:59:45 +0000 (20:59 -0000)
svn path=/main/trunk/; revision=4501

pym/cache/flat_hash.py
pym/cache/metadata.py

index df8043c2d90b6d8f08af16842a50cac466183450..bf5140c100eb2f95bcfbf0a4fec918e44e7b24d4 100644 (file)
@@ -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
index 0d5402342ac2361155d0ef0d3d8d65126828ee31..00a7d4694ae17763206e4eea364e61511b94e751 100644 (file)
@@ -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 = {}