Skip to content

Commit c50352d

Browse files
committed
Fix download progress
1 parent 5a2cd88 commit c50352d

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

include/vcpkg/base/contractual-constants.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,8 @@ namespace vcpkg
591591
inline constexpr StringLiteral StatusNotInstalled = "not-installed";
592592
inline constexpr StringLiteral StatusPurge = "purge";
593593

594+
// App Insights JSON response fields
594595
inline constexpr StringLiteral AppInsightsResponseItemsReceived = "itemsReceived";
595596
inline constexpr StringLiteral AppInsightsResponseItemsAccepted = "itemsAccepted";
597+
inline constexpr StringLiteral AppInsightsResponseErrors = "errors";
596598
}

src/vcpkg/base/downloads.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,16 +137,16 @@ namespace vcpkg
137137
return static_cast<WriteFilePointer*>(param)->write(contents, size, nmemb);
138138
}
139139

140-
static size_t progress_callback(void* clientp, double dltotal, double dlnow, double ultotal, double ulnow)
140+
static size_t progress_callback(
141+
void* clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow)
141142
{
142143
(void)ultotal;
143144
(void)ulnow;
144145
auto machine_readable_progress = static_cast<MessageSink*>(clientp);
145-
146-
if (dltotal > 0)
146+
if (dltotal && machine_readable_progress)
147147
{
148-
const double percent = (dlnow / dltotal) * 100.0;
149-
machine_readable_progress->println(LocalizedString::from_raw(fmt::format("{:.2f}%", percent)));
148+
double percentage = (static_cast<double>(dlnow) / static_cast<double>(dltotal)) * 100.0;
149+
machine_readable_progress->println(LocalizedString::from_raw(fmt::format("{:.2f}%", percentage)));
150150
}
151151
return 0;
152152
}
@@ -512,7 +512,7 @@ namespace vcpkg
512512
set_common_curl_easy_options(handle, raw_url, request_headers);
513513
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &write_file_callback);
514514
curl_easy_setopt(curl, CURLOPT_WRITEDATA, static_cast<void*>(&fileptr));
515-
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L); // enable progress
515+
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L); // change from default to enable progress
516516
curl_easy_setopt(curl, CURLOPT_XFERINFOFUNCTION, &progress_callback);
517517
curl_easy_setopt(curl, CURLOPT_XFERINFODATA, static_cast<void*>(&machine_readable_progress));
518518
auto curl_code = curl_easy_perform(curl);

src/vcpkg/metrics.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ namespace vcpkg
551551

552552
auto maybe_received = json->get(vcpkg::AppInsightsResponseItemsReceived);
553553
auto maybe_accepted = json->get(vcpkg::AppInsightsResponseItemsAccepted);
554-
auto maybe_errors = json->get("errors");
554+
auto maybe_errors = json->get(vcpkg::AppInsightsResponseErrors);
555555

556556
if (maybe_received && maybe_accepted && maybe_errors && maybe_received->is_integer() &&
557557
maybe_accepted->is_integer() && maybe_errors->is_array())
@@ -590,7 +590,6 @@ namespace vcpkg
590590
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); // CURLFOLLOW_ALL
591591
curl_easy_setopt(curl, CURLOPT_USERAGENT, vcpkg_curl_user_agent);
592592

593-
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1L);
594593
std::string buff;
595594
curl_easy_setopt(curl, CURLOPT_WRITEDATA, static_cast<void*>(&buff));
596595
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &string_append_cb);

0 commit comments

Comments
 (0)