Blame SOURCES/0007-curl-7.63.0-JO-preserve-local-file.patch

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