]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/cachefile.cc
* doc/examples/configure-index:
[apt.git] / apt-pkg / cachefile.cc
index 8b3b02171de95575aa3b407f6a55b605c67905ab..8b8e6dc98426a9f4d878ef1d472e5d1e63174b1b 100644 (file)
@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // Description                                                         /*{{{*/
-// $Id: cachefile.cc,v 1.7 2001/07/01 20:49:08 jgg Exp $
+// $Id: cachefile.cc,v 1.8 2002/04/27 04:28:04 jgg Exp $
 /* ######################################################################
    
    CacheFile - Simple wrapper class for opening, generating and whatnot
@@ -23,6 +23,8 @@
 #include <apt-pkg/configuration.h>
 #include <apt-pkg/policy.h>
 #include <apt-pkg/pkgsystem.h>
+#include <apt-pkg/acquire-item.h>
+#include <apt-pkg/fileutl.h>
     
 #include <apti18n.h>
                                                                        /*}}}*/
@@ -46,10 +48,10 @@ pkgCacheFile::~pkgCacheFile()
    _system->UnLock(true);
 }   
                                                                        /*}}}*/
-// CacheFile::Open - Open the cache files, creating if necessary       /*{{{*/
+// CacheFile::BuildCaches - Open and build the cache files             /*{{{*/
 // ---------------------------------------------------------------------
 /* */
-bool pkgCacheFile::Open(OpProgress &Progress,bool WithLock)
+bool pkgCacheFile::BuildCaches(OpProgress &Progress,bool WithLock)
 {
    if (WithLock == true)
       if (_system->Lock() == false)
@@ -79,6 +81,16 @@ bool pkgCacheFile::Open(OpProgress &Progress,bool WithLock)
    Cache = new pkgCache(Map);
    if (_error->PendingError() == true)
       return false;
+   return true;
+}
+                                                                       /*}}}*/
+// CacheFile::Open - Open the cache files, creating if necessary       /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+bool pkgCacheFile::Open(OpProgress &Progress,bool WithLock)
+{
+   if (BuildCaches(Progress,WithLock) == false)
+      return false;
    
    // The policy engine
    Policy = new pkgPolicy(Cache);
@@ -101,6 +113,56 @@ bool pkgCacheFile::Open(OpProgress &Progress,bool WithLock)
 }
                                                                        /*}}}*/
 
+// CacheFile::ListUpdate - update the cache files                      /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+bool pkgCacheFile::ListUpdate(pkgAcquireStatus &Stat, pkgSourceList &List)
+{
+   pkgAcquire Fetcher(&Stat);
+
+   // Populate it with the source selection
+   if (List.GetIndexes(&Fetcher) == false)
+        return false;
+   
+   // Run scripts
+   RunScripts("APT::Update::Pre-Invoke");
+
+   // Run it
+   if (Fetcher.Run() == pkgAcquire::Failed)
+      return false;
+
+   bool Failed = false;
+   for (pkgAcquire::ItemIterator I = Fetcher.ItemsBegin(); I != Fetcher.ItemsEnd(); I++)
+   {
+      if ((*I)->Status == pkgAcquire::Item::StatDone)
+        continue;
+
+      (*I)->Finished();
+      
+      _error->Warning(_("Failed to fetch %s  %s\n"),
+                     (*I)->DescURI().c_str(),
+                     (*I)->ErrorText.c_str());
+      Failed = true;
+   }
+
+   // Clean out any old list files (if it was not a failure)
+   // Keep "APT::Get::List-Cleanup" name for compatibility, but
+   // this is really a global option for the APT library now
+   if (!Failed && (_config->FindB("APT::Get::List-Cleanup",true) == true ||
+                  _config->FindB("APT::List-Cleanup",true) == true))
+   {
+      if (Fetcher.Clean(_config->FindDir("Dir::State::lists")) == false ||
+         Fetcher.Clean(_config->FindDir("Dir::State::lists") + "partial/") == false)
+        return false;
+   }
+
+   // Run the scripts
+   RunScripts("APT::Update::Post-Invoke");
+
+   return (Failed == false);
+}
+                                                                       /*}}}*/
+
 // CacheFile::Close - close the cache files                            /*{{{*/
 // ---------------------------------------------------------------------
 /* */