// -*- 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
#include <apt-pkg/error.h>
#include <strutl.h>
+#include <dirent.h>
#include <sys/time.h>
/*}}}*/
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;
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
{
clog << "Fetching " << Item.URI << endl;
clog << " to " << Item.Owner->DestFile << endl;
- clog << " Queue is: " << QueueName(Item.URI) << endl;
+ clog << " Queue is: " << Name << endl;
}
}
/*}}}*/
/* 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();
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 /*{{{*/
// ---------------------------------------------------------------------
PreScan = false;
Pipeline = false;
SendConfig = false;
+ LocalOnly = false;
Next = 0;
}
/*}}}*/
/* */
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)
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;
}
// 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;
ElapsedTime = 0;
}
/*}}}*/
-// pkgAcquireStatus::Stop - Finished downloading /*{{{*/
+// AcquireStatus::Stop - Finished downloading /*{{{*/
// ---------------------------------------------------------------------
/* This accurately computes the elapsed time and the total overall CPS. */
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;
}