summaryrefslogtreecommitdiff
path: root/apt-pkg/acquire.cc
diff options
context:
space:
mode:
authorMichael Vogt <mvo@ubuntu.com>2014-04-16 17:41:11 +0200
committerMichael Vogt <mvo@ubuntu.com>2014-04-16 17:41:11 +0200
commit96c6cab1fd5a5de19fbd552b42e1dd1c08417946 (patch)
treeaf57b603454e42d784aa3ace7253151e8d805818 /apt-pkg/acquire.cc
parentb11f95991d844d36fc0e3832810057f72a2d810b (diff)
calculate Percent as part of pkgAcquireStatus to provide a weighted percent for both items and bytes
Diffstat (limited to 'apt-pkg/acquire.cc')
-rw-r--r--apt-pkg/acquire.cc34
1 files changed, 17 insertions, 17 deletions
diff --git a/apt-pkg/acquire.cc b/apt-pkg/acquire.cc
index 46d5e6386..37964c943 100644
--- a/apt-pkg/acquire.cc
+++ b/apt-pkg/acquire.cc
@@ -31,6 +31,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <iomanip>
#include <dirent.h>
#include <sys/time.h>
@@ -859,12 +860,6 @@ bool pkgAcquireStatus::Pulse(pkgAcquire *Owner)
}
}
- // debug
- if (_config->FindB("Debug::acquire::progress", false) == true)
- std::clog << " Bytes: "
- << SizeToStr(CurrentBytes) << " / " << SizeToStr(TotalBytes)
- << std::endl;
-
// Normalize the figures and account for unknown size downloads
if (TotalBytes <= 0)
TotalBytes = 1;
@@ -874,6 +869,12 @@ bool pkgAcquireStatus::Pulse(pkgAcquire *Owner)
// Wha?! Is not supposed to happen.
if (CurrentBytes > TotalBytes)
CurrentBytes = TotalBytes;
+
+ // debug
+ if (_config->FindB("Debug::acquire::progress", false) == true)
+ std::clog << " Bytes: "
+ << SizeToStr(CurrentBytes) << " / " << SizeToStr(TotalBytes)
+ << std::endl;
// Compute the CPS
struct timeval NewTime;
@@ -894,6 +895,15 @@ bool pkgAcquireStatus::Pulse(pkgAcquire *Owner)
Time = NewTime;
}
+ // calculate the percentage, if we have too little data assume 0%
+ // FIXME: the 5k is totally arbitrary
+ if (TotalBytes < 5*1024)
+ Percent = 0;
+ else
+ // use both files and bytes because bytes can be unreliable
+ Percent = (0.8 * (CurrentBytes/float(TotalBytes)*100.0) +
+ 0.2 * (CurrentItems/float(TotalItems)*100.0));
+
int fd = _config->FindI("APT::Status-Fd",-1);
if(fd > 0)
{
@@ -911,19 +921,9 @@ bool pkgAcquireStatus::Pulse(pkgAcquire *Owner)
else
snprintf(msg,sizeof(msg), _("Retrieving file %li of %li"), i, TotalItems);
-
- // calculate the percentage, if we have too little data assume 0%
- // FIXME: the 5k is totally arbitrary
- // FIXME2: instead, use a algorithm where 50% is based on total bytes
- // and the other 50% on total files
- int Percent;
- if (TotalBytes < 5*1024)
- Percent = 0;
- else
- Percent = (CurrentBytes/float(TotalBytes)*100.0);
// build the status str
status << "dlstatus:" << i
- << ":" << Percent
+ << ":" << std::setprecision(3) << Percent
<< ":" << msg
<< endl;