* Fix portage.cache.template.database.__getitem__() to validate the _mtime_
authorZac Medico <zmedico@gentoo.org>
Sun, 1 Mar 2009 06:25:07 +0000 (06:25 -0000)
committerZac Medico <zmedico@gentoo.org>
Sun, 1 Mar 2009 06:25:07 +0000 (06:25 -0000)
  field and raise a CacheCorruption exception if necessary.
* Make _mtime_ and _eclasses_ validation code in portdbapi and mirror_cache()
  assume that these fields are the correct type (otherwise a CacheCorruption
  exeception should be raised earlier).
* Fix the sqlite module to implement _getitem() so that it properly inherits
  __getitem__() _mtime_ and _eclasses_ handling.

svn path=/main/trunk/; revision=12735

pym/portage/cache/sqlite.py
pym/portage/cache/template.py
pym/portage/cache/util.py
pym/portage/dbapi/porttree.py

index f6e8c103cf5ba0f3c6534c75706bfc8d53fe06a4..5a7bcf1f5d652fca4b2209e64fd8c3dfa8052f4b 100644 (file)
@@ -143,7 +143,7 @@ class database(fs_template.FsBased):
                if actual_synchronous!=synchronous:
                        raise cache_errors.InitializationError(self.__class__,"actual synchronous = "+actual_synchronous+" does does not match requested value of "+synchronous)
 
-       def __getitem__(self, cpv):
+       def _getitem(self, cpv):
                cursor = self._db_cursor
                cursor.execute("select * from %s where %s=%s" % \
                        (self._db_table["packages"]["table_name"],
@@ -169,10 +169,6 @@ class database(fs_template.FsBased):
                                d[k]=str(d[k]) # convert unicode strings to normal
                        except UnicodeEncodeError, e:
                                pass #writemsg("%s: %s\n" % (cpv, str(e)))
-               if "_eclasses_" in d:
-                       d["_eclasses_"] = reconstruct_eclasses(cpv, d["_eclasses_"])
-               else:
-                       d["_eclasses_"] = {}
                for x in self._known_keys:
                        d.setdefault(x,'')
                return d
index 35b9efeffbd976b7eaddb908433e8fb0126af4df..7fce8ef179e2b4c042e58d23922fc599ed277bb5 100644 (file)
@@ -40,6 +40,16 @@ class database(object):
                        d["_eclasses_"] = reconstruct_eclasses(cpv, d["_eclasses_"])
                elif "_eclasses_" not in d:
                        d["_eclasses_"] = {}
+               mtime = d.get('_mtime_')
+               if mtime is None:
+                       raise cache_errors.CacheCorruption(cpv,
+                               '_mtime_ field is missing')
+               try:
+                       mtime = long(mtime)
+               except ValueError:
+                       raise cache_errors.CacheCorruption(cpv,
+                               '_mtime_ conversion to long failed: %s' % (mtime,))
+               d['_mtime_'] = mtime
                return d
 
        def _getitem(self, cpv):
index 86f93440e8cc6c2e961f9d88397b9ddb605c0771..e152f50814e334c07644652722ee93eb85ae145c 100644 (file)
@@ -45,13 +45,10 @@ def mirror_cache(valid_nodes_iterable, src_cache, trg_cache, eclass_cache=None,
                except (KeyError, cache_errors.CacheError):
                        pass
                else:
-                       try:
-                               if long(trg["_mtime_"]) == long(entry["_mtime_"]) and \
-                                       eclass_cache.is_eclass_data_valid(trg["_eclasses_"]) and \
-                                       set(trg["_eclasses_"]) == set(entry["_eclasses_"]):
-                                       write_it = False
-                       except cache_errors.CacheError:
-                               pass
+                       if trg['_mtime_'] == entry['_mtime_'] and \
+                               eclass_cache.is_eclass_data_valid(trg['_eclasses_']) and \
+                               set(trg['_eclasses_']) == set(entry['_eclasses_']):
+                               write_it = False
 
                for d in (entry, trg):
                        if d is not None and d.get('EAPI') in ('', '0'):
index 5fcb50ce577b72b541e2b162cd698b83e8628301..bf05531c027c85b7a7e0b84d8bc95079629d7b91 100644 (file)
@@ -346,19 +346,6 @@ class portdbapi(dbapi):
                for auxdb in auxdbs:
                        try:
                                metadata = auxdb[cpv]
-                               eapi = metadata.get("EAPI","").strip()
-                               if not eapi:
-                                       eapi = "0"
-                               if eapi.startswith("-") and eapi_is_supported(eapi[1:]):
-                                       pass
-                               elif emtime != int(metadata.get("_mtime_", 0)):
-                                       pass
-                               elif len(metadata.get("_eclasses_", [])) > 0:
-                                       if self.eclassdb.is_eclass_data_valid(
-                                               metadata["_eclasses_"]):
-                                               doregen = False
-                               else:
-                                       doregen = False
                        except KeyError:
                                pass
                        except CacheError:
@@ -367,6 +354,15 @@ class portdbapi(dbapi):
                                                del auxdb[cpv]
                                        except KeyError:
                                                pass
+                       else:
+                               eapi = metadata.get('EAPI', '').strip()
+                               if not eapi:
+                                       eapi = '0'
+                               if not (eapi[:1] == '-' and eapi_is_supported(eapi[1:])) and \
+                                       emtime == metadata['_mtime_'] and \
+                                       self.eclassdb.is_eclass_data_valid(metadata['_eclasses_']):
+                                       doregen = False
+
                        if not doregen:
                                break