* Don't load the CATEGORY in config.load_infodir() since this value is
authorZac Medico <zmedico@gentoo.org>
Mon, 3 Dec 2007 21:46:01 +0000 (21:46 -0000)
committerZac Medico <zmedico@gentoo.org>
Mon, 3 Dec 2007 21:46:01 +0000 (21:46 -0000)
  critical for doebuild() operation and we already know the category.
* Always call config.setcpv() prior to config.load_infodir() so that
  the CATEGORY is always known.

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

pym/portage/__init__.py
pym/portage/dbapi/vartree.py

index 334736e5ecc7d2a4b3f2d387b9e65813dc8aa5f8..c4399f6e4c7bd49ce653fb05379e5d32821f3b7c 100644 (file)
@@ -1771,16 +1771,18 @@ class config(object):
        def load_infodir(self,infodir):
                self.modifying()
                backup_pkg_metadata = dict(self.configdict["pkg"].iteritems())
-               if "pkg" in self.configdict:
+               if "pkg" in self.configdict and \
+                       "CATEGORY" in self.configdict["pkg"]:
                        self.configdict["pkg"].clear()
+                       self.configdict["pkg"]["CATEGORY"] = \
+                               backup_pkg_metadata["CATEGORY"]
                else:
-                       writemsg("No pkg setup for settings instance?\n",
-                               noiselevel=-1)
-                       sys.exit(17)
+                       raise portage.exception.PortageException(
+                               "No pkg setup for settings instance?")
 
                retval = 0
-               category_corrupt = False
-               if os.path.exists(infodir):
+               found_category_file = False
+               if os.path.isdir(infodir):
                        if os.path.exists(infodir+"/environment"):
                                self.configdict["pkg"]["PORT_ENV_FILE"] = infodir+"/environment"
 
@@ -1791,6 +1793,9 @@ class config(object):
                                        # FEATURES from the build host shouldn't be interpreted as
                                        # FEATURES on the client system.
                                        continue
+                               if filename == "CATEGORY":
+                                       found_category_file = True
+                                       continue
                                if myre.match(filename):
                                        try:
                                                file_path = os.path.join(infodir, filename)
@@ -1807,29 +1812,22 @@ class config(object):
                                                        else:
                                                                self.configdict["pkg"][filename] = mydata
                                                                self.configdict["env"][filename] = mydata
-                                               # CATEGORY is important because it's used in doebuild
-                                               # to infer the cpv.  If it's corrupted, it leads to
-                                               # strange errors later on, so we'll validate it and
-                                               # print a warning if necessary.
-                                               if filename == "CATEGORY":
-                                                       matchobj = re.match(r'^[-\w_.+]+', mydata)
-                                                       if not matchobj:
-                                                               writemsg("!!! CATEGORY file is corrupt: %s\n" % \
-                                                                       os.path.join(infodir, filename), noiselevel=-1)
-                                                               self.configdict["pkg"].pop(filename, None)
-                                                               self.configdict["env"].pop(filename, None)
-                                                               category_corrupt = True
                                        except (OSError, IOError):
                                                writemsg("!!! Unable to read file: %s\n" % infodir+"/"+filename,
                                                        noiselevel=-1)
                                                pass
                        retval = 1
-               if "CATEGORY" not in self.configdict["pkg"]:
-                       if not category_corrupt:
-                               writemsg("!!! CATEGORY file is missing: %s\n" % \
-                                       os.path.join(infodir, "CATEGORY"), noiselevel=-1)
+
+               # Missing or corrupt CATEGORY will cause problems for
+               # doebuild(), which uses it to infer the cpv. We already
+               # know the category, so there's no need to trust this
+               # file. Show a warning if the file is missing though,
+               # because it's required (especially for binary packages).
+               if not found_category_file:
+                       writemsg("!!! CATEGORY file is missing: %s\n" % \
+                               os.path.join(infodir, "CATEGORY"), noiselevel=-1)
                        self.configdict["pkg"].update(backup_pkg_metadata)
-                       retval = 0
+               retval = 0
                return retval
 
        def setcpv(self, mycpv, use_cache=1, mydb=None):
@@ -5771,6 +5769,7 @@ def pkgmerge(mytbz2, myroot, mysettings, mydbapi=None, vartree=None, prev_mtimes
                                gid=portage_gid, mode=0755)
                writemsg_stdout(">>> Extracting info\n")
                xptbz2.unpackinfo(infloc)
+               mysettings.setcpv(mycat + "/" + mypkg, mydb=mydbapi)
                mysettings.load_infodir(infloc)
                # Store the md5sum in the vdb.
                fp = open(os.path.join(infloc, "BINPKGMD5"), "w")
index 54b8d135e0d1fb0f6f1d09177bac657861567e98..4974a04af9f1ee0f2272dd3efe90608a910e3580 100644 (file)
@@ -1083,6 +1083,7 @@ class dblink(object):
                                        write_atomic(os.path.join(self.dbdir, "PF"), self.pkg+"\n")
                                break
 
+               self.settings.setcpv(self.mycpv, mydb=self.vartree.dbapi)
                self.settings.load_infodir(self.dbdir)
                if myebuildpath:
                        try: