|
|
d73b74 |
From ff74657fb645e7175971128a171ef7d5ece40d77 Mon Sep 17 00:00:00 2001
|
|
|
d73b74 |
From: Daniel Stenberg <daniel@haxx.se>
|
|
|
d73b74 |
Date: Mon, 17 Dec 2018 12:51:51 +0100
|
|
|
d73b74 |
Subject: [PATCH] curl -J: do not append to the destination file
|
|
|
d73b74 |
|
|
|
d73b74 |
Reported-by: Kamil Dudka
|
|
|
d73b74 |
Fixes #3380
|
|
|
d73b74 |
Closes #3381
|
|
|
d73b74 |
|
|
|
d73b74 |
Upstream-commit: 4849267197682e69cfa056c2bd7a44acd123a917
|
|
|
d73b74 |
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
|
|
|
d73b74 |
---
|
|
|
d73b74 |
src/tool_cb_hdr.c | 6 +++---
|
|
|
d73b74 |
src/tool_cb_wrt.c | 9 ++++-----
|
|
|
d73b74 |
src/tool_cb_wrt.h | 2 +-
|
|
|
d73b74 |
src/tool_operate.c | 2 +-
|
|
|
d73b74 |
4 files changed, 9 insertions(+), 10 deletions(-)
|
|
|
d73b74 |
|
|
|
d73b74 |
diff --git a/src/tool_cb_hdr.c b/src/tool_cb_hdr.c
|
|
|
d73b74 |
index 84b0d9c..3844904 100644
|
|
|
d73b74 |
--- a/src/tool_cb_hdr.c
|
|
|
d73b74 |
+++ b/src/tool_cb_hdr.c
|
|
|
d73b74 |
@@ -148,12 +148,12 @@ size_t tool_header_cb(char *ptr, size_t size, size_t nmemb, void *userdata)
|
|
|
d73b74 |
outs->filename = filename;
|
|
|
d73b74 |
outs->alloc_filename = TRUE;
|
|
|
d73b74 |
hdrcbdata->honor_cd_filename = FALSE; /* done now! */
|
|
|
d73b74 |
- if(!tool_create_output_file(outs, TRUE))
|
|
|
d73b74 |
+ if(!tool_create_output_file(outs))
|
|
|
d73b74 |
return failure;
|
|
|
d73b74 |
}
|
|
|
d73b74 |
break;
|
|
|
d73b74 |
}
|
|
|
d73b74 |
- if(!outs->stream && !tool_create_output_file(outs, FALSE))
|
|
|
d73b74 |
+ if(!outs->stream && !tool_create_output_file(outs))
|
|
|
d73b74 |
return failure;
|
|
|
d73b74 |
}
|
|
|
d73b74 |
|
|
|
d73b74 |
@@ -162,7 +162,7 @@ size_t tool_header_cb(char *ptr, size_t size, size_t nmemb, void *userdata)
|
|
|
d73b74 |
/* bold headers only happen for HTTP(S) and RTSP */
|
|
|
d73b74 |
char *value = NULL;
|
|
|
d73b74 |
|
|
|
d73b74 |
- if(!outs->stream && !tool_create_output_file(outs, FALSE))
|
|
|
d73b74 |
+ if(!outs->stream && !tool_create_output_file(outs))
|
|
|
d73b74 |
return failure;
|
|
|
d73b74 |
|
|
|
d73b74 |
if(hdrcbdata->global->isatty && hdrcbdata->global->styled_output)
|
|
|
d73b74 |
diff --git a/src/tool_cb_wrt.c b/src/tool_cb_wrt.c
|
|
|
d73b74 |
index 2cb5e1b..195d6e7 100644
|
|
|
d73b74 |
--- a/src/tool_cb_wrt.c
|
|
|
d73b74 |
+++ b/src/tool_cb_wrt.c
|
|
|
d73b74 |
@@ -32,8 +32,7 @@
|
|
|
d73b74 |
#include "memdebug.h" /* keep this as LAST include */
|
|
|
d73b74 |
|
|
|
d73b74 |
/* create a local file for writing, return TRUE on success */
|
|
|
d73b74 |
-bool tool_create_output_file(struct OutStruct *outs,
|
|
|
d73b74 |
- bool append)
|
|
|
d73b74 |
+bool tool_create_output_file(struct OutStruct *outs)
|
|
|
d73b74 |
{
|
|
|
d73b74 |
struct GlobalConfig *global = outs->config->global;
|
|
|
d73b74 |
FILE *file;
|
|
|
d73b74 |
@@ -43,7 +42,7 @@ bool tool_create_output_file(struct OutStruct *outs,
|
|
|
d73b74 |
return FALSE;
|
|
|
d73b74 |
}
|
|
|
d73b74 |
|
|
|
d73b74 |
- if(outs->is_cd_filename && !append) {
|
|
|
d73b74 |
+ if(outs->is_cd_filename) {
|
|
|
d73b74 |
/* don't overwrite existing files */
|
|
|
d73b74 |
file = fopen(outs->filename, "rb");
|
|
|
d73b74 |
if(file) {
|
|
|
d73b74 |
@@ -55,7 +54,7 @@ bool tool_create_output_file(struct OutStruct *outs,
|
|
|
d73b74 |
}
|
|
|
d73b74 |
|
|
|
d73b74 |
/* open file for writing */
|
|
|
d73b74 |
- file = fopen(outs->filename, append?"ab":"wb");
|
|
|
d73b74 |
+ file = fopen(outs->filename, "wb");
|
|
|
d73b74 |
if(!file) {
|
|
|
d73b74 |
warnf(global, "Failed to create the file %s: %s\n", outs->filename,
|
|
|
d73b74 |
strerror(errno));
|
|
|
d73b74 |
@@ -142,7 +141,7 @@ size_t tool_write_cb(char *buffer, size_t sz, size_t nmemb, void *userdata)
|
|
|
d73b74 |
}
|
|
|
d73b74 |
#endif
|
|
|
d73b74 |
|
|
|
d73b74 |
- if(!outs->stream && !tool_create_output_file(outs, FALSE))
|
|
|
d73b74 |
+ if(!outs->stream && !tool_create_output_file(outs))
|
|
|
d73b74 |
return failure;
|
|
|
d73b74 |
|
|
|
d73b74 |
if(is_tty && (outs->bytes < 2000) && !config->terminal_binary_ok) {
|
|
|
d73b74 |
diff --git a/src/tool_cb_wrt.h b/src/tool_cb_wrt.h
|
|
|
d73b74 |
index 51e002b..188d3ea 100644
|
|
|
d73b74 |
--- a/src/tool_cb_wrt.h
|
|
|
d73b74 |
+++ b/src/tool_cb_wrt.h
|
|
|
d73b74 |
@@ -30,7 +30,7 @@
|
|
|
d73b74 |
size_t tool_write_cb(char *buffer, size_t sz, size_t nmemb, void *userdata);
|
|
|
d73b74 |
|
|
|
d73b74 |
/* create a local file for writing, return TRUE on success */
|
|
|
d73b74 |
-bool tool_create_output_file(struct OutStruct *outs, bool append);
|
|
|
d73b74 |
+bool tool_create_output_file(struct OutStruct *outs);
|
|
|
d73b74 |
|
|
|
d73b74 |
#endif /* HEADER_CURL_TOOL_CB_WRT_H */
|
|
|
d73b74 |
|
|
|
d73b74 |
diff --git a/src/tool_operate.c b/src/tool_operate.c
|
|
|
d73b74 |
index e53a9d8..429e9cf 100644
|
|
|
d73b74 |
--- a/src/tool_operate.c
|
|
|
d73b74 |
+++ b/src/tool_operate.c
|
|
|
d73b74 |
@@ -1581,7 +1581,7 @@ static CURLcode operate_do(struct GlobalConfig *global,
|
|
|
d73b74 |
/* do not create (or even overwrite) the file in case we get no
|
|
|
d73b74 |
data because of unmet condition */
|
|
|
d73b74 |
curl_easy_getinfo(curl, CURLINFO_CONDITION_UNMET, &cond_unmet);
|
|
|
d73b74 |
- if(!cond_unmet && !tool_create_output_file(&outs, FALSE))
|
|
|
d73b74 |
+ if(!cond_unmet && !tool_create_output_file(&outs))
|
|
|
d73b74 |
result = CURLE_WRITE_ERROR;
|
|
|
d73b74 |
}
|
|
|
d73b74 |
|
|
|
d73b74 |
--
|
|
|
d73b74 |
2.17.2
|
|
|
d73b74 |
|