From 65ca2294619f865362332ceddc622db92d0f50a6 Mon Sep 17 00:00:00 2001 From: Jay Satiro Date: Thu, 28 Jan 2021 18:56:50 -0500 Subject: tool_writeout: refactor write-out and write-out json - 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 https://github.com/curl/curl/pull/6544 --- src/tool_operate.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/tool_operate.c') diff --git a/src/tool_operate.c b/src/tool_operate.c index 140142a32..2b23680f2 100644 --- a/src/tool_operate.c +++ b/src/tool_operate.c @@ -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); @@ -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); -- cgit v1.2.1