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>
19 // ListUpdate - construct Fetcher and update the cache files /*{{{*/
20 // ---------------------------------------------------------------------
21 /* This is a simple wrapper to update the cache. it will fetch stuff
22 * from the network (or any other sources defined in sources.list)
24 bool ListUpdate(pkgAcquireStatus
&Stat
,
28 pkgAcquire
Fetcher(&Stat
);
29 if (Fetcher
.GetLock(_config
->FindDir("Dir::State::Lists")) == false)
32 // Populate it with the source selection
33 if (List
.GetIndexes(&Fetcher
) == false)
36 return AcquireUpdate(Fetcher
, PulseInterval
, true);
39 // AcquireUpdate - take Fetcher and update the cache files /*{{{*/
40 // ---------------------------------------------------------------------
41 /* This is a simple wrapper to update the cache with a provided acquire
42 * If you only need control over Status and the used SourcesList use
43 * ListUpdate method instead.
45 bool AcquireUpdate(pkgAcquire
&Fetcher
, int const PulseInterval
,
46 bool const RunUpdateScripts
, bool const ListCleanup
)
49 if (RunUpdateScripts
== true)
50 RunScripts("APT::Update::Pre-Invoke");
52 pkgAcquire::RunResult res
;
54 res
= Fetcher
.Run(PulseInterval
);
58 if (res
== pkgAcquire::Failed
)
62 bool TransientNetworkFailure
= false;
63 for (pkgAcquire::ItemIterator I
= Fetcher
.ItemsBegin();
64 I
!= Fetcher
.ItemsEnd(); ++I
)
66 if ((*I
)->Status
== pkgAcquire::Item::StatDone
)
71 ::URI
uri((*I
)->DescURI());
74 string descUri
= string(uri
);
75 _error
->Warning(_("Failed to fetch %s %s"), descUri
.c_str(),
76 (*I
)->ErrorText
.c_str());
78 if ((*I
)->Status
== pkgAcquire::Item::StatTransientNetworkError
)
80 TransientNetworkFailure
= true;
87 // Clean out any old list files
88 // Keep "APT::Get::List-Cleanup" name for compatibility, but
89 // this is really a global option for the APT library now
90 if (!TransientNetworkFailure
&& !Failed
&& ListCleanup
== true &&
91 (_config
->FindB("APT::Get::List-Cleanup",true) == true &&
92 _config
->FindB("APT::List-Cleanup",true) == true))
94 if (Fetcher
.Clean(_config
->FindDir("Dir::State::lists")) == false ||
95 Fetcher
.Clean(_config
->FindDir("Dir::State::lists") + "partial/") == false)
96 // something went wrong with the clean
100 if (TransientNetworkFailure
== true)
101 _error
->Warning(_("Some index files failed to download. They have been ignored, or old ones used instead."));
102 else if (Failed
== true)
103 return _error
->Error(_("Some index files failed to download. They have been ignored, or old ones used instead."));
106 // Run the success scripts if all was fine
107 if (RunUpdateScripts
== true)
109 if(!TransientNetworkFailure
&& !Failed
)
110 RunScripts("APT::Update::Post-Invoke-Success");
112 // Run the other scripts
113 RunScripts("APT::Update::Post-Invoke");