Fix serialize_eclasses = False in cache template.
authorZac Medico <zmedico@gentoo.org>
Tue, 18 Oct 2011 05:26:27 +0000 (22:26 -0700)
committerZac Medico <zmedico@gentoo.org>
Tue, 18 Oct 2011 05:26:27 +0000 (22:26 -0700)
This fixes volatile cache validation that did not get fixed in commit
a63c163a50bf8a4e5ca8673cd8bebae29c36643a. Now all volatile cache
problems that have been introduced since commit
2ed1cb53cc4158af08c22d466b15b9a9a7767212 should be fixed.

pym/portage/cache/template.py
pym/portage/cache/volatile.py

index a76a5f59f6a498593b85c1a4d5af05ae7df101d3..515ba022b30150c901cbfb95dd251a8d5eb4b075 100644 (file)
@@ -64,24 +64,46 @@ class database(object):
                override this in derived classess"""
                raise NotImplementedError
 
+       @staticmethod
+       def _internal_eclasses(extern_ec_dict, chf_type, paths):
+               """
+               When serialize_eclasses is False, we have to convert an external
+               eclass dict containing hashed_path objects into an appropriate
+               internal dict containing values of chf_type (and eclass dirs
+               if store_eclass_paths is True).
+               """
+               if not extern_ec_dict:
+                       return extern_ec_dict
+               chf_getter = operator.attrgetter(chf_type)
+               if paths:
+                       intern_ec_dict = dict((k, (v.eclass_dir, chf_getter(v)))
+                               for k, v in extern_ec_dict.items())
+               else:
+                       intern_ec_dict = dict((k, chf_getter(v))
+                               for k, v in extern_ec_dict.items())
+               return intern_ec_dict
+
        def __setitem__(self, cpv, values):
                """set a cpv to values
                This shouldn't be overriden in derived classes since it handles the readonly checks"""
                if self.readonly:
                        raise cache_errors.ReadOnlyRestriction()
+               d = None
                if self.cleanse_keys:
                        d=ProtectedDict(values)
                        for k, v in list(d.items()):
                                if not v:
                                        del d[k]
-                       if self.serialize_eclasses and "_eclasses_" in values:
+               if "_eclasses_" in values:
+                       if d is None:
+                               d = ProtectedDict(values)
+                       if self.serialize_eclasses:
                                d["_eclasses_"] = serialize_eclasses(d["_eclasses_"],
                                        self.validation_chf, paths=self.store_eclass_paths)
-               elif self.serialize_eclasses and "_eclasses_" in values:
-                       d = ProtectedDict(values)
-                       d["_eclasses_"] = serialize_eclasses(d["_eclasses_"],
-                               self.validation_chf, paths=self.store_eclass_paths)
-               else:
+                       else:
+                               d["_eclasses_"] = self._internal_eclasses(d["_eclasses_"],
+                                       self.validation_chf, self.store_eclass_paths)
+               elif d is None:
                        d = values
                self._setitem(cpv, d)
                if not self.autocommits:
index a3c57f55f1fcff33d31d63b3e2fdd6df04d258cb..55167451be47b422f22ff47d88c3e3473d472563 100644 (file)
@@ -17,7 +17,7 @@ class database(template.database):
                self._data = {}
                self._delitem = self._data.__delitem__
 
-       def __setitem__(self, name, values):
+       def _setitem(self, name, values):
                self._data[name] = copy.deepcopy(values)
 
        def __getitem__(self, cpv):