]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/acquire.cc
merge from lp:~mvo/apt/mvo
[apt.git] / apt-pkg / acquire.cc
index 832eaa02cfc7224a3bee3f348b2f85ee1e2acf10..2064abc5031d8005b8af2dcae02819c5f4171f51 100644 (file)
@@ -37,9 +37,9 @@ using namespace std;
 // Acquire::pkgAcquire - Constructor                                   /*{{{*/
 // ---------------------------------------------------------------------
 /* We grab some runtime state from the configuration space */
-pkgAcquire::pkgAcquire() : Queues(0), Workers(0), Configs(0), Log(NULL), ToFetch(0),
+pkgAcquire::pkgAcquire() : LockFD(-1), Queues(0), Workers(0), Configs(0), Log(NULL), ToFetch(0),
                           Debug(_config->FindB("Debug::pkgAcquire",false)),
-                          Running(false), LockFD(-1)
+                          Running(false)
 {
    string const Mode = _config->Find("Acquire::Queue-Mode","host");
    if (strcasecmp(Mode.c_str(),"host") == 0)
@@ -47,10 +47,10 @@ pkgAcquire::pkgAcquire() : Queues(0), Workers(0), Configs(0), Log(NULL), ToFetch
    if (strcasecmp(Mode.c_str(),"access") == 0)
       QueueMode = QueueAccess;
 }
-pkgAcquire::pkgAcquire(pkgAcquireStatus *Progress) : Queues(0), Workers(0),
+pkgAcquire::pkgAcquire(pkgAcquireStatus *Progress) :  LockFD(-1), Queues(0), Workers(0),
                           Configs(0), Log(Progress), ToFetch(0),
                           Debug(_config->FindB("Debug::pkgAcquire",false)),
-                          Running(false), LockFD(-1)
+                          Running(false)
 {
    string const Mode = _config->Find("Acquire::Queue-Mode","host");
    if (strcasecmp(Mode.c_str(),"host") == 0)
@@ -74,12 +74,12 @@ bool pkgAcquire::Setup(pkgAcquireStatus *Progress, string const &Lock)
    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)
+   if (CreateAPTDirectoryIfNeeded(_config->FindDir("Dir::State"), partialListDir) == false &&
+       CreateAPTDirectoryIfNeeded(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)
+   if (CreateAPTDirectoryIfNeeded(_config->FindDir("Dir::Cache"), partialArchivesDir) == false &&
+       CreateAPTDirectoryIfNeeded(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)
@@ -93,27 +93,6 @@ bool pkgAcquire::Setup(pkgAcquireStatus *Progress, string const &Lock)
    return true;
 }
                                                                        /*}}}*/
-// Acquire::CheckDirectory - ensure that the given directory exists    /*{{{*/
-// ---------------------------------------------------------------------
-/* a small wrapper around CreateDirectory to check if it exists and to
-   remove the trailing "/apt/" from the parent directory if needed */
-bool pkgAcquire::CheckDirectory(string const &Parent, string const &Path) const
-{
-   if (DirectoryExists(Path) == true)
-      return true;
-
-   size_t const len = Parent.size();
-   if (len > 5 && Parent.find("/apt/", len - 6, 5) == len - 5)
-   {
-      if (CreateDirectory(Parent.substr(0,len-5), Path) == true)
-        return true;
-   }
-   else if (CreateDirectory(Parent, Path) == true)
-      return true;
-
-   return false;
-}
-                                                                       /*}}}*/
 // Acquire::~pkgAcquire        - Destructor                                    /*{{{*/
 // ---------------------------------------------------------------------
 /* Free our memory, clean up the queues (destroy the workers) */
@@ -506,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;
@@ -517,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;
@@ -529,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;
@@ -820,7 +799,7 @@ bool pkgAcquireStatus::Pulse(pkgAcquire *Owner)
    }
    
    // Compute the current completion
-   unsigned long ResumeSize = 0;
+   unsigned long long ResumeSize = 0;
    for (pkgAcquire::Worker *I = Owner->WorkersBegin(); I != 0;
        I = Owner->WorkerStep(I))
       if (I->CurrentItem != 0 && I->CurrentItem->Owner->Complete == false)
@@ -859,7 +838,7 @@ bool pkgAcquireStatus::Pulse(pkgAcquire *Owner)
       else
         CurrentCPS = ((CurrentBytes - ResumeSize) - LastBytes)/Delta;
       LastBytes = CurrentBytes - ResumeSize;
-      ElapsedTime = (unsigned long)Delta;
+      ElapsedTime = (unsigned long long)Delta;
       Time = NewTime;
    }
 
@@ -870,8 +849,7 @@ bool pkgAcquireStatus::Pulse(pkgAcquire *Owner)
 
       char msg[200];
       long i = CurrentItems < TotalItems ? CurrentItems + 1 : CurrentItems;
-      unsigned long ETA =
-        (unsigned long)((TotalBytes - CurrentBytes) / CurrentCPS);
+      unsigned long long const ETA = (TotalBytes - CurrentBytes) / CurrentCPS;
 
       // only show the ETA if it makes sense
       if (ETA > 0 && ETA < 172800 /* two days */ )
@@ -927,13 +905,13 @@ void pkgAcquireStatus::Stop()
    else
       CurrentCPS = FetchedBytes/Delta;
    LastBytes = CurrentBytes;
-   ElapsedTime = (unsigned int)Delta;
+   ElapsedTime = (unsigned long long)Delta;
 }
                                                                        /*}}}*/
 // AcquireStatus::Fetched - Called when a byte set has been fetched    /*{{{*/
 // ---------------------------------------------------------------------
 /* This is used to get accurate final transfer rate reporting. */
-void pkgAcquireStatus::Fetched(unsigned long Size,unsigned long Resume)
+void pkgAcquireStatus::Fetched(unsigned long long Size,unsigned long long Resume)
 {   
    FetchedBytes += Size - Resume;
 }