Skip to content

Commit

Permalink
tool_writeout: refactor write-out and write-out json
Browse files Browse the repository at this point in the history
- Deduplicate the logic used by write-out and write-out json.

Rather than have separate writeLong, writeString, etc, logic for
each of write-out and write-out json instead have respective shared
functions that can output either format and a 'use_json' parameter to
indicate whether it is json that is output.

This will make it easier to maintain. Rather than have to go through
two sets of logic now we only have to go through one.

- Support write-out %{errormsg} and %{exitcode} in json.

- Clarify in the doc that %{exitcode} is the exit code of the transfer.

Prior to this change it just said "The numerical exitcode" which
implies it's the exit code of the tool, and it's not necessarily that.

Closes #xxxx
  • Loading branch information
jay committed Jan 28, 2021
1 parent 36ef648 commit 0969181
Show file tree
Hide file tree
Showing 6 changed files with 230 additions and 397 deletions.
2 changes: 1 addition & 1 deletion docs/cmdline-opts/write-out.d
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ The Content-Type of the requested document, if there was any.
The error message. (Added in 7.75.0)
.TP
.B exitcode
The numerical exitcode. (Added in 7.75.0)
The numerical exitcode of the transfer. (Added in 7.75.0)
.TP
.B filename_effective
The ultimate filename that curl writes out to. This is only meaningful if curl
Expand Down
7 changes: 4 additions & 3 deletions src/tool_operate.c
Original file line number Diff line number Diff line change
Expand Up @@ -625,9 +625,6 @@ static CURLcode post_per_transfer(struct GlobalConfig *global,
newline here */
fputs("\n", per->progressbar.out);

if(config->writeout)
ourWriteOut(per->curl, per, config->writeout, result);

/* Close the outs file */
if(outs->fopened && outs->stream) {
int rc = fclose(outs->stream);
Expand All @@ -647,6 +644,10 @@ static CURLcode post_per_transfer(struct GlobalConfig *global,
setfiletime(filetime, outs->filename, global);
}

/* Write the --write-out data before cleanup but after result is final */
if(config->writeout)
ourWriteOut(config->writeout, per, result);

/* Close function-local opened file descriptors */
if(per->heads.fopened && per->heads.stream)
fclose(per->heads.stream);
Expand Down
Loading

0 comments on commit 0969181

Please sign in to comment.