summaryrefslogtreecommitdiff
path: root/apt-pkg/acquire.cc
diff options
context:
space:
mode:
authorMichael Vogt <michael.vogt@ubuntu.com>2010-09-03 14:04:50 +0200
committerMichael Vogt <michael.vogt@ubuntu.com>2010-09-03 14:04:50 +0200
commit0205540433440a9ff4ad4ea4cce44c700a4b401c (patch)
tree97809e2e38482d3d7f124b30552a0936adf4d405 /apt-pkg/acquire.cc
parent24baab5c477bf1e57a0b169a7bac1d2e9ab0c974 (diff)
parent2c6baa5a1f935eb3b8d4eb9fdef62e696416e27a (diff)
merged from lp:~donkult/apt/sid
Diffstat (limited to 'apt-pkg/acquire.cc')
-rw-r--r--apt-pkg/acquire.cc89
1 files changed, 60 insertions, 29 deletions
diff --git a/apt-pkg/acquire.cc b/apt-pkg/acquire.cc
index 74510ae21..6ec557397 100644
--- a/apt-pkg/acquire.cc
+++ b/apt-pkg/acquire.cc
@@ -19,6 +19,7 @@
#include <apt-pkg/configuration.h>
#include <apt-pkg/error.h>
#include <apt-pkg/strutl.h>
+#include <apt-pkg/fileutl.h>
#include <apti18n.h>
@@ -29,7 +30,6 @@
#include <dirent.h>
#include <sys/time.h>
#include <errno.h>
-#include <sys/stat.h>
/*}}}*/
using namespace std;
@@ -37,32 +37,60 @@ using namespace std;
// Acquire::pkgAcquire - Constructor /*{{{*/
// ---------------------------------------------------------------------
/* We grab some runtime state from the configuration space */
-pkgAcquire::pkgAcquire(pkgAcquireStatus *Log) : Log(Log)
+pkgAcquire::pkgAcquire() : Queues(0), Workers(0), Configs(0), Log(NULL), ToFetch(0),
+ Debug(_config->FindB("Debug::pkgAcquire",false)),
+ Running(false), LockFD(-1)
{
- Queues = 0;
- Configs = 0;
- Workers = 0;
- ToFetch = 0;
- Running = false;
-
- string Mode = _config->Find("Acquire::Queue-Mode","host");
+ string const Mode = _config->Find("Acquire::Queue-Mode","host");
+ if (strcasecmp(Mode.c_str(),"host") == 0)
+ QueueMode = QueueHost;
+ if (strcasecmp(Mode.c_str(),"access") == 0)
+ QueueMode = QueueAccess;
+}
+pkgAcquire::pkgAcquire(pkgAcquireStatus *Progress) : Queues(0), Workers(0),
+ Configs(0), Log(Progress), ToFetch(0),
+ Debug(_config->FindB("Debug::pkgAcquire",false)),
+ Running(false), LockFD(-1)
+{
+ string const Mode = _config->Find("Acquire::Queue-Mode","host");
if (strcasecmp(Mode.c_str(),"host") == 0)
QueueMode = QueueHost;
if (strcasecmp(Mode.c_str(),"access") == 0)
- QueueMode = QueueAccess;
+ QueueMode = QueueAccess;
+ Setup(Progress, "");
+}
+ /*}}}*/
+// Acquire::Setup - Delayed Constructor /*{{{*/
+// ---------------------------------------------------------------------
+/* Do everything needed to be a complete Acquire object and report the
+ success (or failure) back so the user knows that something is wrong… */
+bool pkgAcquire::Setup(pkgAcquireStatus *Progress, string const &Lock)
+{
+ Log = Progress;
- Debug = _config->FindB("Debug::pkgAcquire",false);
-
- // This is really a stupid place for this
- struct stat St;
- if (stat((_config->FindDir("Dir::State::lists") + "partial/").c_str(),&St) != 0 ||
- S_ISDIR(St.st_mode) == 0)
- _error->Error(_("Lists directory %spartial is missing."),
- _config->FindDir("Dir::State::lists").c_str());
- if (stat((_config->FindDir("Dir::Cache::Archives") + "partial/").c_str(),&St) != 0 ||
- S_ISDIR(St.st_mode) == 0)
- _error->Error(_("Archive directory %spartial is missing."),
- _config->FindDir("Dir::Cache::Archives").c_str());
+ // check for existence and possibly create auxiliary directories
+ string const listDir = _config->FindDir("Dir::State::lists");
+ string const partialListDir = listDir + "partial/";
+ string const archivesDir = _config->FindDir("Dir::Cache::Archives");
+ string const partialArchivesDir = archivesDir + "partial/";
+
+ if (CheckDirectory(_config->FindDir("Dir::State"), partialListDir) == false &&
+ CheckDirectory(listDir, partialListDir) == false)
+ return _error->Errno("Acquire", _("List directory %spartial is missing."), listDir.c_str());
+
+ if (CheckDirectory(_config->FindDir("Dir::Cache"), partialArchivesDir) == false &&
+ CheckDirectory(archivesDir, partialArchivesDir) == false)
+ return _error->Errno("Acquire", _("Archives directory %spartial is missing."), archivesDir.c_str());
+
+ if (Lock.empty() == true || _config->FindB("Debug::NoLocking", false) == true)
+ return true;
+
+ // Lock the directory this acquire object will work in
+ LockFD = GetLock(flCombine(Lock, "lock"));
+ if (LockFD == -1)
+ return _error->Error(_("Unable to lock directory %s"), Lock.c_str());
+
+ return true;
}
/*}}}*/
// Acquire::~pkgAcquire - Destructor /*{{{*/
@@ -71,7 +99,10 @@ pkgAcquire::pkgAcquire(pkgAcquireStatus *Log) : Log(Log)
pkgAcquire::~pkgAcquire()
{
Shutdown();
-
+
+ if (LockFD != -1)
+ close(LockFD);
+
while (Configs != 0)
{
MethodConfig *Jnk = Configs;
@@ -454,9 +485,9 @@ bool pkgAcquire::Clean(string Dir)
// Acquire::TotalNeeded - Number of bytes to fetch /*{{{*/
// ---------------------------------------------------------------------
/* This is the total number of bytes needed */
-double pkgAcquire::TotalNeeded()
+unsigned long long pkgAcquire::TotalNeeded()
{
- double Total = 0;
+ unsigned long long Total = 0;
for (ItemCIterator I = ItemsBegin(); I != ItemsEnd(); I++)
Total += (*I)->FileSize;
return Total;
@@ -465,9 +496,9 @@ double pkgAcquire::TotalNeeded()
// Acquire::FetchNeeded - Number of bytes needed to get /*{{{*/
// ---------------------------------------------------------------------
/* This is the number of bytes that is not local */
-double pkgAcquire::FetchNeeded()
+unsigned long long pkgAcquire::FetchNeeded()
{
- double Total = 0;
+ unsigned long long Total = 0;
for (ItemCIterator I = ItemsBegin(); I != ItemsEnd(); I++)
if ((*I)->Local == false)
Total += (*I)->FileSize;
@@ -477,9 +508,9 @@ double pkgAcquire::FetchNeeded()
// Acquire::PartialPresent - Number of partial bytes we already have /*{{{*/
// ---------------------------------------------------------------------
/* This is the number of bytes that is not local */
-double pkgAcquire::PartialPresent()
+unsigned long long pkgAcquire::PartialPresent()
{
- double Total = 0;
+ unsigned long long Total = 0;
for (ItemCIterator I = ItemsBegin(); I != ItemsEnd(); I++)
if ((*I)->Local == false)
Total += (*I)->PartialSize;