Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--dump-header doesn't make use of the --create-dirs option #14941

Closed
Montg0mery opened this issue Sep 17, 2024 · 2 comments
Closed

--dump-header doesn't make use of the --create-dirs option #14941

Montg0mery opened this issue Sep 17, 2024 · 2 comments

Comments

@Montg0mery
Copy link

Montg0mery commented Sep 17, 2024

I did this

curl --verbose --create-dirs --head --dump-header ./test/headers.txt https://www.example.com/

Result:

Warning: Failed to open ./test/headers.txt
curl: (23) Failed writing received data to disk/application

I expected the following

Headers to be saved in the directory specified, even if it doesn't already exist, due to the --create-dirs option.

Obviously for a simple example like this, the directory can be manually created first. However, when used in a large config file with thousands of URLs, it is not possible to automatically save headers and responses into a custom directory per-URL (without first creating every single directory required, which defeats the value of --create-dirs).

E.g., in a config file such as this:

fail-early

next
url = "https://files.example.com/download?id=abc123"
fail
create-dirs
output-dir = "abc123"
remote-name
remote-header-name
dump-header = "abc123/headers.txt"

next
url = "https://files.example.com/download?id=def456"
fail
create-dirs
output-dir = "def456"
remote-name
remote-header-name
dump-header "def456/headers.txt"

(The use of --next is needed in order to reset --output-dir per URL. Different directories are needed per URL in this use case as different download IDs can have the same filename in the Content-Disposition header and both the download ID and filename need to be preserved in the resulting structure).

Without the dump-header lines, curl correctly uses the --create-dirs option and creates the directories when it comes to saving the actual response bodies. But because the headers come before the body, the directory does not exist at the time the headers are written, and curl errors out.

Without the dump-header lines, the rest of the config works really well for this use case. Thanks!

Suggested change:

In the dump-header code, if the provided value contains leading directories and they don't exist, before returning an error, first check if the --create-dirs option has been provided, and then first try to create the required directory tree (in the same way that --create-dirs works with --output). Only if that fails, then return an error, otherwise continue with the rest of the command.

curl/libcurl version

curl 8.10.0

operating system

Ubuntu 22.04

@bagder
Copy link
Member

bagder commented Sep 17, 2024

I don't see any claim in documentation that --create-dirs would work for --dump-header; this is not a bug.

It does however sound like a decent feature to add.

@Montg0mery
Copy link
Author

I don't see any claim in documentation that --create-dirs would work for --dump-header; this is not a bug.

It does however sound like a decent feature to add.

You're right, that was an incorrect assumption - but it would be nice if it did make use of the create-dirs feature 🙂

Thanks.

bagder added a commit that referenced this issue Sep 19, 2024
Add test 3011 to verify

Proposed-by: Montg0mery on github
Fixes #14941
@bagder bagder self-assigned this Sep 19, 2024
@bagder bagder closed this as completed in b4f7ec7 Sep 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

2 participants