diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2012-06-13 17:31:07 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2012-06-13 17:31:07 +0200 |
commit | bf146b861083e3170af05016982d50d297e3ace7 (patch) | |
tree | afaabd8eb925a865f74ba26f057dd362c982079d /networking | |
parent | f5abc78579db1b2f0b8d8ed7353c621f4dc3d78d (diff) | |
download | busybox-w32-bf146b861083e3170af05016982d50d297e3ace7.tar.gz busybox-w32-bf146b861083e3170af05016982d50d297e3ace7.tar.bz2 busybox-w32-bf146b861083e3170af05016982d50d297e3ace7.zip |
wget: correctly handle failure to -c (continue)
function old new delta
reset_beg_range_to_zero - 52 +52
wget_main 2168 2189 +21
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'networking')
-rw-r--r-- | networking/wget.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/networking/wget.c b/networking/wget.c index 8520fe2b9..013b87801 100644 --- a/networking/wget.c +++ b/networking/wget.c | |||
@@ -350,6 +350,14 @@ static char *gethdr(FILE *fp) | |||
350 | return hdrval; | 350 | return hdrval; |
351 | } | 351 | } |
352 | 352 | ||
353 | static void reset_beg_range_to_zero(void) | ||
354 | { | ||
355 | //bb_error_msg("restart failed"); | ||
356 | G.beg_range = 0; | ||
357 | xlseek(G.output_fd, 0, SEEK_SET); | ||
358 | ftruncate(G.output_fd, 0); | ||
359 | } | ||
360 | |||
353 | static FILE* prepare_ftp_session(FILE **dfpp, struct host_info *target, len_and_sockaddr *lsa) | 361 | static FILE* prepare_ftp_session(FILE **dfpp, struct host_info *target, len_and_sockaddr *lsa) |
354 | { | 362 | { |
355 | FILE *sfp; | 363 | FILE *sfp; |
@@ -421,6 +429,8 @@ static FILE* prepare_ftp_session(FILE **dfpp, struct host_info *target, len_and_ | |||
421 | sprintf(G.wget_buf, "REST %"OFF_FMT"u", G.beg_range); | 429 | sprintf(G.wget_buf, "REST %"OFF_FMT"u", G.beg_range); |
422 | if (ftpcmd(G.wget_buf, NULL, sfp) == 350) | 430 | if (ftpcmd(G.wget_buf, NULL, sfp) == 350) |
423 | G.content_len -= G.beg_range; | 431 | G.content_len -= G.beg_range; |
432 | else | ||
433 | reset_beg_range_to_zero(); | ||
424 | } | 434 | } |
425 | 435 | ||
426 | if (ftpcmd("RETR ", target->path, sfp) > 150) | 436 | if (ftpcmd("RETR ", target->path, sfp) > 150) |
@@ -744,6 +754,12 @@ However, in real world it was observed that some web servers | |||
744 | (e.g. Boa/0.94.14rc21) simply use code 204 when file size is zero. | 754 | (e.g. Boa/0.94.14rc21) simply use code 204 when file size is zero. |
745 | */ | 755 | */ |
746 | case 204: | 756 | case 204: |
757 | if (G.beg_range != 0) { | ||
758 | /* "Range:..." was not honored by the server. | ||
759 | * Restart download from the beginning. | ||
760 | */ | ||
761 | reset_beg_range_to_zero(); | ||
762 | } | ||
747 | break; | 763 | break; |
748 | case 300: /* redirection */ | 764 | case 300: /* redirection */ |
749 | case 301: | 765 | case 301: |