diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-09-27 15:07:23 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-09-27 15:07:23 +0000 |
commit | a36535b0676aab90b0411a85222c4f3c0eede406 (patch) | |
tree | 0ecd01d99e6d82a28bc0e03fabdef86aa17411e5 | |
parent | 6124c37135b2766d785471fe9b3eba9c1a233c66 (diff) | |
download | busybox-w32-a36535b0676aab90b0411a85222c4f3c0eede406.tar.gz busybox-w32-a36535b0676aab90b0411a85222c4f3c0eede406.tar.bz2 busybox-w32-a36535b0676aab90b0411a85222c4f3c0eede406.zip |
wget: -O FILE is allowed to overwrite existing file (compat)
-rw-r--r-- | networking/wget.c | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/networking/wget.c b/networking/wget.c index df1a45b2a..3f9954cf5 100644 --- a/networking/wget.c +++ b/networking/wget.c | |||
@@ -409,8 +409,8 @@ int wget_main(int argc, char **argv) | |||
409 | llist_t *headers_llist = NULL; | 409 | llist_t *headers_llist = NULL; |
410 | #endif | 410 | #endif |
411 | FILE *sfp = NULL; /* socket to web/ftp server */ | 411 | FILE *sfp = NULL; /* socket to web/ftp server */ |
412 | FILE *dfp = NULL; /* socket to ftp server (data) */ | 412 | FILE *dfp; /* socket to ftp server (data) */ |
413 | char *fname_out = NULL; /* where to direct output (-O) */ | 413 | char *fname_out; /* where to direct output (-O) */ |
414 | bool got_clen = 0; /* got content-length: from server */ | 414 | bool got_clen = 0; /* got content-length: from server */ |
415 | int output_fd = -1; | 415 | int output_fd = -1; |
416 | bool use_proxy = 1; /* Use proxies if env vars are set */ | 416 | bool use_proxy = 1; /* Use proxies if env vars are set */ |
@@ -496,7 +496,7 @@ int wget_main(int argc, char **argv) | |||
496 | } | 496 | } |
497 | 497 | ||
498 | /* Guess an output filename, if there was no -O FILE */ | 498 | /* Guess an output filename, if there was no -O FILE */ |
499 | if (!fname_out) { | 499 | if (!(opt & WGET_OPT_OUTNAME)) { |
500 | fname_out = bb_get_last_path_component_nostrip(target.path); | 500 | fname_out = bb_get_last_path_component_nostrip(target.path); |
501 | /* handle "wget http://kernel.org//" */ | 501 | /* handle "wget http://kernel.org//" */ |
502 | if (fname_out[0] == '/' || !fname_out[0]) | 502 | if (fname_out[0] == '/' || !fname_out[0]) |
@@ -504,6 +504,12 @@ int wget_main(int argc, char **argv) | |||
504 | /* -P DIR is considered only if there was no -O FILE */ | 504 | /* -P DIR is considered only if there was no -O FILE */ |
505 | if (dir_prefix) | 505 | if (dir_prefix) |
506 | fname_out = concat_path_file(dir_prefix, fname_out); | 506 | fname_out = concat_path_file(dir_prefix, fname_out); |
507 | } else { | ||
508 | if (LONE_DASH(fname_out)) { | ||
509 | /* -O - */ | ||
510 | output_fd = 1; | ||
511 | opt &= ~WGET_OPT_CONTINUE; | ||
512 | } | ||
507 | } | 513 | } |
508 | #if ENABLE_FEATURE_WGET_STATUSBAR | 514 | #if ENABLE_FEATURE_WGET_STATUSBAR |
509 | curfile = bb_get_last_path_component_nostrip(fname_out); | 515 | curfile = bb_get_last_path_component_nostrip(fname_out); |
@@ -514,10 +520,6 @@ int wget_main(int argc, char **argv) | |||
514 | bb_error_msg_and_die("cannot specify continue (-c) without a filename (-O)"); */ | 520 | bb_error_msg_and_die("cannot specify continue (-c) without a filename (-O)"); */ |
515 | 521 | ||
516 | /* Determine where to start transfer */ | 522 | /* Determine where to start transfer */ |
517 | if (LONE_DASH(fname_out)) { | ||
518 | output_fd = 1; | ||
519 | opt &= ~WGET_OPT_CONTINUE; | ||
520 | } | ||
521 | if (opt & WGET_OPT_CONTINUE) { | 523 | if (opt & WGET_OPT_CONTINUE) { |
522 | output_fd = open(fname_out, O_WRONLY); | 524 | output_fd = open(fname_out, O_WRONLY); |
523 | if (output_fd >= 0) { | 525 | if (output_fd >= 0) { |
@@ -744,9 +746,13 @@ int wget_main(int argc, char **argv) | |||
744 | */ | 746 | */ |
745 | 747 | ||
746 | /* Do it before progressmeter (want to have nice error message) */ | 748 | /* Do it before progressmeter (want to have nice error message) */ |
747 | if (output_fd < 0) | 749 | if (output_fd < 0) { |
748 | output_fd = xopen(fname_out, | 750 | int o_flags = O_WRONLY | O_CREAT | O_TRUNC | O_EXCL; |
749 | O_WRONLY|O_CREAT|O_EXCL|O_TRUNC); | 751 | /* compat with wget: -O FILE can overwrite */ |
752 | if (opt & WGET_OPT_OUTNAME) | ||
753 | o_flags = O_WRONLY | O_CREAT | O_TRUNC; | ||
754 | output_fd = xopen(fname_out, o_flags); | ||
755 | } | ||
750 | 756 | ||
751 | if (!(opt & WGET_OPT_QUIET)) | 757 | if (!(opt & WGET_OPT_QUIET)) |
752 | progressmeter(-1); | 758 | progressmeter(-1); |