Преглед изворни кода

* move the ListUpdate() code from cachefile.h into algorithms.{cc,h}
as it does not require a cachefile at all

Michael Vogt пре 18 година
родитељ
комит
760d496800
6 измењених фајлова са 80 додато и 78 уклоњено
  1. 75 1
      apt-pkg/algorithms.cc
  2. 3 0
      apt-pkg/algorithms.h
  3. 0 74
      apt-pkg/cachefile.cc
  4. 0 1
      apt-pkg/cachefile.h
  5. 1 1
      cmdline/apt-get.cc
  6. 1 1
      debian/changelog

+ 75 - 1
apt-pkg/algorithms.cc

@@ -19,7 +19,7 @@
 #include <apt-pkg/configuration.h>
 #include <apt-pkg/configuration.h>
 #include <apt-pkg/version.h>
 #include <apt-pkg/version.h>
 #include <apt-pkg/sptr.h>
 #include <apt-pkg/sptr.h>
-
+#include <apt-pkg/acquire-item.h>
     
     
 #include <apti18n.h>
 #include <apti18n.h>
 #include <sys/types.h>
 #include <sys/types.h>
@@ -1302,3 +1302,77 @@ void pkgPrioSortList(pkgCache &Cache,pkgCache::Version **List)
 }
 }
 									/*}}}*/
 									/*}}}*/
 
 
+// CacheFile::ListUpdate - update the cache files                    	/*{{{*/
+// ---------------------------------------------------------------------
+/* This is a simple wrapper to update the cache. it will fetch stuff
+ * from the network (or any other sources defined in sources.list)
+ */
+bool ListUpdate(pkgAcquireStatus &Stat, 
+		pkgSourceList &List, 
+		int PulseInterval)
+{
+   pkgAcquire::RunResult res;
+   pkgAcquire Fetcher(&Stat);
+
+   // Populate it with the source selection
+   if (List.GetIndexes(&Fetcher) == false)
+	 return false;
+
+   // Run scripts
+   RunScripts("APT::Update::Pre-Invoke");
+   
+   // check arguments
+   if(PulseInterval>0)
+      res = Fetcher.Run(PulseInterval);
+   else
+      res = Fetcher.Run();
+
+   if (res == pkgAcquire::Failed)
+      return false;
+
+   bool Failed = false;
+   bool TransientNetworkFailure = 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());
+
+      if ((*I)->Status == pkgAcquire::Item::StatTransientNetworkError) 
+      {
+	 TransientNetworkFailure = true;
+	 continue;
+      }
+
+      Failed = true;
+   }
+   
+   // Clean out any old list files
+   // Keep "APT::Get::List-Cleanup" name for compatibility, but
+   // this is really a global option for the APT library now
+   if (!TransientNetworkFailure && !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)
+	 // something went wrong with the clean
+	 return false;
+   }
+   
+   if (TransientNetworkFailure == true)
+      _error->Warning(_("Some index files failed to download, they have been ignored, or old ones used instead."));
+   else if (Failed == true)
+      return _error->Error(_("Some index files failed to download, they have been ignored, or old ones used instead."));
+
+
+   // Run the scripts if all was fine
+   RunScripts("APT::Update::Post-Invoke");
+   return true;
+}
+									/*}}}*/

+ 3 - 0
apt-pkg/algorithms.h

@@ -33,6 +33,7 @@
 
 
 #include <apt-pkg/packagemanager.h>
 #include <apt-pkg/packagemanager.h>
 #include <apt-pkg/depcache.h>
 #include <apt-pkg/depcache.h>
+#include <apt-pkg/acquire.h>
 
 
 #include <iostream>
 #include <iostream>
 
 
@@ -130,5 +131,7 @@ bool pkgAllUpgrade(pkgDepCache &Cache);
 bool pkgMinimizeUpgrade(pkgDepCache &Cache);
 bool pkgMinimizeUpgrade(pkgDepCache &Cache);
 
 
 void pkgPrioSortList(pkgCache &Cache,pkgCache::Version **List);
 void pkgPrioSortList(pkgCache &Cache,pkgCache::Version **List);
+
+bool ListUpdate(pkgAcquireStatus &progress, pkgSourceList &List, int PulseInterval=0);
 		     
 		     
 #endif
 #endif

+ 0 - 74
apt-pkg/cachefile.cc

@@ -109,80 +109,6 @@ bool pkgCacheFile::Open(OpProgress &Progress,bool WithLock)
 }
 }
 									/*}}}*/
 									/*}}}*/
 
 
