]> git.saurik.com Git - apt.git/blame - apt-pkg/update.cc
ensure Cnf::FindFile doesn't return files below /dev/null
[apt.git] / apt-pkg / update.cc
CommitLineData
d428d131
MV
1// Include Files /*{{{*/
2#include <config.h>
3
d428d131 4#include <apt-pkg/acquire-item.h>
453b82a3
DK
5#include <apt-pkg/configuration.h>
6#include <apt-pkg/error.h>
d428d131 7#include <apt-pkg/fileutl.h>
453b82a3
DK
8#include <apt-pkg/sourcelist.h>
9#include <apt-pkg/acquire.h>
10#include <apt-pkg/strutl.h>
ac7f8f79 11#include <apt-pkg/update.h>
d428d131 12
453b82a3 13#include <string>
d428d131
MV
14
15#include <apti18n.h>
16 /*}}}*/
17
18using namespace std;
19
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)
24 */
25bool ListUpdate(pkgAcquireStatus &Stat,
26 pkgSourceList &List,
27 int PulseInterval)
28{
04a54261
DK
29 pkgAcquire Fetcher(&Stat);
30 if (Fetcher.GetLock(_config->FindDir("Dir::State::Lists")) == false)
d428d131
MV
31 return false;
32
33 // Populate it with the source selection
34 if (List.GetIndexes(&Fetcher) == false)
35 return false;
36
37 return AcquireUpdate(Fetcher, PulseInterval, true);
38}
39 /*}}}*/
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.
45 */
46bool AcquireUpdate(pkgAcquire &Fetcher, int const PulseInterval,
47 bool const RunUpdateScripts, bool const ListCleanup)
48{
49 // Run scripts
50 if (RunUpdateScripts == true)
51 RunScripts("APT::Update::Pre-Invoke");
52
53 pkgAcquire::RunResult res;
54 if(PulseInterval > 0)
55 res = Fetcher.Run(PulseInterval);
56 else
57 res = Fetcher.Run();
58
57f7fb65
DK
59 bool const errorsWereReported = (res == pkgAcquire::Failed);
60 bool Failed = errorsWereReported;
d428d131 61 bool TransientNetworkFailure = false;
35664152 62 bool AllFailed = true;
d428d131
MV
63 for (pkgAcquire::ItemIterator I = Fetcher.ItemsBegin();
64 I != Fetcher.ItemsEnd(); ++I)
65 {
57f7fb65
DK
66 switch ((*I)->Status)
67 {
68 case pkgAcquire::Item::StatDone:
69 AllFailed = false;
70 continue;
71 case pkgAcquire::Item::StatTransientNetworkError:
72 TransientNetworkFailure = true;
73 break;
74 case pkgAcquire::Item::StatIdle:
75 case pkgAcquire::Item::StatFetching:
76 case pkgAcquire::Item::StatError:
77 case pkgAcquire::Item::StatAuthError:
78 Failed = true;
79 break;
35664152 80 }
d428d131
MV
81
82 (*I)->Finished();
83
57f7fb65
DK
84 if (errorsWereReported)
85 continue;
86
d428d131
MV
87 ::URI uri((*I)->DescURI());
88 uri.User.clear();
89 uri.Password.clear();
57f7fb65 90 std::string const descUri = std::string(uri);
f695e761
JAK
91 // Show an error for non-transient failures, otherwise only warn
92 if ((*I)->Status == pkgAcquire::Item::StatTransientNetworkError)
93 _error->Warning(_("Failed to fetch %s %s"), descUri.c_str(),
94 (*I)->ErrorText.c_str());
95 else
96 _error->Error(_("Failed to fetch %s %s"), descUri.c_str(),
97 (*I)->ErrorText.c_str());
d428d131 98 }
57f7fb65 99
d428d131
MV
100 // Clean out any old list files
101 // Keep "APT::Get::List-Cleanup" name for compatibility, but
102 // this is really a global option for the APT library now
103 if (!TransientNetworkFailure && !Failed && ListCleanup == true &&
104 (_config->FindB("APT::Get::List-Cleanup",true) == true &&
105 _config->FindB("APT::List-Cleanup",true) == true))
106 {
107 if (Fetcher.Clean(_config->FindDir("Dir::State::lists")) == false ||
108 Fetcher.Clean(_config->FindDir("Dir::State::lists") + "partial/") == false)
109 // something went wrong with the clean
110 return false;
111 }
35664152
JAK
112
113 bool Res = true;
57f7fb65
DK
114
115 if (errorsWereReported == true)
116 Res = false;
117 else if (TransientNetworkFailure == true)
35664152 118 Res = _error->Warning(_("Some index files failed to download. They have been ignored, or old ones used instead."));
d428d131 119 else if (Failed == true)
35664152 120 Res = _error->Error(_("Some index files failed to download. They have been ignored, or old ones used instead."));
d428d131 121
d428d131
MV
122 // Run the success scripts if all was fine
123 if (RunUpdateScripts == true)
124 {
35664152 125 if(AllFailed == false)
d428d131
MV
126 RunScripts("APT::Update::Post-Invoke-Success");
127
128 // Run the other scripts
129 RunScripts("APT::Update::Post-Invoke");
130 }
35664152 131 return Res;
d428d131
MV
132}
133 /*}}}*/