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>
21 // ListUpdate - construct Fetcher and update the cache files /*{{{*/
22 // ---------------------------------------------------------------------
23 /* This is a simple wrapper to update the cache. it will fetch stuff
24 * from the network (or any other sources defined in sources.list)
26 bool ListUpdate(pkgAcquireStatus
&Stat
,
30 pkgAcquire
Fetcher(&Stat
);
31 if (Fetcher
.GetLock(_config
->FindDir("Dir::State::Lists")) == false)
34 // Populate it with the source selection
35 if (List
.GetIndexes(&Fetcher
) == false)
38 return AcquireUpdate(Fetcher
, PulseInterval
, true);
41 // AcquireUpdate - take Fetcher and update the cache files /*{{{*/
42 // ---------------------------------------------------------------------
43 /* This is a simple wrapper to update the cache with a provided acquire
44 * If you only need control over Status and the used SourcesList use
45 * ListUpdate method instead.
47 bool AcquireUpdate(pkgAcquire
&Fetcher
, int const PulseInterval
,
48 bool const RunUpdateScripts
, bool const ListCleanup
)
51 if (RunUpdateScripts
== true)
52 RunScripts("APT::Update::Pre-Invoke");
54 pkgAcquire::RunResult res
;
56 res
= Fetcher
.Run(PulseInterval
);
60 if (res
== pkgAcquire::Failed
)
64 bool TransientNetworkFailure
= false;
65 for (pkgAcquire::ItemIterator I
= Fetcher
.ItemsBegin();
66 I
!= Fetcher
.ItemsEnd(); ++I
)
68 if ((*I
)->Status
== pkgAcquire::Item::StatDone
)
73 ::URI
uri((*I
)->DescURI());
76 string descUri
= string(uri
);
77 _error
->Warning(_("Failed to fetch %s %s"), descUri
.c_str(),
78 (*I
)->ErrorText
.c_str());
80 if ((*I
)->Status
== pkgAcquire::Item::StatTransientNetworkError
)
82 TransientNetworkFailure
= true;
89 // Clean out any old list files
90 // Keep "APT::Get::List-Cleanup" name for compatibility, but
91 // this is really a global option for the APT library now
92 if (!TransientNetworkFailure
&& !Failed
&& ListCleanup
== true &&
93 (_config
->FindB("APT::Get::List-Cleanup",true) == true &&
94 _config
->FindB("APT::List-Cleanup",true) == true))
96 if (Fetcher
.Clean(_config
->FindDir("Dir::State::lists")) == false ||
97 Fetcher
.Clean(_config
->FindDir("Dir::State::lists") + "partial/") == false)
98 // something went wrong with the clean
102 if (TransientNetworkFailure
== true)
103 _error
->Warning(_("Some index files failed to download. They have been ignored, or old ones used instead."));
104 else if (Failed
== true)
105 return _error
->Error(_("Some index files failed to download. They have been ignored, or old ones used instead."));
108 // Run the success scripts if all was fine
109 if (RunUpdateScripts
== true)
111 if(!TransientNetworkFailure
&& !Failed
)
112 RunScripts("APT::Update::Post-Invoke-Success");
114 // Run the other scripts
115 RunScripts("APT::Update::Post-Invoke");