-// CacheFile::ListUpdate - update the cache files                    	/*{{{*/
-// ---------------------------------------------------------------------
-/* This is a simple wrapper to update the cache. it will fetch stuff
- * from the network (or any other sources defined in sources.list)
- */
-bool pkgCacheFile::ListUpdate(pkgAcquireStatus &Stat, 
-			      pkgSourceList &List, 
-			      int PulseInterval)
-{
-   pkgAcquire::RunResult res;
-   pkgAcquire Fetcher(&Stat);
-
-   // Populate it with the source selection
-   if (List.GetIndexes(&Fetcher) == false)
-	 return false;
-
-   // Run scripts
-   RunScripts("APT::Update::Pre-Invoke");
-   
-   // check arguments
-   if(PulseInterval>0)
-      res = Fetcher.Run(PulseInterval);
-   else
-      res = Fetcher.Run();
-
-   if (res == pkgAcquire::Failed)
-      return false;
-
-   bool Failed = false;
-   bool TransientNetworkFailure = false;
-   for (pkgAcquire::ItemIterator I = Fetcher.ItemsBegin(); 
-	I != Fetcher.ItemsEnd(); I++)
-   {
-      if ((*I)->Status == pkgAcquire::Item::StatDone)
-	 continue;
-
-      (*I)->Finished();
-
-      fprintf(stderr,_("Failed to fetch %s  %s\n"),(*I)->DescURI().c_str(),
-	      (*I)->ErrorText.c_str());
-
-      if ((*I)->Status == pkgAcquire::Item::StatTransientNetworkError) 
-      {
-	 TransientNetworkFailure = true;
-	 continue;
-      }
-
-      Failed = true;
-   }
-   
-   // Clean out any old list files
-   // Keep "APT::Get::List-Cleanup" name for compatibility, but
-   // this is really a global option for the APT library now
-   if (!TransientNetworkFailure && !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)
-	 // something went wrong with the clean
-	 return false;
-   }
-   
-   if (TransientNetworkFailure == true)
-      _error->Warning(_("Some index files failed to download, they have been ignored, or old ones used instead."));
-   else if (Failed == true)
-      return _error->Error(_("Some index files failed to download, they have been ignored, or old ones used instead."));
-
-
-   // Run the scripts if all was fine
-   RunScripts("APT::Update::Post-Invoke");
-   return true;
-}
-									/*}}}*/
 
 
 // CacheFile::Close - close the cache files				/*{{{*/
 // CacheFile::Close - close the cache files				/*{{{*/
 // ---------------------------------------------------------------------
 // ---------------------------------------------------------------------

+ 0 - 1
apt-pkg/cachefile.h

@@ -47,7 +47,6 @@ class pkgCacheFile
 
 
    bool BuildCaches(OpProgress &Progress,bool WithLock = true);
    bool BuildCaches(OpProgress &Progress,bool WithLock = true);
    bool Open(OpProgress &Progress,bool WithLock = true);
    bool Open(OpProgress &Progress,bool WithLock = true);
-   bool ListUpdate(pkgAcquireStatus &progress, pkgSourceList &List, int PulseInterval=0);
    void Close();
    void Close();
    
    
    pkgCacheFile();
    pkgCacheFile();

+ 1 - 1
cmdline/apt-get.cc

@@ -1374,7 +1374,7 @@ bool DoUpdate(CommandLine &CmdL)
 
 
    // do the work
    // do the work
    CacheFile Cache;
    CacheFile Cache;
-   bool res = Cache.ListUpdate(Stat, List);
+   bool res = ListUpdate(Stat, List);
      
      
    // Rebuild the cache.   
    // Rebuild the cache.   
    if (Cache.BuildCaches() == false)
    if (Cache.BuildCaches() == false)

+ 1 - 1
debian/changelog

@@ -50,7 +50,7 @@ apt (0.7.10) UNRELEASED; urgency=low
   * debian/control:
   * debian/control:
     - build against libdb-dev (instead of libdb4.4-dev)
     - build against libdb-dev (instead of libdb4.4-dev)
   * merged the apt--DoListUpdate branch, this provides a common interface
   * merged the apt--DoListUpdate branch, this provides a common interface
-    for apt-get update like operations for the frontends and also provides
+    for "apt-get update" like operations for the frontends and also provides
     hooks to run stuff in APT::Update::{Pre,Post}-Invoke
     hooks to run stuff in APT::Update::{Pre,Post}-Invoke
 
 
   [ Chris Cheney ]
   [ Chris Cheney ]