From f23a3dd2f8a4ee11373e0ff8cd22f5fc03a2574f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20B=C3=A1lint=20Misius?= Date: Sat, 27 May 2023 20:16:16 +0200 Subject: [PATCH] Fix unknown HTTP response body size being reported as 0 in some cases Namely, when libcurl dies or when progress is checked before the request is started, although this should never happen. --- src/client/http/requestmanager/Libcurl.cpp | 6 +++--- src/client/http/requestmanager/RequestManager.h | 2 +- src/gui/update/UpdateActivity.cpp | 9 ++++++++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/client/http/requestmanager/Libcurl.cpp b/src/client/http/requestmanager/Libcurl.cpp index 121c5a747..22a87dbb6 100644 --- a/src/client/http/requestmanager/Libcurl.cpp +++ b/src/client/http/requestmanager/Libcurl.cpp @@ -371,11 +371,11 @@ namespace http { #ifdef REQUEST_USE_CURL_OFFSET_T curl_off_t total, done; - HandleCURLcode(curl_easy_getinfo(handle->curlEasy, CURLINFO_CONTENT_LENGTH_DOWNLOAD_T, &total)); + HandleCURLcode(curl_easy_getinfo(handle->curlEasy, CURLINFO_CONTENT_LENGTH_DOWNLOAD_T, &total)); // stores -1 if unknown HandleCURLcode(curl_easy_getinfo(handle->curlEasy, CURLINFO_SIZE_DOWNLOAD_T, &done)); #else double total, done; - HandleCURLcode(curl_easy_getinfo(handle->curlEasy, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &total)); + HandleCURLcode(curl_easy_getinfo(handle->curlEasy, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &total)); // stores -1 if unknown HandleCURLcode(curl_easy_getinfo(handle->curlEasy, CURLINFO_SIZE_DOWNLOAD, &done)); #endif handle->bytesTotal = int(total); @@ -383,7 +383,7 @@ namespace http } else { - handle->bytesTotal = 0; + handle->bytesTotal = -1; handle->bytesDone = 0; } } diff --git a/src/client/http/requestmanager/RequestManager.h b/src/client/http/requestmanager/RequestManager.h index c7cbb1ee9..b199e1a92 100644 --- a/src/client/http/requestmanager/RequestManager.h +++ b/src/client/http/requestmanager/RequestManager.h @@ -37,7 +37,7 @@ namespace http State state = ready; std::mutex stateMx; std::condition_variable stateCv; - std::atomic bytesTotal = 0; + std::atomic bytesTotal = -1; std::atomic bytesDone = 0; int statusCode = 0; ByteString responseData; diff --git a/src/gui/update/UpdateActivity.cpp b/src/gui/update/UpdateActivity.cpp index c75a6ab4c..e44beb58a 100644 --- a/src/gui/update/UpdateActivity.cpp +++ b/src/gui/update/UpdateActivity.cpp @@ -42,7 +42,14 @@ private: { int total, done; std::tie(total, done) = request->CheckProgress(); - notifyProgress(total ? done * 100 / total : 0); + if (total == -1) + { + notifyProgress(-1); + } + else + { + notifyProgress(total ? done * 100 / total : 0); + } Platform::Millisleep(1); }