]> granicus.if.org Git - curl/commitdiff
curl -J: do not append to the destination file
authorDaniel Stenberg <daniel@haxx.se>
Mon, 17 Dec 2018 11:51:51 +0000 (12:51 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Wed, 19 Dec 2018 07:44:02 +0000 (08:44 +0100)
Reported-by: Kamil Dudka
Fixes #3380
Closes #3381

src/tool_cb_hdr.c
src/tool_cb_wrt.c
src/tool_cb_wrt.h
src/tool_operate.c

index 84b0d9c87134454a3bea0951adced6e30004fc53..3844904c9052b34cbc76c7517c47a08b308faf16 100644 (file)
@@ -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;
   }
 
@@ -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)
index 2cb5e1b41e1d78254294f79b1c4ea305ab74989f..195d6e79c8918f69cc574699129eaa75a37f38e1 100644 (file)
@@ -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;
@@ -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) {
@@ -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));
@@ -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) {
index 51e002beaebb69bbffd911d83041a9b7443654ce..188d3ea7da095abda15d9ce8cbaef0a04869e412 100644 (file)
@@ -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 */
index e53a9d8676168f5ebf0cb2a4199452e669a8508d..429e9cf469e367994252e0e878f116660eb1dd2a 100644 (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
                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;
           }