]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/acquire.cc
Dselect support
[apt.git] / apt-pkg / acquire.cc
index 3e22268a7093da7eb666801c6e3916dd70088bac..3bd7662fd022fffbe3cb23d7fed4b57d49c9c4d6 100644 (file)
@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // Description                                                         /*{{{*/
-// $Id: acquire.cc,v 1.13 1998/11/11 23:45:08 jgg Exp $
+// $Id: acquire.cc,v 1.17 1998/11/22 23:37:03 jgg Exp $
 /* ######################################################################
 
    Acquire - File Acquiration
@@ -23,6 +23,7 @@
 #include <apt-pkg/error.h>
 #include <strutl.h>
 
+#include <dirent.h>
 #include <sys/time.h>
                                                                        /*}}}*/
 
@@ -129,7 +130,8 @@ void pkgAcquire::Remove(Worker *Work)
 void pkgAcquire::Enqueue(ItemDesc &Item)
 {
    // Determine which queue to put the item in
-   string Name = QueueName(Item.URI);
+   const MethodConfig *Config;
+   string Name = QueueName(Item.URI,Config);
    if (Name.empty() == true)
       return;
 
@@ -146,6 +148,9 @@ void pkgAcquire::Enqueue(ItemDesc &Item)
         I->Startup();
    }
 
+   // See if this is a local only URI
+   if (Config->LocalOnly == true && Item.Owner->Complete == false)
+      Item.Owner->Local = true;
    Item.Owner->Status = Item::StatIdle;
    
    // Queue it into the named queue
@@ -157,7 +162,7 @@ void pkgAcquire::Enqueue(ItemDesc &Item)
    {
       clog << "Fetching " << Item.URI << endl;
       clog << " to " << Item.Owner->DestFile << endl;
-      clog << " Queue is: " << QueueName(Item.URI) << endl;
+      clog << " Queue is: " << Name << endl;
    }
 }
                                                                        /*}}}*/
@@ -183,11 +188,11 @@ void pkgAcquire::Dequeue(Item *Itm)
 /* The string returned depends on the configuration settings and the
    method parameters. Given something like http://foo.org/bar it can
    return http://foo.org or http */
-string pkgAcquire::QueueName(string Uri)
+string pkgAcquire::QueueName(string Uri,MethodConfig const *&Config)
 {
    URI U(Uri);
    
-   const MethodConfig *Config = GetConfig(U.Access);
+   Config = GetConfig(U.Access);
    if (Config == 0)
       return string();
    
@@ -343,6 +348,71 @@ pkgAcquire::Worker *pkgAcquire::WorkerStep(Worker *I)
    return I->NextAcquire;
 };
                                                                        /*}}}*/
+// Acquire::Clean - Cleans a directory                                 /*{{{*/
+// ---------------------------------------------------------------------
+/* This is a bit simplistic, it looks at every file in the dir and sees
+   if it is part of the download set. */
+bool pkgAcquire::Clean(string Dir)
+{
+   DIR *D = opendir(Dir.c_str());   
+   if (D == 0)
+      return _error->Errno("opendir","Unable to read %s",Dir.c_str());
+   
+   string StartDir = SafeGetCWD();
+   if (chdir(Dir.c_str()) != 0)
+   {
+      closedir(D);
+      return _error->Errno("chdir","Unable to change to ",Dir.c_str());
+   }
+   
+   for (struct dirent *Dir = readdir(D); Dir != 0; Dir = readdir(D))
+   {
+      // Skip some files..
+      if (strcmp(Dir->d_name,"lock") == 0 ||
+         strcmp(Dir->d_name,"partial") == 0 ||
+         strcmp(Dir->d_name,".") == 0 ||
+         strcmp(Dir->d_name,"..") == 0)
+        continue;
+      
+      // Look in the get list
+      vector<Item *>::iterator I = Items.begin();
+      for (; I != Items.end(); I++)
+        if (flNotDir((*I)->DestFile) == Dir->d_name)
+           break;
+      
+      // Nothing found, nuke it
+      if (I == Items.end())
+        unlink(Dir->d_name);
+   };
+   
+   chdir(StartDir.c_str());
+   closedir(D);
+   return true;   
+}
+                                                                       /*}}}*/
+// Acquire::TotalNeeded - Number of bytes to fetch                     /*{{{*/
+// ---------------------------------------------------------------------
+/* This is the total number of bytes needed */
+unsigned long pkgAcquire::TotalNeeded()
+{
+   unsigned long Total = 0;
+   for (pkgAcquire::Item **I = ItemsBegin(); I != ItemsEnd(); I++)
+      Total += (*I)->FileSize;
+   return Total;
+}
+                                                                       /*}}}*/
+// Acquire::FetchNeeded - Number of bytes needed to get                        /*{{{*/
+// ---------------------------------------------------------------------
+/* This is the number of bytes that is not local */
+unsigned long pkgAcquire::FetchNeeded()
+{
+   unsigned long Total = 0;
+   for (pkgAcquire::Item **I = ItemsBegin(); I != ItemsEnd(); I++)
+      if ((*I)->Local == false)
+        Total += (*I)->FileSize;
+   return Total;
+}
+                                                                       /*}}}*/
 
 // Acquire::MethodConfig::MethodConfig - Constructor                   /*{{{*/
 // ---------------------------------------------------------------------
