// -*- 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
#include <apt-pkg/error.h>
#include <strutl.h>
+#include <dirent.h>
#include <sys/time.h>
/*}}}*/
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 /*{{{*/
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 /*{{{*/
// ---------------------------------------------------------------------
/* */
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 /*{{{*/
// ---------------------------------------------------------------------
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;
ElapsedTime = 0;
}
/*}}}*/
-// pkgAcquireStatus::Stop - Finished downloading /*{{{*/
+// AcquireStatus::Stop - Finished downloading /*{{{*/
// ---------------------------------------------------------------------
/* This accurately computes the elapsed time and the total overall CPS. */
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;
}
/*}}}*/