diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2020-12-08 19:06:28 +0100 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2020-12-08 19:06:28 +0100 |
| commit | e7d853b4eb080dd8ea6433d010378e119e5a4cb3 (patch) | |
| tree | 763b97e9588504b5e25819d208b47c68f0029742 | |
| parent | abaee4aada7c91da6a43a83e9a73f98916a803a4 (diff) | |
| download | busybox-w32-e7d853b4eb080dd8ea6433d010378e119e5a4cb3.tar.gz busybox-w32-e7d853b4eb080dd8ea6433d010378e119e5a4cb3.tar.bz2 busybox-w32-e7d853b4eb080dd8ea6433d010378e119e5a4cb3.zip | |
wget: do not ftruncate if -O- is used, closes 13351
function old new delta
wget_main 2558 2571 +13
retrieve_file_data 612 621 +9
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 22/0) Total: 22 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| -rw-r--r-- | networking/wget.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/networking/wget.c b/networking/wget.c index ea60c18b2..ff0df4ca0 100644 --- a/networking/wget.c +++ b/networking/wget.c | |||
| @@ -287,6 +287,8 @@ enum { | |||
| 287 | WGET_OPT_POST_DATA = (1 << 12) * ENABLE_FEATURE_WGET_LONG_OPTIONS, | 287 | WGET_OPT_POST_DATA = (1 << 12) * ENABLE_FEATURE_WGET_LONG_OPTIONS, |
| 288 | WGET_OPT_SPIDER = (1 << 13) * ENABLE_FEATURE_WGET_LONG_OPTIONS, | 288 | WGET_OPT_SPIDER = (1 << 13) * ENABLE_FEATURE_WGET_LONG_OPTIONS, |
| 289 | WGET_OPT_NO_CHECK_CERT = (1 << 14) * ENABLE_FEATURE_WGET_LONG_OPTIONS, | 289 | WGET_OPT_NO_CHECK_CERT = (1 << 14) * ENABLE_FEATURE_WGET_LONG_OPTIONS, |
| 290 | /* hijack this bit for other than opts purposes: */ | ||
| 291 | WGET_NO_FTRUNCATE = (1 << 31) | ||
| 290 | }; | 292 | }; |
| 291 | 293 | ||
| 292 | enum { | 294 | enum { |
| @@ -1052,8 +1054,13 @@ static void NOINLINE retrieve_file_data(FILE *dfp) | |||
| 1052 | */ | 1054 | */ |
| 1053 | { | 1055 | { |
| 1054 | off_t pos = lseek(G.output_fd, 0, SEEK_CUR); | 1056 | off_t pos = lseek(G.output_fd, 0, SEEK_CUR); |
| 1055 | if (pos != (off_t)-1) | 1057 | if (pos != (off_t)-1) { |
| 1056 | ftruncate(G.output_fd, pos); | 1058 | /* do not truncate if -O- is in use, a user complained about |
| 1059 | * "wget -qO- 'http://example.com/empty' >>FILE" truncating FILE. | ||
| 1060 | */ | ||
| 1061 | if (!(option_mask32 & WGET_NO_FTRUNCATE)) | ||
| 1062 | ftruncate(G.output_fd, pos); | ||
| 1063 | } | ||
| 1057 | } | 1064 | } |
| 1058 | 1065 | ||
| 1059 | if (!(option_mask32 & WGET_OPT_QUIET)) { | 1066 | if (!(option_mask32 & WGET_OPT_QUIET)) { |
| @@ -1566,7 +1573,7 @@ IF_DESKTOP( "no-parent\0" No_argument "\xf0") | |||
| 1566 | if (G.fname_out) { /* -O FILE ? */ | 1573 | if (G.fname_out) { /* -O FILE ? */ |
| 1567 | if (LONE_DASH(G.fname_out)) { /* -O - ? */ | 1574 | if (LONE_DASH(G.fname_out)) { /* -O - ? */ |
| 1568 | G.output_fd = 1; | 1575 | G.output_fd = 1; |
| 1569 | option_mask32 &= ~WGET_OPT_CONTINUE; | 1576 | option_mask32 = (option_mask32 & (~WGET_OPT_CONTINUE)) | WGET_NO_FTRUNCATE; |
| 1570 | } | 1577 | } |
| 1571 | /* compat with wget: -O FILE can overwrite */ | 1578 | /* compat with wget: -O FILE can overwrite */ |
| 1572 | G.o_flags = O_WRONLY | O_CREAT | O_TRUNC; | 1579 | G.o_flags = O_WRONLY | O_CREAT | O_TRUNC; |
