summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Vogt <mvo@debian.org>2013-10-05 12:22:55 +0200
committerMichael Vogt <mvo@debian.org>2013-10-05 12:22:55 +0200
commitd428d131a29a08fa7c1d95b98b684fb2ebb554c0 (patch)
tree3b87f98fee2553dbe482c976d769653f3e32b0e9
parent82e369c4b93b5b81db7988ab377a3c5bd388268e (diff)
Move ListUpdate/AquireUpdate into update.{cc,h}
This moves the ListUpdate/AquireUpdate out of the "catch-all" algorithm.{cc,h} file into its own update.{cc,h}
-rw-r--r--apt-pkg/algorithms.cc99
-rw-r--r--apt-pkg/algorithms.h6
-rw-r--r--apt-pkg/makefile4
-rw-r--r--apt-pkg/update.cc126
-rw-r--r--apt-pkg/update.h21
-rw-r--r--apt-private/private-update.cc1
6 files changed, 151 insertions, 106 deletions
diff --git a/apt-pkg/algorithms.cc b/apt-pkg/algorithms.cc
index 22701f8a6..8644a8138 100644
--- a/apt-pkg/algorithms.cc
+++ b/apt-pkg/algorithms.cc
@@ -1337,102 +1337,3 @@ void pkgPrioSortList(pkgCache &Cache,pkgCache::Version **List)
qsort(List,Count,sizeof(*List),PrioComp);
}
/*}}}*/
-// ListUpdate - construct Fetcher and 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 Fetcher;
- if (Fetcher.Setup(&Stat, _config->FindDir("Dir::State::Lists")) == false)
- return false;
-
- // Populate it with the source selection
- if (List.GetIndexes(&Fetcher) == false)
- return false;
-
- return AcquireUpdate(Fetcher, PulseInterval, true);
-}
- /*}}}*/
-// AcquireUpdate - take Fetcher and update the cache files /*{{{*/
-// ---------------------------------------------------------------------
-/* This is a simple wrapper to update the cache with a provided acquire
- * If you only need control over Status and the used SourcesList use
- * ListUpdate method instead.
- */
-bool AcquireUpdate(pkgAcquire &Fetcher, int const PulseInterval,
- bool const RunUpdateScripts, bool const ListCleanup)
-{
- // Run scripts
- if (RunUpdateScripts == true)
- RunScripts("APT::Update::Pre-Invoke");
-
- pkgAcquire::RunResult res;
- 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();
-
- ::URI uri((*I)->DescURI());
- uri.User.clear();
- uri.Password.clear();
- string descUri = string(uri);
- _error->Warning(_("Failed to fetch %s %s\n"), 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 && ListCleanup == true &&
- (_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 success scripts if all was fine
- if (RunUpdateScripts == true)
- {
- if(!TransientNetworkFailure && !Failed)
- RunScripts("APT::Update::Post-Invoke-Success");
-
- // Run the other scripts
- RunScripts("APT::Update::Post-Invoke");
- }
- return true;
-}
- /*}}}*/
diff --git a/apt-pkg/algorithms.h b/apt-pkg/algorithms.h
index 9dfa1538a..80f6578eb 100644
--- a/apt-pkg/algorithms.h
+++ b/apt-pkg/algorithms.h
@@ -46,10 +46,9 @@ using std::ostream;
#ifndef APT_9_CLEANER_HEADERS
#include <apt-pkg/upgrade.h>
+#include <apt-pkg/update.h>
#endif
-class pkgAcquireStatus;
-
class pkgSimulate : public pkgPackageManager /*{{{*/
{
@@ -152,8 +151,5 @@ bool pkgFixBroken(pkgDepCache &Cache);
void pkgPrioSortList(pkgCache &Cache,pkgCache::Version **List);
-bool ListUpdate(pkgAcquireStatus &progress, pkgSourceList &List, int PulseInterval=0);
-bool AcquireUpdate(pkgAcquire &Fetcher, int const PulseInterval = 0,
- bool const RunUpdateScripts = true, bool const ListCleanup = true);
#endif
diff --git a/apt-pkg/makefile b/apt-pkg/makefile
index 262f8fd41..dc943aad4 100644
--- a/apt-pkg/makefile
+++ b/apt-pkg/makefile
@@ -44,7 +44,7 @@ SOURCE+= pkgcache.cc version.cc depcache.cc \
pkgsystem.cc indexfile.cc pkgcachegen.cc acquire-item.cc \
indexrecords.cc vendor.cc vendorlist.cc cdrom.cc indexcopy.cc \
aptconfiguration.cc cachefilter.cc cacheset.cc edsp.cc \
- upgrade.cc
+ upgrade.cc update.cc
HEADERS+= algorithms.h depcache.h pkgcachegen.h cacheiterators.h \
orderlist.h sourcelist.h packagemanager.h tagfile.h \
init.h pkgcache.h version.h progress.h pkgrecords.h \
@@ -52,7 +52,7 @@ HEADERS+= algorithms.h depcache.h pkgcachegen.h cacheiterators.h \
clean.h srcrecords.h cachefile.h versionmatch.h policy.h \
pkgsystem.h indexfile.h metaindex.h indexrecords.h vendor.h \
vendorlist.h cdrom.h indexcopy.h aptconfiguration.h \
- cachefilter.h cacheset.h edsp.h upgrade.h
+ cachefilter.h cacheset.h edsp.h upgrade.h update.h
# Source code for the debian specific components
# In theory the deb headers do not need to be exported..
diff --git a/apt-pkg/update.cc b/apt-pkg/update.cc
new file mode 100644
index 000000000..97be5490b
--- /dev/null
+++ b/apt-pkg/update.cc
@@ -0,0 +1,126 @@
+
+// Include Files /*{{{*/
+#include <config.h>
+
+#include <apt-pkg/algorithms.h>
+#include <apt-pkg/update.h>
+#include <apt-pkg/error.h>
+#include <apt-pkg/configuration.h>
+#include <apt-pkg/version.h>
+#include <apt-pkg/sptr.h>
+#include <apt-pkg/acquire-item.h>
+#include <apt-pkg/edsp.h>
+#include <apt-pkg/sourcelist.h>
+#include <apt-pkg/fileutl.h>
+#include <apt-pkg/progress.h>
+
+#include <sys/types.h>
+#include <cstdlib>
+#include <algorithm>
+#include <iostream>
+#include <stdio.h>
+
+#include <apti18n.h>
+ /*}}}*/
+
+using namespace std;
+
+// ListUpdate - construct Fetcher and 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 Fetcher;
+ if (Fetcher.Setup(&Stat, _config->FindDir("Dir::State::Lists")) == false)
+ return false;
+
+ // Populate it with the source selection
+ if (List.GetIndexes(&Fetcher) == false)
+ return false;
+
+ return AcquireUpdate(Fetcher, PulseInterval, true);
+}
+ /*}}}*/
+// AcquireUpdate - take Fetcher and update the cache files /*{{{*/
+// ---------------------------------------------------------------------
+/* This is a simple wrapper to update the cache with a provided acquire
+ * If you only need control over Status and the used SourcesList use
+ * ListUpdate method instead.
+ */
+bool AcquireUpdate(pkgAcquire &Fetcher, int const PulseInterval,
+ bool const RunUpdateScripts, bool const ListCleanup)
+{
+ // Run scripts
+ if (RunUpdateScripts == true)
+ RunScripts("APT::Update::Pre-Invoke");
+
+ pkgAcquire::RunResult res;
+ 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();
+
+ ::URI uri((*I)->DescURI());
+ uri.User.clear();
+ uri.Password.clear();
+ string descUri = string(uri);
+ _error->Warning(_("Failed to fetch %s %s\n"), 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 && ListCleanup == true &&
+ (_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 success scripts if all was fine
+ if (RunUpdateScripts == true)
+ {
+ if(!TransientNetworkFailure && !Failed)
+ RunScripts("APT::Update::Post-Invoke-Success");
+
+ // Run the other scripts
+ RunScripts("APT::Update::Post-Invoke");
+ }
+ return true;
+}
+ /*}}}*/
diff --git a/apt-pkg/update.h b/apt-pkg/update.h
new file mode 100644
index 000000000..3835644de
--- /dev/null
+++ b/apt-pkg/update.h
@@ -0,0 +1,21 @@
+// -*- mode: cpp; mode: fold -*-
+// Description /*{{{*/
+/* ######################################################################
+
+ Update - ListUpdate releated code
+
+ ##################################################################### */
+ /*}}}*/
+
+#ifndef PKGLIB_UPDATE_H
+#define PKGLIB_UPDATE_H
+
+class pkgAcquireStatus;
+
+
+bool ListUpdate(pkgAcquireStatus &progress, pkgSourceList &List, int PulseInterval=0);
+bool AcquireUpdate(pkgAcquire &Fetcher, int const PulseInterval = 0,
+ bool const RunUpdateScripts = true, bool const ListCleanup = true);
+
+
+#endif
diff --git a/apt-private/private-update.cc b/apt-private/private-update.cc
index 61259748d..f6c12c26a 100644
--- a/apt-private/private-update.cc
+++ b/apt-private/private-update.cc
@@ -23,6 +23,7 @@
#include <apt-pkg/pkgsystem.h>
#include <apt-pkg/pkgrecords.h>
#include <apt-pkg/indexfile.h>
+#include <apt-pkg/update.h>
#include <sys/types.h>
#include <sys/stat.h>