From: lilydjwg <lilydjwg@gmail.com>
To: elfutils-devel@sourceware.org
Cc: lilydjwg <lilydjwg@gmail.com>
Subject: [PATCH v2 2/2] debuginfod-client.c: Fix x-debuginfod-size counts differently than CURLINFO_SIZE_DOWNLOAD_T
Date: Wed, 29 Mar 2023 23:02:37 +0800 [thread overview]
Message-ID: <20230329150237.896092-2-lilydjwg@gmail.com> (raw)
In-Reply-To: <20230329150237.896092-1-lilydjwg@gmail.com>
x-debuginfod-size is the actual file size, but CURLINFO_SIZE_DOWNLOAD_T
is transferred size, i.e. the gzipped one if gzip is on.
Let's count written data and use that if and only if x-debuginfod-size
is used.
Signed-off-by: lilydjwg <lilydjwg@gmail.com>
---
ChangeLog | 2 ++
debuginfod/debuginfod-client.c | 45 ++++++++++++++++++++++------------
2 files changed, 32 insertions(+), 15 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 05697a02..903b3494 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,8 @@
* debuginfod/debuginfod-client.c: Fix download size not correctly
fallbacks to x-debuginfod-size header
+ * debuginfod-client.c: Fix x-debuginfod-size counts differently than
+ CURLINFO_SIZE_DOWNLOAD_T
2023-03-03 Mark Wielaard <mark@klomp.org>
diff --git a/debuginfod/debuginfod-client.c b/debuginfod/debuginfod-client.c
index d6d3f0dd..ebc8e6b2 100644
--- a/debuginfod/debuginfod-client.c
+++ b/debuginfod/debuginfod-client.c
@@ -215,6 +215,9 @@ struct handle_data
/* Response http headers for this client handle, sent from the server */
char *response_data;
size_t response_data_size;
+
+ /* The data size that has been written */
+ long written_size;
};
static size_t
@@ -243,6 +246,7 @@ debuginfod_write_callback (char *ptr, size_t size, size_t nmemb, void *data)
if (*d->target_handle != d->handle)
return -1;
+ d->written_size += count;
return (size_t) write(d->fd, (void*)ptr, count);
}
@@ -1265,6 +1269,7 @@ debuginfod_query_server (debuginfod_client *c,
data[i].errbuf[0] = '\0';
data[i].response_data = NULL;
data[i].response_data_size = 0;
+ data[i].written_size = 0;
}
char *escaped_string = NULL;
@@ -1468,6 +1473,7 @@ debuginfod_query_server (debuginfod_client *c,
}
long dl_size = -1;
+ bool size_compressed = true;
if (target_handle && (c->progressfn || maxsize > 0))
{
/* Get size of file being downloaded. NB: If going through
@@ -1498,7 +1504,10 @@ debuginfod_query_server (debuginfod_client *c,
if (hdr != NULL
&& sscanf(hdr, "x-debuginfod-size: %ld", &xdl) == 1)
- dl_size = xdl;
+ {
+ dl_size = xdl;
+ size_compressed = false;
+ }
}
}
@@ -1508,23 +1517,29 @@ 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;
+ if (size_compressed)
+ {
+ 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
-
+ }
+ else
+ {
+ pa = data[committed_to].written_size;
+ }
}
if ((*c->progressfn) (c, pa, dl_size == -1 ? 0 : dl_size))
--
2.40.0
next prev parent reply other threads:[~2023-03-29 15:03 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-29 4:51 [PATCH] debuginfod-client.c: Fix download size not correctly fallbacks to x-debuginfod-size header lilydjwg
2023-03-29 12:28 ` Frank Ch. Eigler
2023-03-29 14:57 ` lilydjwg
2023-03-29 15:02 ` [PATCH v2 1/2] " lilydjwg
2023-03-29 15:02 ` lilydjwg [this message]
2023-03-29 19:14 ` [PATCH v2 2/2] debuginfod-client.c: Fix x-debuginfod-size counts differently than CURLINFO_SIZE_DOWNLOAD_T Frank Ch. Eigler
2023-03-30 3:41 ` lilydjwg
2023-03-30 17:24 ` Frank Ch. Eigler
2023-03-31 4:50 ` lilydjwg
2023-08-29 13:17 ` Mark Wielaard
2023-08-29 18:33 ` PR30809, was " Frank Ch. Eigler
2023-08-29 19:26 ` Mark Wielaard
2023-03-29 20:49 ` [PATCH v2 1/2] debuginfod-client.c: Fix download size not correctly fallbacks to x-debuginfod-size header Frank Ch. Eigler
2023-03-29 15:05 ` [PATCH] " lilydjwg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230329150237.896092-2-lilydjwg@gmail.com \
--to=lilydjwg@gmail.com \
--cc=elfutils-devel@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).