Hi - pushing as obvious:
Author: Frank Ch. Eigler <f...@redhat.com> Date: Sun Mar 29 15:10:37 2020 -0400 debuginfod-client default_progressfn: formatting fix The saga of clean $DEBUGINFOD_PROGRESS=1 output continues. Previous code would sometimes insert a \n (a blank line) into the output stream, even if the target file was found in a cache and thus the progressfn was never called. New code sets a client flag to track this case more precisely. Signed-off-by: Frank Ch. Eigler <f...@redhat.com> diff --git a/debuginfod/ChangeLog b/debuginfod/ChangeLog index 193c27210855..9901c521de53 100644 --- a/debuginfod/ChangeLog +++ b/debuginfod/ChangeLog @@ -1,3 +1,11 @@ +2020-03-29 Frank Ch. Eigler <f...@redhat.com> + + * debuginfod-client.c (struct debuginfod_client): Add a flag field + for progressfn printing. + (default_progressfn): Set it if printing \rsomething. + (debuginfod_end): Terminate with \n if flag set, i.e., only if the + default_progressfn was actually called. + 2020-03-27 Mark Wielaard <m...@klomp.org> * debuginfod.cxx (parse_opt): Check port is not zero. diff --git a/debuginfod/debuginfod-client.c b/debuginfod/debuginfod-client.c index 043e8aa24fac..fa017a84c7cf 100644 --- a/debuginfod/debuginfod-client.c +++ b/debuginfod/debuginfod-client.c @@ -89,6 +89,10 @@ struct debuginfod_client int user_agent_set_p; /* affects add_default_headers */ struct curl_slist *headers; + /* Flags the default_progressfn having printed something that + debuginfod_end needs to terminate. */ + int default_progressfn_printed_p; + /* Can contain all other context, like cache_path, server_urls, timeout or other info gotten from environment variables, the handle data, etc. So those don't have to be reparsed and @@ -438,6 +442,7 @@ default_progressfn (debuginfod_client *c, long a, long b) dprintf(STDERR_FILENO, "\rDownloading from %.*s %ld/%ld", len, url, a, b); + c->default_progressfn_printed_p = 1; return 0; } @@ -935,7 +940,10 @@ debuginfod_query_server (debuginfod_client *c, /* general purpose exit */ out: /* Conclude the last \r status line */ - if (c->progressfn == & default_progressfn) + /* Another possibility is to use the ANSI CSI n K EL "Erase in Line" + code. That way, the previously printed messages would be erased, + and without a newline. */ + if (c->default_progressfn_printed_p) dprintf(STDERR_FILENO, "\n"); free (cache_path);