Inside the portdbapi constructor, handle repositories with the same repo_name
authorZac Medico <zmedico@gentoo.org>
Sun, 12 Apr 2009 02:55:17 +0000 (02:55 -0000)
committerZac Medico <zmedico@gentoo.org>
Sun, 12 Apr 2009 02:55:17 +0000 (02:55 -0000)
by discarding the ones that were encountered earlier.

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

pym/portage/dbapi/porttree.py

index 1bc08b8fa12911d2d3bf0e966631a6a27ba479f8..a7e074d45845337f58906909bd71ad155f01c602 100644 (file)
@@ -125,10 +125,6 @@ class portdbapi(dbapi):
                # this purpose because doebuild makes many changes to the config
                # instance that is passed in.
                self.doebuild_settings = config(clone=self.mysettings)
-
-               porttree_root = os.path.realpath(porttree_root)
-               self.porttree_root = porttree_root
-
                self.depcachedir = os.path.realpath(self.mysettings.depcachedir)
 
                if os.environ.get("SANDBOX_ON") == "1":
@@ -140,6 +136,46 @@ class portdbapi(dbapi):
                                os.environ["SANDBOX_WRITE"] = \
                                        ":".join(filter(None, sandbox_write))
 
+               porttrees = [os.path.realpath(porttree_root)]
+               porttrees.extend(os.path.realpath(x) for x in \
+                       self.mysettings.get('PORTDIR_OVERLAY', '').split())
+               treemap = {}
+               repository_map = {}
+               self.treemap = treemap
+               self._repository_map = repository_map
+               identically_named_paths = set()
+               for path in porttrees:
+                       if path in repository_map:
+                               continue
+                       repo_name_path = os.path.join(path, REPO_NAME_LOC)
+                       try:
+                               repo_name = open(repo_name_path, 'r').readline().strip()
+                       except EnvironmentError:
+                               # warn about missing repo_name at some other time, since we
+                               # don't want to see a warning every time the portage module is
+                               # imported.
+                               pass
+                       else:
+                               identically_named_path = treemap.get(repo_name)
+                               if identically_named_path is not None:
+                                       # The earlier one is discarded.
+                                       del repository_map[identically_named_path]
+                                       identically_named_paths.add(identically_named_path)
+                                       if identically_named_path == porttrees[0]:
+                                               # Found another repo with the same name as
+                                               # $PORTDIR, so update porttrees[0] to match.
+                                               porttrees[0] = path
+                               treemap[repo_name] = path
+                               repository_map[path] = repo_name
+
+               # Ensure that each repo_name is unique. Later paths override
+               # earlier ones that correspond to the same name.
+               porttrees = [x for x in porttrees if x not in identically_named_paths]
+
+               self.porttrees = porttrees
+               porttree_root = porttrees[0]
+               self.porttree_root = porttree_root
+
                self.eclassdb = eclass_cache.cache(porttree_root)
 
                # This is used as sanity check for aux_get(). If there is no
@@ -155,22 +191,6 @@ class portdbapi(dbapi):
                self.xcache = {}
                self.frozen = 0
 
-               self.porttrees = [self.porttree_root] + \
-                       [os.path.realpath(t) for t in self.mysettings["PORTDIR_OVERLAY"].split()]
-               self.treemap = {}
-               self._repository_map = {}
-               for path in self.porttrees:
-                       repo_name_path = os.path.join(path, REPO_NAME_LOC)
-                       try:
-                               repo_name = open(repo_name_path, 'r').readline().strip()
-                               self.treemap[repo_name] = path
-                               self._repository_map[path] = repo_name
-                       except (OSError,IOError):
-                               # warn about missing repo_name at some other time, since we
-                               # don't want to see a warning every time the portage module is
-                               # imported.
-                               pass
-
                self._repo_info = {}
                eclass_dbs = {porttree_root : self.eclassdb}
                local_repo_configs = self.mysettings._local_repo_configs