tool_operate: let --create-dirs work for --dump-header as well

Add test 3011 to verify

Proposed-by: Montg0mery on github
Fixes #14941
Closes #14965
This commit is contained in:
Daniel Stenberg 2024-09-19 10:43:58 +02:00
parent 44fc2687b1
commit b4f7ec71ce
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2
4 changed files with 77 additions and 1 deletions

View File

@ -28,5 +28,8 @@ writes the output to stderr.
When used in FTP, the FTP server response lines are considered being "headers" When used in FTP, the FTP server response lines are considered being "headers"
and thus are saved there. and thus are saved there.
Starting in curl 8.11.0, using the --create-dirs option can also create
missing directory components for the path provided in --dump-header.
Having multiple transfers in one set of operations (i.e. the URLs in one Having multiple transfers in one set of operations (i.e. the URLs in one
--next clause), appends them to the same file, separated by a blank line. --next clause), appends them to the same file, separated by a blank line.

View File

@ -1090,6 +1090,12 @@ static CURLcode single_transfer(struct GlobalConfig *global,
* OperationConfig, so that it does not need to be opened/closed * OperationConfig, so that it does not need to be opened/closed
* for every transfer. * for every transfer.
*/ */
if(config->create_dirs) {
result = create_dir_hierarchy(config->headerfile, global);
/* create_dir_hierarchy shows error upon CURLE_WRITE_ERROR */
if(result)
break;
}
if(!per->prev || per->prev->config != config) { if(!per->prev || per->prev->config != config) {
newfile = fopen(config->headerfile, "wb"); newfile = fopen(config->headerfile, "wb");
if(newfile) if(newfile)

View File

@ -264,7 +264,7 @@ test2600 test2601 test2602 test2603 test2604 \
test3000 test3001 test3002 test3003 test3004 test3005 test3006 test3007 \ test3000 test3001 test3002 test3003 test3004 test3005 test3006 test3007 \
test3008 test3009 test3010 test3011 test3012 test3013 test3014 test3015 \ test3008 test3009 test3010 test3011 test3012 test3013 test3014 test3015 \
test3016 test3017 test3018 test3019 test3020 test3021 test3022 test3023 \ test3016 test3017 test3018 test3019 test3020 test3021 test3022 test3023 \
test3024 test3025 test3026 test3027 test3028 test3029 test3030 \ test3024 test3025 test3026 test3027 test3028 test3029 test3030 test3031 \
\ \
test3100 test3101 test3102 test3103 \ test3100 test3101 test3102 test3103 \
test3200 \ test3200 \

67
tests/data/test3031 Normal file
View File

@ -0,0 +1,67 @@
<testcase>
<info>
<keywords>
--dump-header
</keywords>
</info>
#
# Server-side
<reply>
<data nocheck="yes" crlf="yes">
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>
<features>
http
</features>
<name>
--output-dir with --create-dirs
</name>
<command>
http://%HOSTIP:%HTTPPORT/this/is/the/%TESTNUMBER --dump-header %PWD/%LOGDIR/tmp/out.txt --create-dirs
</command>
</client>
#
# Verify data after the test has been "shot"
<verify>
<protocol>
GET /this/is/the/%TESTNUMBER HTTP/1.1
Host: %HOSTIP:%HTTPPORT
User-Agent: curl/%VERSION
Accept: */*
</protocol>
<file name="%LOGDIR/tmp/out.txt" crlf="yes">
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
</file>
</verify>
</testcase>