]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/acquire.cc
* methods/mirror.{cc,h}:
[apt.git] / apt-pkg / acquire.cc
index 212c8d52bfc2ba806993e94b76eb8f8855ed1929..cbd67055d952a37de89027a85804764869f9a5b8 100644 (file)
@@ -13,9 +13,6 @@
    ##################################################################### */
                                                                        /*}}}*/
 // Include Files                                                       /*{{{*/
-#ifdef __GNUG__
-#pragma implementation "apt-pkg/acquire.h"
-#endif       
 #include <apt-pkg/acquire.h>
 #include <apt-pkg/acquire-item.h>
 #include <apt-pkg/acquire-worker.h>
@@ -26,6 +23,7 @@
 #include <apti18n.h>
 
 #include <iostream>
+#include <sstream>
     
 #include <dirent.h>
 #include <sys/time.h>
@@ -192,9 +190,9 @@ void pkgAcquire::Enqueue(ItemDesc &Item)
    Item.Owner->Status = Item::StatIdle;
    
    // Queue it into the named queue
-   I->Enqueue(Item);
-   ToFetch++;
-         
+   if(I->Enqueue(Item)) 
+      ToFetch++;
+            
    // Some trace stuff
    if (Debug == true)
    {
@@ -265,11 +263,11 @@ pkgAcquire::MethodConfig *pkgAcquire::GetConfig(string Access)
    Worker Work(Conf);
    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;
 }
                                                                        /*}}}*/
@@ -548,11 +546,17 @@ pkgAcquire::Queue::~Queue()
 // Queue::Enqueue - Queue an item to the queue                         /*{{{*/
 // ---------------------------------------------------------------------
 /* */
-void pkgAcquire::Queue::Enqueue(ItemDesc &Item)
+bool pkgAcquire::Queue::Enqueue(ItemDesc &Item)
 {
    QItem **I = &Items;
-   for (; *I != 0; I = &(*I)->Next);
-   
+   // move to the end of the queue and check for duplicates here
+   for (; *I != 0; I = &(*I)->Next)
+      if (Item.URI == (*I)->URI) 
+      {
+        Item.Owner->Status = Item::StatDone;
+        return false;
+      }
+
    // Create a new item
    QItem *Itm = new QItem;
    *Itm = Item;
@@ -562,6 +566,7 @@ void pkgAcquire::Queue::Enqueue(ItemDesc &Item)
    Item.Owner->QueueCounter++;   
    if (Items->Next == 0)
       Cycle();
+   return true;
 }
                                                                        /*}}}*/
 // Queue::Dequeue - Remove an item from the queue                      /*{{{*/
@@ -807,6 +812,32 @@ 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);
+
+      // only show the ETA if it makes sense
+      if (ETA > 0 && ETA < 172800 /* two days */ )
+        snprintf(msg,sizeof(msg), _("Retrieving file %li of %li (%s remaining)"), i, TotalItems, TimeToStr(ETA).c_str());
+      else
+        snprintf(msg,sizeof(msg), _("Retrieving file %li of %li"), i, TotalItems);
+        
+
+
+      // 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;
 }
                                                                        /*}}}*/