Skip to content

Commit

Permalink
curl -J: do not append to the destination file
Browse files Browse the repository at this point in the history
Fixes #3380
  • Loading branch information
bagder committed Dec 17, 2018
1 parent d8a9de6 commit 697689e
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/tool_cb_hdr.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,12 @@ size_t tool_header_cb(char *ptr, size_t size, size_t nmemb, void *userdata)
outs->filename = filename;
outs->alloc_filename = TRUE;
hdrcbdata->honor_cd_filename = FALSE; /* done now! */
if(!tool_create_output_file(outs, TRUE))
if(!tool_create_output_file(outs))
return failure;
}
break;
}
if(!outs->stream && !tool_create_output_file(outs, FALSE))
if(!outs->stream && !tool_create_output_file(outs))
return failure;
}

Expand All @@ -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 */
char *value = NULL;

if(!outs->stream && !tool_create_output_file(outs, FALSE))
if(!outs->stream && !tool_create_output_file(outs))
return failure;

if(hdrcbdata->global->isatty && hdrcbdata->global->styled_output)
Expand Down
9 changes: 4 additions & 5 deletions src/tool_cb_wrt.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@
#include "memdebug.h" /* keep this as LAST include */

/* 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)
{
struct GlobalConfig *global = outs->config->global;
FILE *file;
Expand All @@ -43,7 +42,7 @@ bool tool_create_output_file(struct OutStruct *outs,
return FALSE;
}

if(outs->is_cd_filename && !append) {
if(outs->is_cd_filename) {
/* don't overwrite existing files */
file = fopen(outs->filename, "rb");
if(file) {
Expand All @@ -55,7 +54,7 @@ bool tool_create_output_file(struct OutStruct *outs,
}

/* open file for writing */
file = fopen(outs->filename, append?"ab":"wb");
file = fopen(outs->filename, "wb");
if(!file) {
warnf(global, "Failed to create the file %s: %s\n", outs->filename,
strerror(errno));
Expand Down Expand Up @@ -142,7 +141,7 @@ size_t tool_write_cb(char *buffer, size_t sz, size_t nmemb, void *userdata)
}
#endif

if(!outs->stream && !tool_create_output_file(outs, FALSE))
if(!outs->stream && !tool_create_output_file(outs))
return failure;

if(is_tty && (outs->bytes < 2000) && !config->terminal_binary_ok) {
Expand Down
2 changes: 1 addition & 1 deletion src/tool_cb_wrt.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@
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 */
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 */
2 changes: 1 addition & 1 deletion src/tool_operate.c
Original file line number Diff line number Diff line change
Expand Up @@ -1583,7 +1583,7 @@ static CURLcode operate_do(struct GlobalConfig *global,
/* do not create (or even overwrite) the file in case we get no
data because of unmet condition */
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;
}

Expand Down

0 comments on commit 697689e

Please sign in to comment.