Make config.load_infodir() more fault tolerant for cases like bug
authorZac Medico <zmedico@gentoo.org>
Mon, 3 Dec 2007 19:58:16 +0000 (19:58 -0000)
committerZac Medico <zmedico@gentoo.org>
Mon, 3 Dec 2007 19:58:16 +0000 (19:58 -0000)
#201082.

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

pym/portage/__init__.py

index 0fdc5a8fba6b4391b63c79f330bba8b37900cf82..334736e5ecc7d2a4b3f2d387b9e65813dc8aa5f8 100644 (file)
@@ -1770,6 +1770,7 @@ class config(object):
 
        def load_infodir(self,infodir):
                self.modifying()
+               backup_pkg_metadata = dict(self.configdict["pkg"].iteritems())
                if "pkg" in self.configdict:
                        self.configdict["pkg"].clear()
                else:
@@ -1777,6 +1778,8 @@ class config(object):
                                noiselevel=-1)
                        sys.exit(17)
 
+               retval = 0
+               category_corrupt = False
                if os.path.exists(infodir):
                        if os.path.exists(infodir+"/environment"):
                                self.configdict["pkg"]["PORT_ENV_FILE"] = infodir+"/environment"
@@ -1809,17 +1812,25 @@ class config(object):
                                                # strange errors later on, so we'll validate it and
                                                # print a warning if necessary.
                                                if filename == "CATEGORY":
-                                                       matchobj = re.match("[-a-zA-Z0-9_.+]+", mydata)
-                                                       if not matchobj or matchobj.start() != 0 or \
-                                                               matchobj.end() != len(mydata):
+                                                       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
-                       return 1
-               return 0
+                       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)
+                       self.configdict["pkg"].update(backup_pkg_metadata)
+                       retval = 0
+               return retval
 
        def setcpv(self, mycpv, use_cache=1, mydb=None):
                """