]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/acquire.cc
releasing package apt version 1.1~exp1
[apt.git] / apt-pkg / acquire.cc
index 2b427ccd347f10da9f8fc7a0c9694097a669ed16..57cbba169ec5cd66ea01d4f521dbfc985d3b6772 100644 (file)
@@ -31,6 +31,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <iomanip>
 
 #include <dirent.h>
 #include <sys/time.h>
@@ -821,7 +822,9 @@ bool pkgAcquireStatus::Pulse(pkgAcquire *Owner)
    // Compute the total number of bytes to fetch
    unsigned int Unknown = 0;
    unsigned int Count = 0;
-   for (pkgAcquire::ItemCIterator I = Owner->ItemsBegin(); I != Owner->ItemsEnd();
+   bool UnfetchedReleaseFiles = false;
+   for (pkgAcquire::ItemCIterator I = Owner->ItemsBegin(); 
+        I != Owner->ItemsEnd();
        ++I, ++Count)
    {
       TotalItems++;
@@ -835,6 +838,10 @@ bool pkgAcquireStatus::Pulse(pkgAcquire *Owner)
       // see if the method tells us to expect more
       TotalItems += (*I)->ExpectedAdditionalItems;
 
+      // check if there are unfetched Release files
+      if ((*I)->Complete == false && (*I)->ExpectedAdditionalItems > 0)
+         UnfetchedReleaseFiles = true;
+
       TotalBytes += (*I)->FileSize;
       if ((*I)->Complete == true)
         CurrentBytes += (*I)->FileSize;
@@ -846,6 +853,7 @@ bool pkgAcquireStatus::Pulse(pkgAcquire *Owner)
    unsigned long long ResumeSize = 0;
    for (pkgAcquire::Worker *I = Owner->WorkersBegin(); I != 0;
        I = Owner->WorkerStep(I))
+   {
       if (I->CurrentItem != 0 && I->CurrentItem->Owner->Complete == false)
       {
         CurrentBytes += I->CurrentSize;
@@ -856,6 +864,7 @@ bool pkgAcquireStatus::Pulse(pkgAcquire *Owner)
             I->CurrentItem->Owner->Complete == false)
            TotalBytes += I->CurrentSize;
       }
+   }
    
    // Normalize the figures and account for unknown size downloads
    if (TotalBytes <= 0)
@@ -866,6 +875,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;
@@ -886,6 +901,14 @@ bool pkgAcquireStatus::Pulse(pkgAcquire *Owner)
       Time = NewTime;
    }
 
+   // calculate the percentage, if we have too little data assume 1%
+   if (TotalBytes > 0 && UnfetchedReleaseFiles)
+      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) 
    {
@@ -903,16 +926,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%
-      int Percent;
-      if (TotalBytes < 1*1024)
-         Percent = 0;
-      else
-         Percent = (CurrentBytes/float(TotalBytes)*100.0);
       // build the status str
       status << "dlstatus:" << i
-             << ":"  << Percent
+             << ":"  << std::setprecision(3) << Percent
              << ":" << msg 
              << endl;