curl-library
[PATCH 2/2] src/tool_operate: create output file on successful download
From: Kamil Dudka <kdudka_at_redhat.com>
Date: Mon, 30 Mar 2015 14:14:41 +0200
Date: Mon, 30 Mar 2015 14:14:41 +0200
... of an empty file
Bug: https://github.com/bagder/curl/issues/183
---
src/tool_cb_wrt.h | 3 +++
src/tool_operate.c | 7 +++++++
2 files changed, 10 insertions(+)
diff --git a/src/tool_cb_wrt.h b/src/tool_cb_wrt.h
index 380d8dd..ecbefa8 100644
--- a/src/tool_cb_wrt.h
+++ b/src/tool_cb_wrt.h
@@ -29,5 +29,8 @@
size_t tool_write_cb(void *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);
+
#endif /* HEADER_CURL_TOOL_CB_WRT_H */
diff --git a/src/tool_operate.c b/src/tool_operate.c
index 01a61f9..771e42d 100644
--- a/src/tool_operate.c
+++ b/src/tool_operate.c
@@ -1388,6 +1388,13 @@ static CURLcode operate_do(struct GlobalConfig *global,
#endif
result = curl_easy_perform(curl);
+ if(!result && !outs.stream && !outs.bytes
+ /* we have received no data despite the transfer was successful
+ ==> force cration of an empty output file (if an output file
+ was specified) */
+ && !tool_create_output_file(&outs))
+ result = CURLE_WRITE_ERROR;
+
if(outs.is_cd_filename && outs.stream && !global->mute &&
outs.filename)
printf("curl: Saved to filename '%s'\n", outs.filename);
--
2.1.0
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2015-03-30