1
0
mirror of https://github.com/moparisthebest/curl synced 2024-08-13 17:03:50 -04:00

curl -J: do not append to the destination file

Reported-by: Kamil Dudka
Fixes #3380
Closes #3381
This commit is contained in:
Daniel Stenberg 2018-12-17 12:51:51 +01:00
parent f097669248
commit 4849267197
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2
4 changed files with 9 additions and 10 deletions

View File

@ -157,12 +157,12 @@ size_t tool_header_cb(char *ptr, size_t size, size_t nmemb, void *userdata)
outs->filename = filename; outs->filename = filename;
outs->alloc_filename = TRUE; outs->alloc_filename = TRUE;
hdrcbdata->honor_cd_filename = FALSE; /* done now! */ hdrcbdata->honor_cd_filename = FALSE; /* done now! */
if(!tool_create_output_file(outs, TRUE)) if(!tool_create_output_file(outs))
return failure; return failure;
} }
break; break;
} }
if(!outs->stream && !tool_create_output_file(outs, FALSE)) if(!outs->stream && !tool_create_output_file(outs))
return failure; return failure;
} }
@ -172,7 +172,7 @@ size_t tool_header_cb(char *ptr, size_t size, size_t nmemb, void *userdata)
/* bold headers only for selected protocols */ /* bold headers only for selected protocols */
char *value = NULL; char *value = NULL;
if(!outs->stream && !tool_create_output_file(outs, FALSE)) if(!outs->stream && !tool_create_output_file(outs))
return failure; return failure;
if(hdrcbdata->global->isatty && hdrcbdata->global->styled_output) if(hdrcbdata->global->isatty && hdrcbdata->global->styled_output)

View File

@ -32,8 +32,7 @@
#include "memdebug.h" /* keep this as LAST include */ #include "memdebug.h" /* keep this as LAST include */
/* create a local file for writing, return TRUE on success */ /* create a local file for writing, return TRUE on success */
bool tool_create_output_file(struct OutStruct *outs, bool tool_create_output_file(struct OutStruct *outs)
bool append)
{ {
struct GlobalConfig *global = outs->config->global; struct GlobalConfig *global = outs->config->global;
FILE *file; FILE *file;
@ -43,7 +42,7 @@ bool tool_create_output_file(struct OutStruct *outs,
return FALSE; return FALSE;
} }
if(outs->is_cd_filename && !append) { if(outs->is_cd_filename) {
/* don't overwrite existing files */ /* don't overwrite existing files */
file = fopen(outs->filename, "rb"); file = fopen(outs->filename, "rb");
if(file) { if(file) {
@ -55,7 +54,7 @@ bool tool_create_output_file(struct OutStruct *outs,
} }
/* open file for writing */ /* open file for writing */
file = fopen(outs->filename, append?"ab":"wb"); file = fopen(outs->filename, "wb");
if(!file) { if(!file) {
warnf(global, "Failed to create the file %s: %s\n", outs->filename, warnf(global, "Failed to create the file %s: %s\n", outs->filename,
strerror(errno)); strerror(errno));
@ -142,7 +141,7 @@ size_t tool_write_cb(char *buffer, size_t sz, size_t nmemb, void *userdata)
} }
#endif #endif
if(!outs->stream && !tool_create_output_file(outs, FALSE)) if(!outs->stream && !tool_create_output_file(outs))
return failure; return failure;
if(is_tty && (outs->bytes < 2000) && !config->terminal_binary_ok) { if(is_tty && (outs->bytes < 2000) && !config->terminal_binary_ok) {

View File

@ -30,6 +30,6 @@
size_t tool_write_cb(char *buffer, size_t sz, size_t nmemb, void *userdata); size_t tool_write_cb(char *buffer, size_t sz, size_t nmemb, void *userdata);
/* create a local file for writing, return TRUE on success */ /* create a local file for writing, return TRUE on success */
bool tool_create_output_file(struct OutStruct *outs, bool append); bool tool_create_output_file(struct OutStruct *outs);
#endif /* HEADER_CURL_TOOL_CB_WRT_H */ #endif /* HEADER_CURL_TOOL_CB_WRT_H */

View File

@ -1583,7 +1583,7 @@ static CURLcode operate_do(struct GlobalConfig *global,
/* do not create (or even overwrite) the file in case we get no /* do not create (or even overwrite) the file in case we get no
data because of unmet condition */ data because of unmet condition */
curl_easy_getinfo(curl, CURLINFO_CONDITION_UNMET, &cond_unmet); curl_easy_getinfo(curl, CURLINFO_CONDITION_UNMET, &cond_unmet);
if(!cond_unmet && !tool_create_output_file(&outs, FALSE)) if(!cond_unmet && !tool_create_output_file(&outs))
result = CURLE_WRITE_ERROR; result = CURLE_WRITE_ERROR;
} }