]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
curl: make --etag-save acknowledge --create-dirs
authorDaniel Stenberg <daniel@haxx.se>
Sat, 21 Dec 2024 10:45:28 +0000 (11:45 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Sat, 21 Dec 2024 13:12:16 +0000 (14:12 +0100)
Add test 693 to verify

Fixes #15730
Suggested-by: Tamir Duberstein
Closes #15732

docs/cmdline-opts/etag-save.md
src/tool_operate.c
tests/data/Makefile.am
tests/data/test693 [new file with mode: 0644]

index c81773b6e263ce685e689b85085fe3b4ab18fd24..237b5dc54873c04e29d56629561801f2df29d5d9 100644 (file)
@@ -20,3 +20,6 @@ Save an HTTP ETag to the specified file. An ETag is a caching related header,
 usually returned in a response. Use this option with a single URL only.
 
 If no ETag is sent by the server, an empty file is created.
+
+Starting in curl 8.12.0, using the --create-dirs option can also create
+missing directory components for the path provided in --etag-save.
index a2ceeac3dd4ed1c51ab473f62d7a8c869d22b61a..14b559b65664420004e50e91c1aa176d80d67ee8 100644 (file)
@@ -1976,6 +1976,12 @@ static CURLcode single_transfer(struct GlobalConfig *global,
       }
 
       if(config->etag_save_file) {
+        if(config->create_dirs) {
+          result = create_dir_hierarchy(config->etag_save_file, global);
+          if(result)
+            break;
+        }
+
         /* open file for output: */
         if(strcmp(config->etag_save_file, "-")) {
           FILE *newfile = fopen(config->etag_save_file, "ab");
index 6d4ddd29aee3aad0cebdc7d4f5b578eee624861e..5bef667fa16e5ef35c5231539f2524fa7555dc28 100644 (file)
@@ -101,7 +101,7 @@ test652 test653 test654 test655 test656 test658 test659 test660 test661 \
 test662 test663 test664 test665 test666 test667 test668 test669 test670 \
 test671 test672 test673 test674 test675 test676 test677 test678 test679 \
 test680 test681 test682 test683 test684 test685 test686 test687 test688 \
-test689 test690 test691 test692 \
+test689 test690 test691 test692 test693 \
 \
 test700 test701 test702 test703 test704 test705 test706 test707 test708 \
 test709 test710 test711 test712 test713 test714 test715 test716 test717 \
diff --git a/tests/data/test693 b/tests/data/test693
new file mode 100644 (file)
index 0000000..533ce80
--- /dev/null
@@ -0,0 +1,62 @@
+<testcase>
+<info>
+<keywords>
+HTTP
+HTTP GET
+etags
+</keywords>
+</info>
+#
+# Server-side
+<reply>
+<data nocheck="yes">
+HTTP/1.1 200 funky chunky!\r
+Server: fakeit/0.9 fakeitbad/1.0\r
+Transfer-Encoding: chunked\r
+Trailer: chunky-trailer\r
+Connection: mooo\r
+ETag: W/"asdf"\r
+\r
+40\r
+aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r
+30\r
+bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\r
+21;heresatest=moooo\r
+cccccccccccccccccccccccccccccccc
+\r
+0\r
+chunky-trailer: header data\r
+\r
+</data>
+</reply>
+
+#
+# Client-side
+<client>
+<server>
+http
+</server>
+<name>
+--etag-save with --create-dirs
+</name>
+<command>
+http://%HOSTIP:%HTTPPORT/%TESTNUMBER --etag-save %LOGDIR/moo/boo/etag%TESTNUMBER --create-dirs
+</command>
+</client>
+
+#
+# Verify data after the test has been "shot"
+<verify>
+<protocol>
+GET /%TESTNUMBER HTTP/1.1\r
+Host: %HOSTIP:%HTTPPORT\r
+User-Agent: curl/%VERSION\r
+Accept: */*\r
+\r
+</protocol>
+<file name="%LOGDIR/moo/boo/etag%TESTNUMBER">
+W/"asdf"
+</file>
+</verify>
+
+</testcase>