@@ -353,6 +423,7 @@ pkgAcquire::MethodConfig::MethodConfig()
    PreScan = false;
    Pipeline = false;
    SendConfig = false;
+   LocalOnly = false;
    Next = 0;
 }
                                                                        /*}}}*/
@@ -388,11 +459,14 @@ pkgAcquire::Queue::~Queue()
 /* */
 void pkgAcquire::Queue::Enqueue(ItemDesc &Item)
 {
+   QItem **I = &Items;
+   for (; *I != 0; I = &(*I)->Next);
+   
    // Create a new item
-   QItem *I = new QItem;
-   I->Next = Items;
-   Items = I;
-   *I = Item;
+   QItem *Itm = new QItem;
+   *Itm = Item;
+   Itm->Next = 0;
+   *I = Itm;
    
    Item.Owner->QueueCounter++;   
    if (Items->Next == 0)
@@ -545,6 +619,10 @@ void pkgAcquireStatus::Pulse(pkgAcquire *Owner)
    for (pkgAcquire::Item **I = Owner->ItemsBegin(); I != Owner->ItemsEnd(); 
        I++, Count++)
    {
+      // Totally ignore local items
+      if ((*I)->Local == true)
+        continue;
+      
       TotalBytes += (*I)->FileSize;
       if ((*I)->Complete == true)
         CurrentBytes += (*I)->FileSize;
@@ -584,7 +662,10 @@ void pkgAcquireStatus::Pulse(pkgAcquire *Owner)
       }
             
       // Compute the CPS value
-      CurrentCPS = (CurrentBytes - LastBytes)/(sdiff + usdiff/1000000.0);
+      if (sdiff == 0 && usdiff == 0)
+        CurrentCPS = 0;
+      else
+        CurrentCPS = (CurrentBytes - LastBytes)/(sdiff + usdiff/1000000.0);
       LastBytes = CurrentBytes;
       ElapsedTime = NewTime.tv_sec - StartTime.tv_sec;
       Time = NewTime;
@@ -606,7 +687,7 @@ void pkgAcquireStatus::Start()
    ElapsedTime = 0;
 }
                                                                        /*}}}*/
-// pkgAcquireStatus::Stop - Finished downloading                       /*{{{*/
+// AcquireStatus::Stop - Finished downloading                          /*{{{*/
 // ---------------------------------------------------------------------
 /* This accurately computes the elapsed time and the total overall CPS. */
 void pkgAcquireStatus::Stop()
@@ -625,9 +706,12 @@ void pkgAcquireStatus::Stop()
       usdiff += 1000000;
       sdiff--;
    }
-   
+
    // Compute the CPS value
-   CurrentCPS = FetchedBytes/(sdiff + usdiff/1000000.0);
+   if (sdiff == 0 && usdiff == 0)
+      CurrentCPS = 0;
+   else
+      CurrentCPS = FetchedBytes/(sdiff + usdiff/1000000.0);
    LastBytes = CurrentBytes;
    ElapsedTime = sdiff;
 }