PR30809, was Re: [PATCH v2 2/2] debuginfod-client.c: Fix x-debuginfod-size counts differently than CURLINFO_SIZE_DOWNLOAD_T

Message ID 20230829183307.GE24480@redhat.com
State Committed
Headers
Series PR30809, was Re: [PATCH v2 2/2] debuginfod-client.c: Fix x-debuginfod-size counts differently than CURLINFO_SIZE_DOWNLOAD_T |

Commit Message

Frank Ch. Eigler Aug. 29, 2023, 6:33 p.m. UTC
  Hi -

> What is the status of this patch/discussion?

Ummmm forgot about it.  But that's OK, filed PR30809, and wrote &
tested this little patch:

commit 3ef3fab0d64c89a52dd6e2ce0d01dd5e713d7b5a
Author: Frank Ch. Eigler <fche@redhat.com>
Date:   Tue Aug 29 14:08:04 2023 -0400

    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 <fche@redhat.com>
  

Comments

Mark Wielaard Aug. 29, 2023, 7:26 p.m. UTC | #1
Hi Frank,

On Tue, Aug 29, 2023 at 02:33:07PM -0400, Frank Ch. Eigler wrote:
> commit 3ef3fab0d64c89a52dd6e2ce0d01dd5e713d7b5a
> Author: Frank Ch. Eigler <fche@redhat.com>
> Date:   Tue Aug 29 14:08:04 2023 -0400
> 
>     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 <fche@redhat.com>

Very nice and simple. Looks good.

Thanks,

Mark
  

Patch

diff --git a/debuginfod/debuginfod-client.c b/debuginfod/debuginfod-client.c
index d92d8d62c982..6882cb190d3c 100644
--- a/debuginfod/debuginfod-client.c
+++ b/debuginfod/debuginfod-client.c
@@ -1533,6 +1533,20 @@  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 */
             {
+              /* 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;
@@ -1549,7 +1563,7 @@  debuginfod_query_server (debuginfod_client *c,
                   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))