2
// Include Files /*{{{*/
5
#include <apt-pkg/algorithms.h>
6
#include <apt-pkg/update.h>
7
#include <apt-pkg/error.h>
8
#include <apt-pkg/configuration.h>
9
#include <apt-pkg/version.h>
10
#include <apt-pkg/sptr.h>
11
#include <apt-pkg/acquire-item.h>
12
#include <apt-pkg/edsp.h>
13
#include <apt-pkg/sourcelist.h>
14
#include <apt-pkg/fileutl.h>
15
#include <apt-pkg/progress.h>
17
#include <sys/types.h>
28
// ListUpdate - construct Fetcher and update the cache files /*{{{*/
29
// ---------------------------------------------------------------------
30
/* This is a simple wrapper to update the cache. it will fetch stuff
31
* from the network (or any other sources defined in sources.list)
33
bool ListUpdate(pkgAcquireStatus &Stat,
38
if (Fetcher.Setup(&Stat, _config->FindDir("Dir::State::Lists")) == false)
41
// Populate it with the source selection
42
if (List.GetIndexes(&Fetcher) == false)
45
return AcquireUpdate(Fetcher, PulseInterval, true);
48
// AcquireUpdate - take Fetcher and update the cache files /*{{{*/
49
// ---------------------------------------------------------------------
50
/* This is a simple wrapper to update the cache with a provided acquire
51
* If you only need control over Status and the used SourcesList use
52
* ListUpdate method instead.
54
bool AcquireUpdate(pkgAcquire &Fetcher, int const PulseInterval,
55
bool const RunUpdateScripts, bool const ListCleanup)
58
if (RunUpdateScripts == true)
59
RunScripts("APT::Update::Pre-Invoke");
61
pkgAcquire::RunResult res;
63
res = Fetcher.Run(PulseInterval);
67
if (res == pkgAcquire::Failed)
71
bool TransientNetworkFailure = false;
72
for (pkgAcquire::ItemIterator I = Fetcher.ItemsBegin();
73
I != Fetcher.ItemsEnd(); ++I)
75
if ((*I)->Status == pkgAcquire::Item::StatDone)
80
::URI uri((*I)->DescURI());
83
string descUri = string(uri);
84
_error->Warning(_("Failed to fetch %s %s\n"), descUri.c_str(),
85
(*I)->ErrorText.c_str());
87
if ((*I)->Status == pkgAcquire::Item::StatTransientNetworkError)
89
TransientNetworkFailure = true;
96
// Clean out any old list files
97
// Keep "APT::Get::List-Cleanup" name for compatibility, but
98
// this is really a global option for the APT library now
99
if (!TransientNetworkFailure && !Failed && ListCleanup == true &&
100
(_config->FindB("APT::Get::List-Cleanup",true) == true &&
101
_config->FindB("APT::List-Cleanup",true) == true))
103
if (Fetcher.Clean(_config->FindDir("Dir::State::lists")) == false ||
104
Fetcher.Clean(_config->FindDir("Dir::State::lists") + "partial/") == false)
105
// something went wrong with the clean
109
if (TransientNetworkFailure == true)
110
_error->Warning(_("Some index files failed to download. They have been ignored, or old ones used instead."));
111
else if (Failed == true)
112
return _error->Error(_("Some index files failed to download. They have been ignored, or old ones used instead."));
115
// Run the success scripts if all was fine
116
if (RunUpdateScripts == true)
118
if(!TransientNetworkFailure && !Failed)
119
RunScripts("APT::Update::Post-Invoke-Success");
121
// Run the other scripts
122
RunScripts("APT::Update::Post-Invoke");