diff options
author | Stefan Eissing <stefan@eissing.org> | 2023-01-04 14:37:52 +0100 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2023-01-04 23:11:54 +0100 |
commit | 24e4e57cf33d00e4ca8654a795ef7916d6e6ea04 (patch) | |
tree | e19095a463ae5dc5d49ff647f43ee6dda7232f29 | |
parent | 1485e8921398f434c38528127c8ba0584324e10d (diff) | |
download | curl-24e4e57cf33d00e4ca8654a795ef7916d6e6ea04.tar.gz |
tool_operate: fix headerfile writing
Do not rely on the first transfer started to be the first to get a
response (remember -Z). All transfers now write the headefile (-D) in
append mode, making sure that the order of transfer responses does not
lead to overwrites of previous data.
Closes #10224
-rw-r--r-- | src/tool_operate.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/tool_operate.c b/src/tool_operate.c index 97ed5dbf0..6b139a3cc 100644 --- a/src/tool_operate.c +++ b/src/tool_operate.c @@ -971,18 +971,19 @@ static CURLcode single_transfer(struct GlobalConfig *global, FILE *newfile; /* - * this checks if the previous transfer had the same - * OperationConfig, which would mean, that an output file has - * already been created and data can be appended to it, instead - * of overwriting it. + * Since every transfer has its own file handle for dumping + * the headers, we need to open it in append mode, since transfers + * might finish in any order. + * The first transfer just clears the file. * TODO: Consider placing the file handle inside the * OperationConfig, so that it does not need to be opened/closed * for every transfer. */ - if(per->prev && per->prev->config == config) - newfile = fopen(config->headerfile, "ab+"); - else + if(!per->prev || per->prev->config != config) { newfile = fopen(config->headerfile, "wb+"); + fclose(newfile); + } + newfile = fopen(config->headerfile, "ab+"); if(!newfile) { warnf(global, "Failed to open %s\n", config->headerfile); |