summaryrefslogtreecommitdiff
path: root/apt-pkg/cachefile.cc
diff options
context:
space:
mode:
authorMichael Vogt <michael.vogt@ubuntu.com>2008-01-04 21:33:09 +0100
committerMichael Vogt <michael.vogt@ubuntu.com>2008-01-04 21:33:09 +0100
commit893d3e85b98124fc28002be5584b685324646037 (patch)
tree4539342955019ce483a9558be33dcb14fffa5e24 /apt-pkg/cachefile.cc
parent110277098f846c98cbb1f155fe7d53ecca64cc1a (diff)
parentf8477782df203e1998a8704e71a1a3cc699e9e3a (diff)
* merged the apt--DoListUpdate branch, this provides a common interface
for apt-get update like operations for the frontends and also provides hooks to run stuff in APT::Update::{Pre,Post}-Invoke
Diffstat (limited to 'apt-pkg/cachefile.cc')
-rw-r--r--apt-pkg/cachefile.cc69
1 files changed, 69 insertions, 0 deletions
diff --git a/apt-pkg/cachefile.cc b/apt-pkg/cachefile.cc
index cccad2bf3..4c2c56893 100644
--- a/apt-pkg/cachefile.cc
+++ b/apt-pkg/cachefile.cc
@@ -19,6 +19,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>
/*}}}*/
@@ -107,6 +109,73 @@ 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)
+{
+ 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;
+ 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 /*{{{*/
// ---------------------------------------------------------------------
/* */