]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/acquire.cc
Fixed signed conversion
[apt.git] / apt-pkg / acquire.cc
index ccc28a3f70f7e0cff6f72545f133107d254e43a6..9a546c7e204d829b9455665e6b1437ee0c454492 100644 (file)
@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // Description                                                         /*{{{*/
-// $Id: acquire.cc,v 1.11 1998/11/11 06:54:16 jgg Exp $
+// $Id: acquire.cc,v 1.15 1998/11/13 07:08:54 jgg Exp $
 /* ######################################################################
 
    Acquire - File Acquiration
@@ -23,6 +23,7 @@
 #include <apt-pkg/error.h>
 #include <strutl.h>
 
+#include <dirent.h>
 #include <sys/time.h>
                                                                        /*}}}*/
 
@@ -322,7 +323,7 @@ bool pkgAcquire::Run()
    for (Queue *I = Queues; I != 0; I = I->Next)
       I->Shutdown();
 
-   return _error->PendingError();
+   return !_error->PendingError();
 }
                                                                        /*}}}*/
 // Acquire::Bump - Called when an item is dequeued                     /*{{{*/
@@ -343,7 +344,48 @@ 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::MethodConfig::MethodConfig - Constructor                   /*{{{*/
 // ---------------------------------------------------------------------
 /* */
@@ -356,6 +398,29 @@ pkgAcquire::MethodConfig::MethodConfig()
    Next = 0;
 }
                                                                        /*}}}*/
+// 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;
+}
+                                                                       /*}}}*/
 
 // Queue::Queue - Constructor                                          /*{{{*/
 // ---------------------------------------------------------------------
@@ -545,6 +610,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;
@@ -606,7 +675,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()
@@ -636,7 +705,7 @@ void pkgAcquireStatus::Stop()
 // ---------------------------------------------------------------------
 /* This is used to get accurate final transfer rate reporting. */
 void pkgAcquireStatus::Fetched(unsigned long Size,unsigned long Resume)
-{
+{   
    FetchedBytes += Size - Resume;
 }
                                                                        /*}}}*/