From 67b5b05e1795347db67a1547bef6ca77d98732a5 Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Fri, 30 Sep 2016 01:14:50 +0300 Subject: [PATCH] Fix auth segfault, remove 1/1000 progressbar interval (fixes #103) --- libgrive/src/http/CurlAgent.cc | 17 ++++++---- libgrive/src/util/ProgressBar.cc | 57 +++++++++++++++----------------- libgrive/src/util/ProgressBar.hh | 1 - 3 files changed, 36 insertions(+), 39 deletions(-) diff --git a/libgrive/src/http/CurlAgent.cc b/libgrive/src/http/CurlAgent.cc index 122822d..2e1f46d 100644 --- a/libgrive/src/http/CurlAgent.cc +++ b/libgrive/src/http/CurlAgent.cc @@ -159,13 +159,16 @@ std::size_t CurlAgent::Receive( void* ptr, size_t size, size_t nmemb, CurlAgent int CurlAgent::progress_callback( CurlAgent *pthis, curl_off_t totalDownload, curl_off_t finishedDownload, curl_off_t totalUpload, curl_off_t finishedUpload ) { // Only report download progress when set explicitly - totalDownload = pthis->m_pimpl->total_download; - if ( !totalUpload ) - totalUpload = pthis->m_pimpl->total_upload; - pthis->m_pb->reportProgress( - totalDownload > 0 ? totalDownload : totalUpload, - totalDownload > 0 ? finishedDownload : finishedUpload - ); + if ( pthis->m_pb ) + { + totalDownload = pthis->m_pimpl->total_download; + if ( !totalUpload ) + totalUpload = pthis->m_pimpl->total_upload; + pthis->m_pb->reportProgress( + totalDownload > 0 ? totalDownload : totalUpload, + totalDownload > 0 ? finishedDownload : finishedUpload + ); + } return 0; } diff --git a/libgrive/src/util/ProgressBar.cc b/libgrive/src/util/ProgressBar.cc index 9ad8de7..d36e0a4 100644 --- a/libgrive/src/util/ProgressBar.cc +++ b/libgrive/src/util/ProgressBar.cc @@ -8,7 +8,7 @@ namespace gr { -ProgressBar::ProgressBar(): showProgressBar(false), last(1000) +ProgressBar::ProgressBar(): showProgressBar(false) { } @@ -48,38 +48,33 @@ void ProgressBar::reportProgress(u64_t total, u64_t processed) double fraction = (double)processed/total; int point = round(fraction*1000); - if (point != this->last) - { - // only print progress after >= 0.1% change - this->last = point; - // 10 for prefix of percent and 22 for suffix of file size - int availableSize = determineTerminalSize() - 32; - int totalDots; - if (availableSize > 100) - totalDots = 100; - else if (availableSize < 0) - totalDots = 10; - else - totalDots = availableSize; + // 10 for prefix of percent and 22 for suffix of file size + int availableSize = determineTerminalSize() - 32; + int totalDots; + if (availableSize > 100) + totalDots = 100; + else if (availableSize < 0) + totalDots = 10; + else + totalDots = availableSize; - int dotz = round(fraction * totalDots); - int count = 0; - // delete previous output line - printf("\r\33[2K [%3.0f%%] [", fraction * 100); - for (; count < dotz - 1; count++) - putchar('='); - putchar('>'); - for (; count < totalDots - 1; count++) - putchar(' '); - printf("] "); - printBytes(processed); - putchar('/'); - printBytes(total); - if (point == 1000) - putchar('\n'); - fflush(stdout); - } + int dotz = round(fraction * totalDots); + int count = 0; + // delete previous output line + printf("\r\33[2K [%3.0f%%] [", fraction * 100); + for (; count < dotz - 1; count++) + putchar('='); + putchar('>'); + for (; count < totalDots - 1; count++) + putchar(' '); + printf("] "); + printBytes(processed); + putchar('/'); + printBytes(total); + if (point == 1000) + putchar('\n'); + fflush(stdout); } } diff --git a/libgrive/src/util/ProgressBar.hh b/libgrive/src/util/ProgressBar.hh index 5e10eee..fbad6af 100644 --- a/libgrive/src/util/ProgressBar.hh +++ b/libgrive/src/util/ProgressBar.hh @@ -18,7 +18,6 @@ private: static unsigned short int determineTerminalSize(); bool showProgressBar; - int last; }; }