]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/acquire.cc
* fixed apt-pkg/acquire-item.h (looks like the last commit didn't include it?)
[apt.git] / apt-pkg / acquire.cc
index 74bdaf85bf20ea4e714e1fc10fe6f583709547f6..47655af80f80229bdcd565d26ac73fb87b2cd62a 100644 (file)
@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // Description                                                         /*{{{*/
-// $Id: acquire.cc,v 1.49 2001/05/27 04:28:37 jgg Exp $
+// $Id: acquire.cc,v 1.50 2004/03/17 05:17:11 mdz Exp $
 /* ######################################################################
 
    Acquire - File Acquiration
@@ -26,6 +26,7 @@
 #include <apti18n.h>
 
 #include <iostream>
+#include <sstream>
     
 #include <dirent.h>
 #include <sys/time.h>
@@ -87,7 +88,11 @@ pkgAcquire::~pkgAcquire()
 void pkgAcquire::Shutdown()
 {
    while (Items.size() != 0)
+   {
+      if (Items[0]->Status == Item::StatFetching)
+         Items[0]->Status = Item::StatError;
       delete Items[0];
+   }
 
    while (Queues != 0)
    {
@@ -262,6 +267,10 @@ pkgAcquire::MethodConfig *pkgAcquire::GetConfig(string Access)
    if (Work.Start() == false)
       return 0;
    
+   /* if a method uses DownloadLimit, we switch to SingleInstance mode */
+   if(_config->FindI("Acquire::"+Access+"::DlLimit",0) > 0)
+      Conf->SingleInstance = true;
+   
    return Conf;
 }
                                                                        /*}}}*/
@@ -308,7 +317,7 @@ void pkgAcquire::RunFds(fd_set *RSet,fd_set *WSet)
 /* This runs the queues. It manages a select loop for all of the
    Worker tasks. The workers interact with the queues and items to
    manage the actual fetch. */
-pkgAcquire::RunResult pkgAcquire::Run()
+pkgAcquire::RunResult pkgAcquire::Run(int PulseIntervall)
 {
    Running = true;
    
@@ -323,7 +332,7 @@ pkgAcquire::RunResult pkgAcquire::Run()
    // Run till all things have been acquired
    struct timeval tv;
    tv.tv_sec = 0;
-   tv.tv_usec = 500000
+   tv.tv_usec = PulseIntervall
    while (ToFetch > 0)
    {
       fd_set RFds;
@@ -353,7 +362,7 @@ pkgAcquire::RunResult pkgAcquire::Run()
       // Timeout, notify the log class
       if (Res == 0 || (Log != 0 && Log->Update == true))
       {
-        tv.tv_usec = 500000;
+        tv.tv_usec = PulseIntervall;
         for (Worker *I = Workers; I != 0; I = I->NextAcquire)
            I->Pulse();
         if (Log != 0 && Log->Pulse(this) == false)
@@ -477,7 +486,7 @@ double pkgAcquire::PartialPresent()
         Total += (*I)->PartialSize;
    return Total;
 }
-                                                                       /*}}}*/
+
 // Acquire::UriBegin - Start iterator for the uri list                 /*{{{*/
 // ---------------------------------------------------------------------
 /* */
@@ -799,6 +808,26 @@ bool pkgAcquireStatus::Pulse(pkgAcquire *Owner)
       Time = NewTime;
    }
 
+   int fd = _config->FindI("APT::Status-Fd",-1);
+   if(fd > 0) 
+   {
+      ostringstream status;
+
+      char msg[200];
+      long i = CurrentItems < TotalItems ? CurrentItems + 1 : CurrentItems;
+      unsigned long ETA =
+        (unsigned long)((TotalBytes - CurrentBytes) / CurrentCPS);
+
+      snprintf(msg,sizeof(msg), _("Downloading file %li of %li (%s remaining)"), i, TotalItems, TimeToStr(ETA).c_str());
+
+      // build the status str
+      status << "dlstatus:" << i
+            << ":"  << (CurrentBytes/float(TotalBytes)*100.0) 
+            << ":" << msg 
+            << endl;
+      write(fd, status.str().c_str(), status.str().size());
+   }
+
    return true;
 }
                                                                        /*}}}*/