diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2012-06-17 19:52:25 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2012-06-17 19:52:25 +0200 |
commit | 6144124aac1d4a30ff81842ba1bb0e28373a71c8 (patch) | |
tree | f6ec5a1d47dd6cc90835a59bdc4518cea68600e7 /networking/wget.c | |
parent | c5b01016e622f01dfa9c8c542c0968fe37d4a5f2 (diff) | |
download | busybox-w32-6144124aac1d4a30ff81842ba1bb0e28373a71c8.tar.gz busybox-w32-6144124aac1d4a30ff81842ba1bb0e28373a71c8.tar.bz2 busybox-w32-6144124aac1d4a30ff81842ba1bb0e28373a71c8.zip |
wget: make -c _not_ truncate the file
function old new delta
retrieve_file_data 396 436 +40
reset_beg_range_to_zero 52 45 -7
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'networking/wget.c')
-rw-r--r-- | networking/wget.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/networking/wget.c b/networking/wget.c index 013b87801..5d5845019 100644 --- a/networking/wget.c +++ b/networking/wget.c | |||
@@ -352,10 +352,11 @@ static char *gethdr(FILE *fp) | |||
352 | 352 | ||
353 | static void reset_beg_range_to_zero(void) | 353 | static void reset_beg_range_to_zero(void) |
354 | { | 354 | { |
355 | //bb_error_msg("restart failed"); | 355 | bb_error_msg("restart failed"); |
356 | G.beg_range = 0; | 356 | G.beg_range = 0; |
357 | xlseek(G.output_fd, 0, SEEK_SET); | 357 | xlseek(G.output_fd, 0, SEEK_SET); |
358 | ftruncate(G.output_fd, 0); | 358 | /* Done at the end instead: */ |
359 | /* ftruncate(G.output_fd, 0); */ | ||
359 | } | 360 | } |
360 | 361 | ||
361 | static FILE* prepare_ftp_session(FILE **dfpp, struct host_info *target, len_and_sockaddr *lsa) | 362 | static FILE* prepare_ftp_session(FILE **dfpp, struct host_info *target, len_and_sockaddr *lsa) |
@@ -554,6 +555,17 @@ static void NOINLINE retrieve_file_data(FILE *dfp) | |||
554 | G.got_clen = 1; | 555 | G.got_clen = 1; |
555 | } | 556 | } |
556 | 557 | ||
558 | /* If -c failed, we restart from the beginning, | ||
559 | * but we do not truncate file then, we do it only now, at the end. | ||
560 | * This lets user to ^C if his 99% complete 10 GB file download | ||
561 | * failed to restart *without* losing the almost complete file. | ||
562 | */ | ||
563 | { | ||
564 | off_t pos = lseek(G.output_fd, 0, SEEK_CUR); | ||
565 | if (pos != (off_t)-1) | ||
566 | ftruncate(G.output_fd, pos); | ||
567 | } | ||
568 | |||
557 | /* Draw full bar and free its resources */ | 569 | /* Draw full bar and free its resources */ |
558 | G.chunked = 0; /* makes it show 100% even for chunked download */ | 570 | G.chunked = 0; /* makes it show 100% even for chunked download */ |
559 | G.got_clen = 1; /* makes it show 100% even for download of (formerly) unknown size */ | 571 | G.got_clen = 1; /* makes it show 100% even for download of (formerly) unknown size */ |