]> git.saurik.com Git - apt.git/blob - apt-pkg/update.cc
support Signed-By in Release files as a sort of HPKP
[apt.git] / apt-pkg / update.cc
1 // Include Files /*{{{*/
2 #include <config.h>
3
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>
12
13 #include <string>
14
15 #include <apti18n.h>
16 /*}}}*/
17
18 using 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 */
25 bool ListUpdate(pkgAcquireStatus &Stat,
26 pkgSourceList &List,
27 int PulseInterval)
28 {
29 pkgAcquire Fetcher(&Stat);
30 if (Fetcher.GetLock(_config->FindDir("Dir::State::Lists")) == false)
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 */
46 bool 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
59 if (res == pkgAcquire::Failed)
60 return false;
61
62 bool Failed = false;
63 bool TransientNetworkFailure = false;
64 for (pkgAcquire::ItemIterator I = Fetcher.ItemsBegin();
65 I != Fetcher.ItemsEnd(); ++I)
66 {
67 if ((*I)->Status == pkgAcquire::Item::StatDone)
68 continue;
69
70 (*I)->Finished();
71
72 ::URI uri((*I)->DescURI());
73 uri.User.clear();
74 uri.Password.clear();
75 string descUri = string(uri);
76 // Show an error for non-transient failures, otherwise only warn
77 if ((*I)->Status == pkgAcquire::Item::StatTransientNetworkError)
78 _error->Warning(_("Failed to fetch %s %s"), descUri.c_str(),
79 (*I)->ErrorText.c_str());
80 else
81 _error->Error(_("Failed to fetch %s %s"), descUri.c_str(),
82 (*I)->ErrorText.c_str());
83 if ((*I)->Status == pkgAcquire::Item::StatTransientNetworkError)
84 {
85 TransientNetworkFailure = true;
86 continue;
87 }
88
89 Failed = true;
90 }
91
92 // Clean out any old list files
93 // Keep "APT::Get::List-Cleanup" name for compatibility, but
94 // this is really a global option for the APT library now
95 if (!TransientNetworkFailure && !Failed && ListCleanup == true &&
96 (_config->FindB("APT::Get::List-Cleanup",true) == true &&
97 _config->FindB("APT::List-Cleanup",true) == true))
98 {
99 if (Fetcher.Clean(_config->FindDir("Dir::State::lists")) == false ||
100 Fetcher.Clean(_config->FindDir("Dir::State::lists") + "partial/") == false)
101 // something went wrong with the clean
102 return false;
103 }
104
105 if (TransientNetworkFailure == true)
106 _error->Warning(_("Some index files failed to download. They have been ignored, or old ones used instead."));
107 else if (Failed == true)
108 return _error->Error(_("Some index files failed to download. They have been ignored, or old ones used instead."));
109
110
111 // Run the success scripts if all was fine
112 if (RunUpdateScripts == true)
113 {
114 if(!TransientNetworkFailure && !Failed)
115 RunScripts("APT::Update::Post-Invoke-Success");
116
117 // Run the other scripts
118 RunScripts("APT::Update::Post-Invoke");
119 }
120 return true;
121 }
122 /*}}}*/