Lines 2671-2676
Link Here
|
2671 |
return retval >> 8 |
2671 |
return retval >> 8 |
2672 |
return retval |
2672 |
return retval |
2673 |
|
2673 |
|
|
|
2674 |
def _checksum_failure_temp_file(distdir, basename): |
2675 |
""" |
2676 |
First try to find a duplicate temp file with the same checksum and return |
2677 |
that filename if available. Otherwise, use mkstemp to create a new unique |
2678 |
filename._checksum_failure_.$RANDOM, rename the given file, and return the |
2679 |
new filename. In any case, filename will be renamed or removed before this |
2680 |
function returns a temp filename. |
2681 |
""" |
2682 |
|
2683 |
filename = os.path.join(distdir, basename) |
2684 |
size = os.stat(filename).st_size |
2685 |
checksum = None |
2686 |
tempfile_re = re.compile(re.escape(basename) + r'\._checksum_failure_\..*') |
2687 |
for temp_filename in os.listdir(distdir): |
2688 |
if not tempfile_re.match(temp_filename): |
2689 |
continue |
2690 |
temp_filename = os.path.join(distdir, temp_filename) |
2691 |
try: |
2692 |
if size != os.stat(temp_filename).st_size: |
2693 |
continue |
2694 |
except OSError: |
2695 |
continue |
2696 |
try: |
2697 |
temp_checksum = portage_checksum.perform_md5(temp_filename) |
2698 |
except portage_exception.FileNotFound: |
2699 |
# Apparently the temp file disappeared. Let it go. |
2700 |
continue |
2701 |
if checksum is None: |
2702 |
checksum = portage_checksum.perform_md5(filename) |
2703 |
if checksum == temp_checksum: |
2704 |
os.unlink(filename) |
2705 |
return temp_filename |
2706 |
|
2707 |
from tempfile import mkstemp |
2708 |
fd, temp_filename = mkstemp("", basename + "._checksum_failure_.", distdir) |
2709 |
os.close(fd) |
2710 |
os.rename(filename, temp_filename) |
2711 |
return temp_filename |
2712 |
|
2674 |
def fetch(myuris, mysettings, listonly=0, fetchonly=0, locks_in_subdir=".locks",use_locks=1, try_mirrors=1): |
2713 |
def fetch(myuris, mysettings, listonly=0, fetchonly=0, locks_in_subdir=".locks",use_locks=1, try_mirrors=1): |
2675 |
"fetch files. Will use digest file if available." |
2714 |
"fetch files. Will use digest file if available." |
2676 |
|
2715 |
|
Lines 2685-2690
Link Here
|
2685 |
print ">>> \"mirror\" mode desired and \"mirror\" restriction found; skipping fetch." |
2724 |
print ">>> \"mirror\" mode desired and \"mirror\" restriction found; skipping fetch." |
2686 |
return 1 |
2725 |
return 1 |
2687 |
|
2726 |
|
|
|
2727 |
# Generally, downloading the same file repeatedly from |
2728 |
# every single available mirror is a waste of bandwidth |
2729 |
# and time, so there needs to be a cap. |
2730 |
checksum_failure_max_tries = 5 |
2731 |
checksum_failure_counts = {} |
2688 |
thirdpartymirrors = mysettings.thirdpartymirrors() |
2732 |
thirdpartymirrors = mysettings.thirdpartymirrors() |
2689 |
|
2733 |
|
2690 |
check_config_instance(mysettings) |
2734 |
check_config_instance(mysettings) |
Lines 2930-2941
Link Here
|
2930 |
if reason[0] == "Insufficient data for checksum verification": |
2975 |
if reason[0] == "Insufficient data for checksum verification": |
2931 |
return 0 |
2976 |
return 0 |
2932 |
if can_fetch and not restrict_fetch: |
2977 |
if can_fetch and not restrict_fetch: |
2933 |
from tempfile import mkstemp |
2978 |
temp_filename = \ |
2934 |
fd, temp_filename = mkstemp("", |
2979 |
_checksum_failure_temp_file( |
2935 |
myfile + "._checksum_failure_.", |
2980 |
mysettings["DISTDIR"], myfile) |
2936 |
mysettings["DISTDIR"]) |
|
|
2937 |
os.close(fd) |
2938 |
os.rename(myfile_path, temp_filename) |
2939 |
writemsg_stdout("Refetching... " + \ |
2981 |
writemsg_stdout("Refetching... " + \ |
2940 |
"File renamed to '%s'\n\n" % \ |
2982 |
"File renamed to '%s'\n\n" % \ |
2941 |
temp_filename, noiselevel=-1) |
2983 |
temp_filename, noiselevel=-1) |
Lines 3112-3127
Link Here
|
3112 |
(reason[1], reason[2]), noiselevel=-1) |
3154 |
(reason[1], reason[2]), noiselevel=-1) |
3113 |
if reason[0] == "Insufficient data for checksum verification": |
3155 |
if reason[0] == "Insufficient data for checksum verification": |
3114 |
return 0 |
3156 |
return 0 |
3115 |
from tempfile import mkstemp |
3157 |
temp_filename = \ |
3116 |
fd, temp_filename = mkstemp("", |
3158 |
_checksum_failure_temp_file( |
3117 |
myfile + "._checksum_failure_.", |
3159 |
mysettings["DISTDIR"], myfile) |
3118 |
mysettings["DISTDIR"]) |
|
|
3119 |
os.close(fd) |
3120 |
os.rename(myfile_path, temp_filename) |
3121 |
writemsg_stdout("Refetching... " + \ |
3160 |
writemsg_stdout("Refetching... " + \ |
3122 |
"File renamed to '%s'\n\n" % \ |
3161 |
"File renamed to '%s'\n\n" % \ |
3123 |
temp_filename, noiselevel=-1) |
3162 |
temp_filename, noiselevel=-1) |
3124 |
fetched=0 |
3163 |
fetched=0 |
|
|
3164 |
count = checksum_failure_counts.get(myfile) |
3165 |
if count is None: |
3166 |
count = 0 |
3167 |
count += 1 |
3168 |
if count >= checksum_failure_max_tries: |
3169 |
break |
3170 |
checksum_failure_counts[myfile] = count |
3125 |
else: |
3171 |
else: |
3126 |
eout = output.EOutput() |
3172 |
eout = output.EOutput() |
3127 |
eout.quiet = mysettings.get("PORTAGE_QUIET", None) == "1" |
3173 |
eout.quiet = mysettings.get("PORTAGE_QUIET", None) == "1" |