]> git.saurik.com Git - apt.git/commitdiff
calculate Percent as part of pkgAcquireStatus to provide a weighted percent for both...
authorMichael Vogt <mvo@ubuntu.com>
Wed, 16 Apr 2014 15:41:11 +0000 (17:41 +0200)
committerMichael Vogt <mvo@ubuntu.com>
Wed, 16 Apr 2014 15:41:11 +0000 (17:41 +0200)
apt-pkg/acquire-item.h
apt-pkg/acquire.cc
apt-pkg/acquire.h
apt-private/acqprogress.cc

index bf5cb09c81c2715d2dd5a07eb346060a6585f391..ab4a69c13208399183a0b2588d30cfb4f96ce330 100644 (file)
@@ -723,6 +723,11 @@ class pkgAcqIndex : public pkgAcquire::Item
     */
    std::string CompressionExtension;
 
     */
    std::string CompressionExtension;
 
+   /** \brief Pointer to the IndexTarget data
+    */
+   const struct IndexTarget * Target;
+   indexRecords *MetaIndexParser;
+
    public:
    
    // Specialized action members
    public:
    
    // Specialized action members
index 46d5e6386e036307e53640339e474e78de78ffcf..37964c943685c9747d62a329be3e9d9c577ff647 100644 (file)
@@ -31,6 +31,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <iomanip>
 
 #include <dirent.h>
 #include <sys/time.h>
 
 #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;
    // 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;
    // 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;
    
    // Compute the CPS
    struct timeval NewTime;
@@ -894,6 +895,15 @@ bool pkgAcquireStatus::Pulse(pkgAcquire *Owner)
       Time = NewTime;
    }
 
       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) 
    {
    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);
         
       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
       // build the status str
       status << "dlstatus:" << i
-             << ":"  << Percent
+             << ":"  << std::setprecision(3) << Percent
              << ":" << msg 
              << endl;
 
              << ":" << msg 
              << endl;
 
index ef16d8556538bc2ab88bd88b71b0ec802db16d3c..0113021b21dce95c1a4cec534a61732c2e75d5c8 100644 (file)
@@ -714,6 +714,10 @@ class pkgAcquireStatus
    /** \brief The number of items that have been successfully downloaded. */
    unsigned long CurrentItems;
    
    /** \brief The number of items that have been successfully downloaded. */
    unsigned long CurrentItems;
    
+   /** \brief The estimated percentage of the download (0-100)
+    */
+   double Percent;
+
    public:
 
    /** \brief If \b true, the download scheduler should call Pulse()
    public:
 
    /** \brief If \b true, the download scheduler should call Pulse()
index fe7a45e12e3ee5c2671b696abc599c40fbcd8c8a..adec3740596a0175fda247934a5554da6442331b 100644 (file)
@@ -170,7 +170,7 @@ bool AcqTextStatus::Pulse(pkgAcquire *Owner)
       ScreenWidth = sizeof(Buffer)-1;
 
    // Put in the percent done
       ScreenWidth = sizeof(Buffer)-1;
 
    // Put in the percent done
-   sprintf(S,"%.0f%%",((CurrentBytes + CurrentItems)*100.0)/(TotalBytes+TotalItems));
+   sprintf(S,"%.0f%%", Percent);
 
    bool Shown = false;
    for (pkgAcquire::Worker *I = Owner->WorkersBegin(); I != 0;
 
    bool Shown = false;
    for (pkgAcquire::Worker *I = Owner->WorkersBegin(); I != 0;