From: Frank Ch. Eigler Date: Tue, 29 Aug 2023 18:08:04 +0000 (-0400) Subject: PR30809: improve debuginfod client progress-callback parameters X-Git-Tag: elfutils-0.190~32 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3ef3fab0d64c89a52dd6e2ce0d01dd5e713d7b5a;p=thirdparty%2Felfutils.git PR30809: improve debuginfod client progress-callback parameters * debuginfod-client.c (debuginfod_query_server): Use fstat(3) of the file handle being downloaded into as the preferred source of download progress. Tested by hand, as the testsuite doesn't have enough machinery to simulate compressed vs. uncompressed service. Hand testing with (unmodified) fedora-38 gdb and debuginfod-find shows dramatically improved progress displays: all have quantitative figures when fetching from real (unmodified) upstream servers. Signed-off-by: Frank Ch. Eigler --- diff --git a/debuginfod/debuginfod-client.c b/debuginfod/debuginfod-client.c index d92d8d62c..6882cb190 100644 --- a/debuginfod/debuginfod-client.c +++ b/debuginfod/debuginfod-client.c @@ -1533,23 +1533,37 @@ debuginfod_query_server (debuginfod_client *c, long pa = loops; /* default param for progress callback */ if (target_handle) /* we've committed to a server; report its download progress */ { - CURLcode curl_res; + /* PR30809: Check actual size of cached file. This same + fd is shared by all the multi-curl handles (but only + one will end up writing to it). Another way could be + to tabulate totals in debuginfod_write_callback(). */ + struct stat cached; + int statrc = fstat(fd, &cached); + if (statrc == 0) + pa = (long) cached.st_size; + else + { + /* Otherwise, query libcurl for its tabulated total. + However, that counts http body length, not + decoded/decompressed content length, so does not + measure quite the same thing as dl. */ + CURLcode curl_res; #if CURL_AT_LEAST_VERSION(7, 55, 0) - curl_off_t dl; - curl_res = curl_easy_getinfo(target_handle, - CURLINFO_SIZE_DOWNLOAD_T, - &dl); - if (curl_res == 0 && dl >= 0) - pa = (dl > LONG_MAX ? LONG_MAX : (long)dl); + curl_off_t dl; + curl_res = curl_easy_getinfo(target_handle, + CURLINFO_SIZE_DOWNLOAD_T, + &dl); + if (curl_res == 0 && dl >= 0) + pa = (dl > LONG_MAX ? LONG_MAX : (long)dl); #else - double dl; - curl_res = curl_easy_getinfo(target_handle, - CURLINFO_SIZE_DOWNLOAD, - &dl); - if (curl_res == 0) - pa = (dl >= (double)(LONG_MAX+1UL) ? LONG_MAX : (long)dl); + double dl; + curl_res = curl_easy_getinfo(target_handle, + CURLINFO_SIZE_DOWNLOAD, + &dl); + if (curl_res == 0) + pa = (dl >= (double)(LONG_MAX+1UL) ? LONG_MAX : (long)dl); #endif - + } } if ((*c->progressfn) (c, pa, dl_size == -1 ? 0 : dl_size))