summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrank Ch. Eigler <[email protected]>2023-08-29 14:08:04 -0400
committerFrank Ch. Eigler <[email protected]>2023-08-29 14:11:27 -0400
commit3ef3fab0d64c89a52dd6e2ce0d01dd5e713d7b5a (patch)
tree930b8ed1d78b27449b63b57f447aca2263d664b5
parent9c41344c968a9c4b9bf539b09ed522e5ada9deb1 (diff)
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 <[email protected]>
-rw-r--r--debuginfod/debuginfod-client.c42
1 files changed, 28 insertions, 14 deletions
diff --git a/debuginfod/debuginfod-client.c b/debuginfod/debuginfod-client.c
index d92d8d62..6882cb19 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))