Add sanity checks in fetch() and digestgen() to automatically detect and handle inval...
authorZac Medico <zmedico@gentoo.org>
Mon, 30 Jul 2007 05:13:31 +0000 (05:13 -0000)
committerZac Medico <zmedico@gentoo.org>
Mon, 30 Jul 2007 05:13:31 +0000 (05:13 -0000)
svn path=/main/branches/2.1.2.9/; revision=7485

pym/portage.py
pym/portage_manifest.py

index e0c2c0005531dd50fa32cdc99623fccb56a6d8a3..3f07785f89c2d4df65131dd9827c360f6407b6ad 100644 (file)
@@ -2532,7 +2532,16 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0, locks_in_subdir=".locks",
                                                if not os.access(myfile_path, os.R_OK):
                                                        writemsg("!!! Failed to adjust permissions:" + \
                                                                " %s\n" % str(e), noiselevel=-1)
-                                       if myfile not in mydigests:
+
+                                       # If the file is empty then it's obviously invalid. Remove
+                                       # the empty file and try to download if possible.
+                                       if mystat.st_size == 0:
+                                               if can_fetch:
+                                                       try:
+                                                               os.unlink(myfile_path)
+                                                       except EnvironmentError:
+                                                               pass
+                                       elif myfile not in mydigests:
                                                # We don't have a digest, but the file exists.  We must
                                                # assume that it is fully downloaded.
                                                continue
@@ -2656,6 +2665,17 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0, locks_in_subdir=".locks",
                                                                writemsg("!!! Failed to adjust permissions:" + \
                                                                        " %s\n" % str(e), noiselevel=-1)
 
+                                       # If the file is empty then it's obviously invalid.  Don't
+                                       # trust the return value from the fetcher.  Remove the
+                                       # empty file and try to download again.
+                                       try:
+                                               if os.stat(myfile_path).st_size == 0:
+                                                       os.unlink(myfile_path)
+                                                       fetched = 0
+                                                       continue
+                                       except EnvironmentError:
+                                               pass
+
                                        if mydigests!=None and mydigests.has_key(myfile):
                                                try:
                                                        mystat = os.stat(myfile_path)
@@ -2790,16 +2810,23 @@ def digestgen(myarchives, mysettings, overwrite=1, manifestonly=0, myportdb=None
                                continue
                        if required_hash_types.difference(myhashes):
                                missing_hashes.add(myfile)
+                               continue
+                       if myhashes["size"] == 0:
+                               missing_hashes.add(myfile)
                if missing_hashes:
                        missing_files = []
                        for myfile in missing_hashes:
                                try:
-                                       os.stat(os.path.join(mysettings["DISTDIR"], myfile))
+                                       st = os.stat(os.path.join(mysettings["DISTDIR"], myfile))
                                except OSError, e:
                                        if e.errno != errno.ENOENT:
                                                raise
                                        del e
                                        missing_files.append(myfile)
+                               else:
+                                       # If the file is empty then it's obviously invalid.
+                                       if st.st_size == 0:
+                                               missing_files.append(myfile)
                        if missing_files:
                                mytree = os.path.realpath(os.path.dirname(
                                        os.path.dirname(mysettings["O"])))
index 6645963dda219b58995437f996da3eb557c49926..ff2603fa8fdb7bc6f8290a71593b5edbe99795d8 100644 (file)
@@ -482,12 +482,12 @@ class Manifest(object):
                        except OSError:
                                pass
                        if f in distfilehashes and \
+                               not required_hash_types.difference(distfilehashes[f]) and \
                                ((assumeDistHashesSometimes and mystat is None) or \
                                (assumeDistHashesAlways and mystat is None) or \
                                (assumeDistHashesAlways and mystat is not None and \
                                len(distfilehashes[f]) == len(self.hashes) and \
-                               distfilehashes[f]["size"] == mystat.st_size)) and \
-                               not required_hash_types.difference(distfilehashes[f]):
+                               distfilehashes[f]["size"] == mystat.st_size)):
                                self.fhashdict["DIST"][f] = distfilehashes[f]
                        else:
                                try: