When organizing remote binhost metadata into a cpv -> metadata map,
authorZac Medico <zmedico@gentoo.org>
Fri, 4 Jun 2010 17:16:05 +0000 (10:16 -0700)
committerZac Medico <zmedico@gentoo.org>
Fri, 4 Jun 2010 17:16:05 +0000 (10:16 -0700)
check for multiple packages with identical CPV values, and prefer
the package with latest BUILD_TIME value.

pym/portage/dbapi/bintree.py

index cc53d45a59c5f9d1e4769ba5e6bf330d84956023..d5e2feaf75e8b60695f76ada1e2e8469a4b80c36 100644 (file)
@@ -778,8 +778,32 @@ class binarytree(object):
                                        # file, but that's alright.
                        if pkgindex:
                                self._remotepkgs = {}
+
+                               # Organize remote package list as a cpv -> metadata map.
+                               # If multiple packages have identical CPV values, prefer
+                               # the package with latest BUILD_TIME value.
+                               remotepkgs = self._remotepkgs
                                for d in pkgindex.packages:
-                                       self._remotepkgs[d["CPV"]] = d
+                                       cpv = d["CPV"]
+
+                                       btime = d.get('BUILD_TIME', '')
+                                       try:
+                                               btime = int(btime)
+                                       except ValueError:
+                                               btime = None
+                                       if btime:
+                                               other_d = remotepkgs.get(cpv)
+                                               if other_d is not None:
+                                                       other_btime = other_d.get('BUILD_TIME', '')
+                                                       try:
+                                                               other_btime = int(other_btime)
+                                                       except ValueError:
+                                                               other_btime = None
+                                                       if other_btime and other_btime > btime:
+                                                               continue
+
+                                       remotepkgs[cpv] = d
+
                                self._remote_has_index = True
                                self._remote_base_uri = pkgindex.header.get("URI", base_url)
                                self.__remotepkgs = {}