1 // Include Files /*{{{*/
4 #include <apt-pkg/acquire-item.h>
5 #include <apt-pkg/configuration.h>
6 #include <apt-pkg/error.h>
7 #include <apt-pkg/fileutl.h>
8 #include <apt-pkg/sourcelist.h>
9 #include <apt-pkg/acquire.h>
10 #include <apt-pkg/strutl.h>
11 #include <apt-pkg/update.h>
20 // ListUpdate - construct Fetcher and update the cache files /*{{{*/
21 // ---------------------------------------------------------------------
22 /* This is a simple wrapper to update the cache. it will fetch stuff
23 * from the network (or any other sources defined in sources.list)
25 bool ListUpdate(pkgAcquireStatus
&Stat
,
29 pkgAcquire
Fetcher(&Stat
);
30 if (Fetcher
.GetLock(_config
->FindDir("Dir::State::Lists")) == false)
33 // Populate it with the source selection
34 if (List
.GetIndexes(&Fetcher
) == false)
37 return AcquireUpdate(Fetcher
, PulseInterval
, true);
40 // AcquireUpdate - take Fetcher and update the cache files /*{{{*/
41 // ---------------------------------------------------------------------
42 /* This is a simple wrapper to update the cache with a provided acquire
43 * If you only need control over Status and the used SourcesList use
44 * ListUpdate method instead.
46 bool AcquireUpdate(pkgAcquire
&Fetcher
, int const PulseInterval
,
47 bool const RunUpdateScripts
, bool const ListCleanup
)
50 if (RunUpdateScripts
== true)
51 RunScripts("APT::Update::Pre-Invoke");
53 pkgAcquire::RunResult res
;
55 res
= Fetcher
.Run(PulseInterval
);
59 if (res
== pkgAcquire::Failed
)
63 bool TransientNetworkFailure
= false;
64 for (pkgAcquire::ItemIterator I
= Fetcher
.ItemsBegin();
65 I
!= Fetcher
.ItemsEnd(); ++I
)
67 if ((*I
)->Status
== pkgAcquire::Item::StatDone
)
72 ::URI
uri((*I
)->DescURI());
75 string descUri
= string(uri
);
76 _error
->Warning(_("Failed to fetch %s %s"), descUri
.c_str(),
77 (*I
)->ErrorText
.c_str());
79 if ((*I
)->Status
== pkgAcquire::Item::StatTransientNetworkError
)
81 TransientNetworkFailure
= true;
88 // Clean out any old list files
89 // Keep "APT::Get::List-Cleanup" name for compatibility, but
90 // this is really a global option for the APT library now
91 if (!TransientNetworkFailure
&& !Failed
&& ListCleanup
== true &&
92 (_config
->FindB("APT::Get::List-Cleanup",true) == true &&
93 _config
->FindB("APT::List-Cleanup",true) == true))
95 if (Fetcher
.Clean(_config
->FindDir("Dir::State::lists")) == false ||
96 Fetcher
.Clean(_config
->FindDir("Dir::State::lists") + "partial/") == false)
97 // something went wrong with the clean
101 if (TransientNetworkFailure
== true)
102 _error
->Warning(_("Some index files failed to download. They have been ignored, or old ones used instead."));
103 else if (Failed
== true)
104 return _error
->Error(_("Some index files failed to download. They have been ignored, or old ones used instead."));
107 // Run the success scripts if all was fine
108 if (RunUpdateScripts
== true)
110 if(!TransientNetworkFailure
&& !Failed
)
111 RunScripts("APT::Update::Post-Invoke-Success");
113 // Run the other scripts
114 RunScripts("APT::Update::Post-Invoke");