summaryrefslogtreecommitdiff
path: root/networking/wget.c
diff options
context:
space:
mode:
authorDenys Vlasenko2012-06-13 17:31:07 +0200
committerDenys Vlasenko2012-06-13 17:31:07 +0200
commitbf146b861083e3170af05016982d50d297e3ace7 (patch)
treeafaabd8eb925a865f74ba26f057dd362c982079d /networking/wget.c
parentf5abc78579db1b2f0b8d8ed7353c621f4dc3d78d (diff)
downloadbusybox-bf146b861083e3170af05016982d50d297e3ace7.zip
busybox-bf146b861083e3170af05016982d50d297e3ace7.tar.gz
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/wget.c')
-rw-r--r--networking/wget.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/networking/wget.c b/networking/wget.c
index 8520fe2..013b878 100644
--- a/networking/wget.c
+++ b/networking/wget.c
@@ -350,6 +350,14 @@ static char *gethdr(FILE *fp)
return hdrval;
}
+static void reset_beg_range_to_zero(void)
+{
+ //bb_error_msg("restart failed");
+ G.beg_range = 0;
+ xlseek(G.output_fd, 0, SEEK_SET);
+ ftruncate(G.output_fd, 0);
+}
+
static FILE* prepare_ftp_session(FILE **dfpp, struct host_info *target, len_and_sockaddr *lsa)
{
FILE *sfp;
@@ -421,6 +429,8 @@ static FILE* prepare_ftp_session(FILE **dfpp, struct host_info *target, len_and_
sprintf(G.wget_buf, "REST %"OFF_FMT"u", G.beg_range);
if (ftpcmd(G.wget_buf, NULL, sfp) == 350)
G.content_len -= G.beg_range;
+ else
+ reset_beg_range_to_zero();
}
if (ftpcmd("RETR ", target->path, sfp) > 150)
@@ -744,6 +754,12 @@ However, in real world it was observed that some web servers
(e.g. Boa/0.94.14rc21) simply use code 204 when file size is zero.
*/
case 204:
+ if (G.beg_range != 0) {
+ /* "Range:..." was not honored by the server.
+ * Restart download from the beginning.
+ */
+ reset_beg_range_to_zero();
+ }
break;
case 300: /* redirection */
case 301: