summaryrefslogtreecommitdiffstats
path: root/pym/portage.py
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2007-06-26 17:50:33 +0000
committerZac Medico <zmedico@gentoo.org>2007-06-26 17:50:33 +0000
commit21426822fe5de4df5b1546fe2e8d8ecedfbdf282 (patch)
tree5a4b7355dbd42492acdc92c6fb86d06260ae4475 /pym/portage.py
parent7a64d1799c11bf3ca4e76a11e55b594bd91ecc0b (diff)
downloadportage-21426822fe5de4df5b1546fe2e8d8ecedfbdf282.tar.gz
portage-21426822fe5de4df5b1546fe2e8d8ecedfbdf282.tar.bz2
portage-21426822fe5de4df5b1546fe2e8d8ecedfbdf282.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. (trunk r7039)
svn path=/main/branches/2.1.2/; revision=7040
Diffstat (limited to 'pym/portage.py')
-rw-r--r--pym/portage.py28
1 files changed, 26 insertions, 2 deletions
diff --git a/pym/portage.py b/pym/portage.py
index 79bb3ca0b..9f5818b95 100644
--- a/pym/portage.py
+++ b/pym/portage.py
@@ -2590,7 +2590,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
@@ -2714,6 +2723,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)
@@ -2852,12 +2872,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"])))