]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/acquire.cc
refactor
[apt.git] / apt-pkg / acquire.cc
index 37964c943685c9747d62a329be3e9d9c577ff647..ec565fcfa6dcdbaea5ed21faa94057e89aeb2179 100644 (file)
@@ -37,6 +37,7 @@
 #include <sys/time.h>
 #include <sys/select.h>
 #include <errno.h>
+#include <sys/stat.h>
 
 #include <apti18n.h>
                                                                        /*}}}*/
@@ -73,23 +74,27 @@ pkgAcquire::pkgAcquire(pkgAcquireStatus *Progress) :  LockFD(-1), Queues(0), Wor
 // ---------------------------------------------------------------------
 /* 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)
+bool pkgAcquire::Setup(pkgAcquireStatus *Progress, string const &Lock,
+      bool const createDirectories)
 {
    Log = Progress;
 
    // 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 (CreateAPTDirectoryIfNeeded(_config->FindDir("Dir::State"), partialListDir) == false &&
-       CreateAPTDirectoryIfNeeded(listDir, partialListDir) == false)
-      return _error->Errno("Acquire", _("List directory %spartial is missing."), listDir.c_str());
-
-   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 (createDirectories == true)
+   {
+      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 (CreateAPTDirectoryIfNeeded(_config->FindDir("Dir::State"), partialListDir) == false &&
+           CreateAPTDirectoryIfNeeded(listDir, partialListDir) == false)
+        return _error->Errno("Acquire", _("List directory %spartial is missing."), listDir.c_str());
+
+      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)
       return true;
@@ -487,6 +492,9 @@ bool pkgAcquire::Clean(string Dir)
    if (DirectoryExists(Dir) == false)
       return true;
 
+   if(Dir == "/")
+      return _error->Error(_("Clean of %s is not supported"), Dir.c_str());
+
    DIR *D = opendir(Dir.c_str());   
    if (D == 0)
       return _error->Errno("opendir",_("Unable to read %s"),Dir.c_str());
@@ -578,27 +586,18 @@ pkgAcquire::UriIterator pkgAcquire::UriEnd()
 // Acquire::MethodConfig::MethodConfig - Constructor                   /*{{{*/
 // ---------------------------------------------------------------------
 /* */
-pkgAcquire::MethodConfig::MethodConfig()
+pkgAcquire::MethodConfig::MethodConfig() : d(NULL), Next(0), SingleInstance(false),
+   Pipeline(false), SendConfig(false), LocalOnly(false), NeedsCleanup(false),
+   Removable(false)
 {
-   SingleInstance = false;
-   Pipeline = false;
-   SendConfig = false;
-   LocalOnly = false;
-   Removable = false;
-   Next = 0;
 }
                                                                        /*}}}*/
 // Queue::Queue - Constructor                                          /*{{{*/
 // ---------------------------------------------------------------------
 /* */
-pkgAcquire::Queue::Queue(string Name,pkgAcquire *Owner) : Name(Name), 
-            Owner(Owner)
+pkgAcquire::Queue::Queue(string Name,pkgAcquire *Owner) : d(NULL), Next(0),
+   Name(Name), Items(0), Workers(0), Owner(Owner), PipeDepth(0), MaxPipeDepth(1)
 {
-   Items = 0;
-   Next = 0;
-   Workers = 0;
-   MaxPipeDepth = 1;
-   PipeDepth = 0;
 }
                                                                        /*}}}*/
 // Queue::~Queue - Destructor                                          /*{{{*/
@@ -802,7 +801,7 @@ void pkgAcquire::Queue::Bump()
 // AcquireStatus::pkgAcquireStatus - Constructor                       /*{{{*/
 // ---------------------------------------------------------------------
 /* */
-pkgAcquireStatus::pkgAcquireStatus() : d(NULL), Update(true), MorePulses(false)
+pkgAcquireStatus::pkgAcquireStatus() : d(NULL), Percent(0), Update(true), MorePulses(false)
 {
    Start();
 }
@@ -822,7 +821,9 @@ bool pkgAcquireStatus::Pulse(pkgAcquire *Owner)
    // Compute the total number of bytes to fetch
    unsigned int Unknown = 0;
    unsigned int Count = 0;
-   for (pkgAcquire::ItemCIterator I = Owner->ItemsBegin(); I != Owner->ItemsEnd();
+   bool UnfetchedReleaseFiles = false;
+   for (pkgAcquire::ItemCIterator I = Owner->ItemsBegin(); 
+        I != Owner->ItemsEnd();
        ++I, ++Count)
    {
       TotalItems++;
@@ -836,6 +837,10 @@ bool pkgAcquireStatus::Pulse(pkgAcquire *Owner)
       // see if the method tells us to expect more
       TotalItems += (*I)->ExpectedAdditionalItems;
 
+      // check if there are unfetched Release files
+      if ((*I)->Complete == false && (*I)->ExpectedAdditionalItems > 0)
+         UnfetchedReleaseFiles = true;
+
       TotalBytes += (*I)->FileSize;
       if ((*I)->Complete == true)
         CurrentBytes += (*I)->FileSize;
@@ -895,9 +900,8 @@ bool pkgAcquireStatus::Pulse(pkgAcquire *Owner)
       Time = NewTime;
    }
 
-   // calculate the percentage, if we have too little data assume 0%
-   // FIXME: the 5k is totally arbitrary 
-   if (TotalBytes < 5*1024)
+   // calculate the percentage, if we have too little data assume 1%
+   if (TotalBytes > 0 && UnfetchedReleaseFiles)
       Percent = 0;
    else 
       // use both files and bytes because bytes can be unreliable