From 90766d70c76c562af20cb4554bb0dab38a1b0abf Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Sun, 1 Mar 2009 06:25:07 +0000 Subject: [PATCH] * Fix portage.cache.template.database.__getitem__() to validate the _mtime_ 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 | 6 +----- pym/portage/cache/template.py | 10 ++++++++++ pym/portage/cache/util.py | 11 ++++------- pym/portage/dbapi/porttree.py | 22 +++++++++------------- 4 files changed, 24 insertions(+), 25 deletions(-) diff --git a/pym/portage/cache/sqlite.py b/pym/portage/cache/sqlite.py index f6e8c103c..5a7bcf1f5 100644 --- a/pym/portage/cache/sqlite.py +++ b/pym/portage/cache/sqlite.py @@ -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 diff --git a/pym/portage/cache/template.py b/pym/portage/cache/template.py index 35b9efeff..7fce8ef17 100644 --- a/pym/portage/cache/template.py +++ b/pym/portage/cache/template.py @@ -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): diff --git a/pym/portage/cache/util.py b/pym/portage/cache/util.py index 86f93440e..e152f5081 100644 --- a/pym/portage/cache/util.py +++ b/pym/portage/cache/util.py @@ -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'): diff --git a/pym/portage/dbapi/porttree.py b/pym/portage/dbapi/porttree.py index 5fcb50ce5..bf05531c0 100644 --- a/pym/portage/dbapi/porttree.py +++ b/pym/portage/dbapi/porttree.py @@ -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 -- 2.26.2