aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Lewis <martin.lewis.x84@gmail.com>2018-12-26 16:28:45 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2019-01-04 18:17:09 +0100
commit64f35361f42946e6e19bcbaa5a8be7b58a159c42 (patch)
treed56da92219b0e238c5a6ea94fdc48350947a87ad
parente05ec6ed3ecc00258e2ac7a897e640760ecf82c6 (diff)
downloadbusybox-w32-64f35361f42946e6e19bcbaa5a8be7b58a159c42.tar.gz
busybox-w32-64f35361f42946e6e19bcbaa5a8be7b58a159c42.tar.bz2
busybox-w32-64f35361f42946e6e19bcbaa5a8be7b58a159c42.zip
wget: add -o flag
function old new delta wget_main 2348 2412 +64 packed_usage 33062 33093 +31 static.wget_longopts 252 266 +14 progress_meter 158 159 +1 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 4/0 up/down: 110/0) Total: 110 bytes Signed-off-by: Martin Lewis <martin.lewis.x84@gmail.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--networking/wget.c52
1 files changed, 37 insertions, 15 deletions
diff --git a/networking/wget.c b/networking/wget.c
index 30683dfc0..da629ccb9 100644
--- a/networking/wget.c
+++ b/networking/wget.c
@@ -123,14 +123,14 @@
123//usage:#define wget_trivial_usage 123//usage:#define wget_trivial_usage
124//usage: IF_FEATURE_WGET_LONG_OPTIONS( 124//usage: IF_FEATURE_WGET_LONG_OPTIONS(
125//usage: "[-c|--continue] [--spider] [-q|--quiet] [-O|--output-document FILE]\n" 125//usage: "[-c|--continue] [--spider] [-q|--quiet] [-O|--output-document FILE]\n"
126//usage: " [--header 'header: value'] [-Y|--proxy on/off] [-P DIR]\n" 126//usage: " [-o|--output-file FILE] [--header 'header: value'] [-Y|--proxy on/off]\n"
127/* Since we ignore these opts, we don't show them in --help */ 127/* Since we ignore these opts, we don't show them in --help */
128/* //usage: " [--no-check-certificate] [--no-cache] [--passive-ftp] [-t TRIES]" */ 128/* //usage: " [--no-check-certificate] [--no-cache] [--passive-ftp] [-t TRIES]" */
129/* //usage: " [-nv] [-nc] [-nH] [-np]" */ 129/* //usage: " [-nv] [-nc] [-nH] [-np]" */
130//usage: " [-S|--server-response] [-U|--user-agent AGENT]" IF_FEATURE_WGET_TIMEOUT(" [-T SEC]") " URL..." 130//usage: " [-P DIR] [-S|--server-response] [-U|--user-agent AGENT]" IF_FEATURE_WGET_TIMEOUT(" [-T SEC]") " URL..."
131//usage: ) 131//usage: )
132//usage: IF_NOT_FEATURE_WGET_LONG_OPTIONS( 132//usage: IF_NOT_FEATURE_WGET_LONG_OPTIONS(
133//usage: "[-cq] [-O FILE] [-Y on/off] [-P DIR] [-S] [-U AGENT]" 133//usage: "[-cq] [-O FILE] [-o FILE] [-Y on/off] [-P DIR] [-S] [-U AGENT]"
134//usage: IF_FEATURE_WGET_TIMEOUT(" [-T SEC]") " URL..." 134//usage: IF_FEATURE_WGET_TIMEOUT(" [-T SEC]") " URL..."
135//usage: ) 135//usage: )
136//usage:#define wget_full_usage "\n\n" 136//usage:#define wget_full_usage "\n\n"
@@ -147,6 +147,7 @@
147//usage: "\n -T SEC Network read timeout is SEC seconds" 147//usage: "\n -T SEC Network read timeout is SEC seconds"
148//usage: ) 148//usage: )
149//usage: "\n -O FILE Save to FILE ('-' for stdout)" 149//usage: "\n -O FILE Save to FILE ('-' for stdout)"
150//usage: "\n -o FILE Log messages to FILE"
150//usage: "\n -U STR Use STR for User-Agent header" 151//usage: "\n -U STR Use STR for User-Agent header"
151//usage: "\n -Y on/off Use proxy" 152//usage: "\n -Y on/off Use proxy"
152 153
@@ -231,9 +232,11 @@ struct globals {
231 unsigned char user_headers; /* Headers mentioned by the user */ 232 unsigned char user_headers; /* Headers mentioned by the user */
232#endif 233#endif
233 char *fname_out; /* where to direct output (-O) */ 234 char *fname_out; /* where to direct output (-O) */
235 char *fname_log; /* where to direct log (-o) */
234 const char *proxy_flag; /* Use proxies if env vars are set */ 236 const char *proxy_flag; /* Use proxies if env vars are set */
235 const char *user_agent; /* "User-Agent" header field */ 237 const char *user_agent; /* "User-Agent" header field */
236 int output_fd; 238 int output_fd;
239 int log_fd;
237 int o_flags; 240 int o_flags;
238#if ENABLE_FEATURE_WGET_TIMEOUT 241#if ENABLE_FEATURE_WGET_TIMEOUT
239 unsigned timeout_seconds; 242 unsigned timeout_seconds;
@@ -262,16 +265,17 @@ enum {
262 WGET_OPT_QUIET = (1 << 1), 265 WGET_OPT_QUIET = (1 << 1),
263 WGET_OPT_SERVER_RESPONSE = (1 << 2), 266 WGET_OPT_SERVER_RESPONSE = (1 << 2),
264 WGET_OPT_OUTNAME = (1 << 3), 267 WGET_OPT_OUTNAME = (1 << 3),
265 WGET_OPT_PREFIX = (1 << 4), 268 WGET_OPT_LOGNAME = (1 << 4),
266 WGET_OPT_PROXY = (1 << 5), 269 WGET_OPT_PREFIX = (1 << 5),
267 WGET_OPT_USER_AGENT = (1 << 6), 270 WGET_OPT_PROXY = (1 << 6),
268 WGET_OPT_NETWORK_READ_TIMEOUT = (1 << 7), 271 WGET_OPT_USER_AGENT = (1 << 7),
269 WGET_OPT_RETRIES = (1 << 8), 272 WGET_OPT_NETWORK_READ_TIMEOUT = (1 << 8),
270 WGET_OPT_nsomething = (1 << 9), 273 WGET_OPT_RETRIES = (1 << 9),
271 WGET_OPT_HEADER = (1 << 10) * ENABLE_FEATURE_WGET_LONG_OPTIONS, 274 WGET_OPT_nsomething = (1 << 10),
272 WGET_OPT_POST_DATA = (1 << 11) * ENABLE_FEATURE_WGET_LONG_OPTIONS, 275 WGET_OPT_HEADER = (1 << 11) * ENABLE_FEATURE_WGET_LONG_OPTIONS,
273 WGET_OPT_SPIDER = (1 << 12) * ENABLE_FEATURE_WGET_LONG_OPTIONS, 276 WGET_OPT_POST_DATA = (1 << 12) * ENABLE_FEATURE_WGET_LONG_OPTIONS,
274 WGET_OPT_NO_CHECK_CERT = (1 << 13) * ENABLE_FEATURE_WGET_LONG_OPTIONS, 277 WGET_OPT_SPIDER = (1 << 13) * ENABLE_FEATURE_WGET_LONG_OPTIONS,
278 WGET_OPT_NO_CHECK_CERT = (1 << 14) * ENABLE_FEATURE_WGET_LONG_OPTIONS,
275}; 279};
276 280
277enum { 281enum {
@@ -287,6 +291,10 @@ static void progress_meter(int flag)
287 if (option_mask32 & WGET_OPT_QUIET) 291 if (option_mask32 & WGET_OPT_QUIET)
288 return; 292 return;
289 293
294 /* Don't save progress to log file */
295 if (G.log_fd >= 0)
296 return;
297
290 if (flag == PROGRESS_START) 298 if (flag == PROGRESS_START)
291 bb_progress_init(&G.pmt, G.curfile); 299 bb_progress_init(&G.pmt, G.curfile);
292 300
@@ -1401,6 +1409,7 @@ int wget_main(int argc UNUSED_PARAM, char **argv)
1401 "quiet\0" No_argument "q" 1409 "quiet\0" No_argument "q"
1402 "server-response\0" No_argument "S" 1410 "server-response\0" No_argument "S"
1403 "output-document\0" Required_argument "O" 1411 "output-document\0" Required_argument "O"
1412 "output-file\0" Required_argument "o"
1404 "directory-prefix\0" Required_argument "P" 1413 "directory-prefix\0" Required_argument "P"
1405 "proxy\0" Required_argument "Y" 1414 "proxy\0" Required_argument "Y"
1406 "user-agent\0" Required_argument "U" 1415 "user-agent\0" Required_argument "U"
@@ -1444,7 +1453,7 @@ IF_DESKTOP( "no-parent\0" No_argument "\xf0")
1444#if ENABLE_FEATURE_WGET_LONG_OPTIONS 1453#if ENABLE_FEATURE_WGET_LONG_OPTIONS
1445#endif 1454#endif
1446 GETOPT32(argv, "^" 1455 GETOPT32(argv, "^"
1447 "cqSO:P:Y:U:T:+" 1456 "cqSO:o:P:Y:U:T:+"
1448 /*ignored:*/ "t:" 1457 /*ignored:*/ "t:"
1449 /*ignored:*/ "n::" 1458 /*ignored:*/ "n::"
1450 /* wget has exactly four -n<letter> opts, all of which we can ignore: 1459 /* wget has exactly four -n<letter> opts, all of which we can ignore:
@@ -1459,7 +1468,7 @@ IF_DESKTOP( "no-parent\0" No_argument "\xf0")
1459 "-1" /* at least one URL */ 1468 "-1" /* at least one URL */
1460 IF_FEATURE_WGET_LONG_OPTIONS(":\xff::") /* --header is a list */ 1469 IF_FEATURE_WGET_LONG_OPTIONS(":\xff::") /* --header is a list */
1461 LONGOPTS 1470 LONGOPTS
1462 , &G.fname_out, &G.dir_prefix, 1471 , &G.fname_out, &G.fname_log, &G.dir_prefix,
1463 &G.proxy_flag, &G.user_agent, 1472 &G.proxy_flag, &G.user_agent,
1464 IF_FEATURE_WGET_TIMEOUT(&G.timeout_seconds) IF_NOT_FEATURE_WGET_TIMEOUT(NULL), 1473 IF_FEATURE_WGET_TIMEOUT(&G.timeout_seconds) IF_NOT_FEATURE_WGET_TIMEOUT(NULL),
1465 NULL, /* -t RETRIES */ 1474 NULL, /* -t RETRIES */
@@ -1521,12 +1530,25 @@ IF_DESKTOP( "no-parent\0" No_argument "\xf0")
1521 G.o_flags = O_WRONLY | O_CREAT | O_TRUNC; 1530 G.o_flags = O_WRONLY | O_CREAT | O_TRUNC;
1522 } 1531 }
1523 1532
1533 G.log_fd = -1;
1534 if (G.fname_log) { /* -o FILE ? */
1535 if (!LONE_DASH(G.fname_log)) { /* not -o - ? */
1536 /* compat with wget: -o FILE can overwrite */
1537 G.log_fd = xopen(G.fname_log, O_WRONLY | O_CREAT | O_TRUNC);
1538 /* Redirect only stderr to log file, so -O - will work */
1539 xdup2(G.log_fd, STDERR_FILENO);
1540 }
1541 }
1542
1524 while (*argv) 1543 while (*argv)
1525 download_one_url(*argv++); 1544 download_one_url(*argv++);
1526 1545
1527 if (G.output_fd >= 0) 1546 if (G.output_fd >= 0)
1528 xclose(G.output_fd); 1547 xclose(G.output_fd);
1529 1548
1549 if (G.log_fd >= 0)
1550 xclose(G.log_fd);
1551
1530#if ENABLE_FEATURE_CLEAN_UP && ENABLE_FEATURE_WGET_LONG_OPTIONS 1552#if ENABLE_FEATURE_CLEAN_UP && ENABLE_FEATURE_WGET_LONG_OPTIONS
1531 free(G.extra_headers); 1553 free(G.extra_headers);
1532#endif 1554#endif