From b4f7ec71cefe9fd044670f8cfa75d66eae4af941 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 19 Sep 2024 10:43:58 +0200 Subject: [PATCH] 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 --- docs/cmdline-opts/dump-header.md | 3 ++ src/tool_operate.c | 6 +++ tests/data/Makefile.am | 2 +- tests/data/test3031 | 67 ++++++++++++++++++++++++++++++++ 4 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 tests/data/test3031 diff --git a/docs/cmdline-opts/dump-header.md b/docs/cmdline-opts/dump-header.md index 81da38c409..bdb0e874e3 100644 --- a/docs/cmdline-opts/dump-header.md +++ b/docs/cmdline-opts/dump-header.md @@ -28,5 +28,8 @@ writes the output to stderr. When used in FTP, the FTP server response lines are considered being "headers" 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 --next clause), appends them to the same file, separated by a blank line. diff --git a/src/tool_operate.c b/src/tool_operate.c index b49e9fd06f..90b6efdade 100644 --- a/src/tool_operate.c +++ b/src/tool_operate.c @@ -1090,6 +1090,12 @@ static CURLcode single_transfer(struct GlobalConfig *global, * OperationConfig, so that it does not need to be opened/closed * 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) { newfile = fopen(config->headerfile, "wb"); if(newfile) diff --git a/tests/data/Makefile.am b/tests/data/Makefile.am index d6bd237c28..f5f903e869 100644 --- a/tests/data/Makefile.am +++ b/tests/data/Makefile.am @@ -264,7 +264,7 @@ test2600 test2601 test2602 test2603 test2604 \ 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 test3029 test3030 \ +test3024 test3025 test3026 test3027 test3028 test3029 test3030 test3031 \ \ test3100 test3101 test3102 test3103 \ test3200 \ diff --git a/tests/data/test3031 b/tests/data/test3031 new file mode 100644 index 0000000000..58edc376dd --- /dev/null +++ b/tests/data/test3031 @@ -0,0 +1,67 @@ + + + +--dump-header + + +# +# Server-side + + +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- + + + +# +# Client-side + + +http + + +http + + +--output-dir with --create-dirs + + +http://%HOSTIP:%HTTPPORT/this/is/the/%TESTNUMBER --dump-header %PWD/%LOGDIR/tmp/out.txt --create-dirs + + + +# +# Verify data after the test has been "shot" + + +GET /this/is/the/%TESTNUMBER HTTP/1.1 +Host: %HOSTIP:%HTTPPORT +User-Agent: curl/%VERSION +Accept: */* + + + +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 + + + +