Skip to content

Commit

Permalink
tool: overwrite instead of append when using -D
Browse files Browse the repository at this point in the history
This commit fixes a bug, in which the tool appends to a text file
instead of overwriting it, when a previous transfer took place.

See curl#4753
See curl#4762
Fixes curl#10074
Closes curl#10079
  • Loading branch information
emilengler committed Dec 11, 2022
1 parent 99f72c0 commit 21fabf4
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/tool_operate.c
Expand Up @@ -969,7 +969,7 @@ static CURLcode single_transfer(struct GlobalConfig *global,
/* open file for output: */
if(strcmp(config->headerfile, "-")) {
FILE *newfile;
newfile = fopen(config->headerfile, per->prev == NULL?"wb":"ab");
newfile = fopen(config->headerfile, "wb+");
if(!newfile) {
warnf(global, "Failed to open %s\n", config->headerfile);
result = CURLE_WRITE_ERROR;
Expand Down
2 changes: 1 addition & 1 deletion tests/data/Makefile.inc
Expand Up @@ -248,7 +248,7 @@ test2500 \
test3000 test3001 test3002 test3003 test3004 test3005 test3006 test3007 \
test3008 test3009 test3010 test3011 test3012 test3013 test3014 test3015 \
test3016 test3017 test3018 test3019 test3020 test3021 test3022 test3023 \
test3024 test3025 test3026 test3027 test3028 \
test3024 test3025 test3026 test3027 test3028 test3029 \
\
test3100 test3101 \
test3200
59 changes: 59 additions & 0 deletions tests/data/test3029
@@ -0,0 +1,59 @@
<testcase>
<info>
<keywords>
HTTP
</keywords>
</info>

#
# Server-side
<reply>
<data>
HTTP/1.1 200 OK
Date: Tue, 09 Nov 2010 14:49:00 GMT
Server: test-server/fake
Last-Modified: Tue, 13 Jun 2000 12:10:00 GMT
ETag: "21025-dc7-39462498"
Accept-Ranges: bytes
Content-Length: 6
Connection: close
Content-Type: text/html
Funny-head: yesyes

-foo-
</data>
</reply>

#
# Client-side
<client>
<server>
http
</server>
<name>
HTTP GET with overwriting a header file
</name>
<command>
-D log/heads%TESTNUMBER http://%HOSTIP:%HTTPPORT/%TESTNUMBER --next -D log/heads%TESTNUMBER http://%HOSTIP:%HTTPPORT/%TESTNUMBER
</command>
</client>

#
# Verify data after the test has been "shot"
<verify>
<file1 name="log/heads%TESTNUMBER" mode="text">
HTTP/1.1 200 OK
Date: Tue, 09 Nov 2010 14:49:00 GMT
Server: test-server/fake
Last-Modified: Tue, 13 Jun 2000 12:10:00 GMT
ETag: "21025-dc7-39462498"
Accept-Ranges: bytes
Content-Length: 6
Connection: close
Content-Type: text/html
Funny-head: yesyes

</file1>

</verify>
</testcase>

0 comments on commit 21fabf4

Please sign in to comment.