diff options
author | Zac Medico <zmedico@gentoo.org> | 2007-06-26 17:48:49 +0000 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2007-06-26 17:48:49 +0000 |
commit | 3b2ca22b58636f93560c45d036627fe337b080ea (patch) | |
tree | 024d02dd15929e961462dd462fd009a99dcd5587 | |
parent | 52badd48f9a7ff1cfbdb6beded1727341b52a20b (diff) | |
download | portage-3b2ca22b58636f93560c45d036627fe337b080ea.tar.gz portage-3b2ca22b58636f93560c45d036627fe337b080ea.tar.bz2 portage-3b2ca22b58636f93560c45d036627fe337b080ea.zip |
Add sanity checks in fetch() and digestgen() to automatically detect and handle invalid empty distfiles since some users have reported difficulty when trying to create digests.
svn path=/main/trunk/; revision=7039
-rw-r--r-- | pym/portage/__init__.py | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py index 2818ae9dd..3e56e8373 100644 --- a/pym/portage/__init__.py +++ b/pym/portage/__init__.py @@ -2700,7 +2700,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 @@ -2824,6 +2833,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) @@ -2962,12 +2982,16 @@ def digestgen(myarchives, mysettings, overwrite=1, manifestonly=0, myportdb=None 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"]))) |