From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by sourceware.org (Postfix) with ESMTPS id 5709A3858C50 for ; Wed, 29 Mar 2023 15:03:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5709A3858C50 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pj1-x1036.google.com with SMTP id p3-20020a17090a74c300b0023f69bc7a68so16419271pjl.4 for ; Wed, 29 Mar 2023 08:03:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1680102190; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=cFB6lwgu3MqmNir9WpnPwtpWnpKOoQfAIa7JlaichB8=; b=pfDEL6SFhMKTNVx9WuqDNsRAEuAH1Lbnf+BvJoa1XlVPGqlCiYYE00hS2PjNgla711 jtWEkqcjphh5P6t8Sv4ib2eT6nmeXBZADuXmSooqAikUbRY6YgAdGvFIiprqYrDMqpiY NrdnPYZRuQnEDKsJT0EVfxvn1k5FrGD4f8IeLw97h6691vntifqxs8J4vd/7AbA1Xylu SIFeu7IBn2GgN1SSEPSwEUjSpBDMqn+/+eoMd8NnF6FvcxOxMbma8JYO67fV3AWdJ4RE Y9qYsn2mJUdAuyPLjd2x5Nlxhk4iCrtJ5EQu093oD5hNLrxwonCrRyWn1fUXppqrBTw/ AOiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680102190; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cFB6lwgu3MqmNir9WpnPwtpWnpKOoQfAIa7JlaichB8=; b=49PWMGNFWeetotDfC7w6JWSIOZ9ISJy1mffg8J14O2DORcA8CW1xwAowjWkZpVpe/g BhyDYSFsT03Q44viLUCu7wlXBltERSG61Ss1WKlZj7qTxaxWHx+JgUlwPFBLUWrTII98 419ekIFFftrmFPVhCMmvnyCIgXbWTiQb1vMeWB2q+uO2pY3mfYu6SoAZyoK2ihSepnWv X1hOUwNTXXrxnUwGXHy0UYuNdoYpS3rXhWE1oc2CKNUze4+cGV5SNNyoIwAWOg7Dk3re wsTqPrX2PMo5ETMdbQJDBfMrm7lSMgvxs2OAeRZccroUZ4WqL5ZjzBhWCEZHnEV02EH+ rN6g== X-Gm-Message-State: AO0yUKVVKW5VKYD7GKK3BOp7HpaekEA0+MGXOA0eMk6piKjZI5dt2GO6 CLkMJMeoszo4Qtwr68PnHkEv0SfVi/j941QtNEI= X-Google-Smtp-Source: AK7set/HfNvYinHJhcFtxug1IS5gZQDyc8rr8oKtAgCuMIKXjdESuuHR651ovvfUxKu6FO1Ar0+00g== X-Received: by 2002:a05:6a20:8357:b0:de:6e42:e0e5 with SMTP id z23-20020a056a20835700b000de6e42e0e5mr16322582pzc.13.1680102189862; Wed, 29 Mar 2023 08:03:09 -0700 (PDT) Received: from localhost ([2a0c:b641:69c:e9b8:1::1]) by smtp.gmail.com with ESMTPSA id b1-20020a6567c1000000b005023496e339sm21619977pgs.63.2023.03.29.08.03.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Mar 2023 08:03:09 -0700 (PDT) From: lilydjwg To: elfutils-devel@sourceware.org Cc: lilydjwg 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 Message-Id: <20230329150237.896092-2-lilydjwg@gmail.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230329150237.896092-1-lilydjwg@gmail.com> References: <20230329150237.896092-1-lilydjwg@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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 --- 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 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