]> git.saurik.com Git - apt.git/blame - apt-pkg/deb/debmetaindex.cc
Removed some debug stuff, corrected the VerifyConfigure calls to VerifyAndConfigure
[apt.git] / apt-pkg / deb / debmetaindex.cc
CommitLineData
7db98ffc
MZ
1// ijones, walters
2
7db98ffc
MZ
3#include <apt-pkg/debmetaindex.h>
4#include <apt-pkg/debindexfile.h>
5#include <apt-pkg/strutl.h>
6#include <apt-pkg/acquire-item.h>
7#include <apt-pkg/configuration.h>
45df0ad2 8#include <apt-pkg/aptconfiguration.h>
7db98ffc
MZ
9#include <apt-pkg/error.h>
10
5dd4c8b8
DK
11#include <set>
12
7db98ffc
MZ
13using namespace std;
14
5dd4c8b8 15string debReleaseIndex::Info(const char *Type, string const &Section, string const &Arch) const
7db98ffc
MZ
16{
17 string Info = ::URI::SiteOnly(URI) + ' ';
18 if (Dist[Dist.size() - 1] == '/')
19 {
20 if (Dist != "/")
21 Info += Dist;
22 }
23 else
5dd4c8b8
DK
24 {
25 Info += Dist + '/' + Section;
ff1ad6fd 26 if (Arch.empty() != true)
5dd4c8b8
DK
27 Info += " " + Arch;
28 }
7db98ffc
MZ
29 Info += " ";
30 Info += Type;
31 return Info;
32}
33
34string debReleaseIndex::MetaIndexInfo(const char *Type) const
35{
36 string Info = ::URI::SiteOnly(URI) + ' ';
37 if (Dist[Dist.size() - 1] == '/')
38 {
39 if (Dist != "/")
40 Info += Dist;
41 }
42 else
43 Info += Dist;
44 Info += " ";
45 Info += Type;
46 return Info;
47}
48
49string debReleaseIndex::MetaIndexFile(const char *Type) const
50{
51 return _config->FindDir("Dir::State::lists") +
52 URItoFileName(MetaIndexURI(Type));
53}
54
55string debReleaseIndex::MetaIndexURI(const char *Type) const
56{
57 string Res;
58
59 if (Dist == "/")
60 Res = URI;
61 else if (Dist[Dist.size()-1] == '/')
62 Res = URI + Dist;
63 else
64 Res = URI + "dists/" + Dist + "/";
65
66 Res += Type;
67 return Res;
68}
69
5dd4c8b8 70string debReleaseIndex::IndexURISuffix(const char *Type, string const &Section, string const &Arch) const
7db98ffc
MZ
71{
72 string Res ="";
73 if (Dist[Dist.size() - 1] != '/')
5dd4c8b8
DK
74 {
75 if (Arch == "native")
76 Res += Section + "/binary-" + _config->Find("APT::Architecture") + '/';
77 else
78 Res += Section + "/binary-" + Arch + '/';
79 }
7db98ffc
MZ
80 return Res + Type;
81}
82
83
5dd4c8b8 84string debReleaseIndex::IndexURI(const char *Type, string const &Section, string const &Arch) const
7db98ffc
MZ
85{
86 if (Dist[Dist.size() - 1] == '/')
87 {
88 string Res;
89 if (Dist != "/")
90 Res = URI + Dist;
91 else
92 Res = URI;
93 return Res + Type;
94 }
95 else
5dd4c8b8 96 return URI + "dists/" + Dist + '/' + IndexURISuffix(Type, Section, Arch);
7db98ffc
MZ
97 }
98
5dd4c8b8 99string debReleaseIndex::SourceIndexURISuffix(const char *Type, const string &Section) const
7db98ffc
MZ
100{
101 string Res ="";
102 if (Dist[Dist.size() - 1] != '/')
103 Res += Section + "/source/";
104 return Res + Type;
105}
106
5dd4c8b8 107string debReleaseIndex::SourceIndexURI(const char *Type, const string &Section) const
7db98ffc
MZ
108{
109 string Res;
110 if (Dist[Dist.size() - 1] == '/')
111 {
112 if (Dist != "/")
113 Res = URI + Dist;
114 else
115 Res = URI;
116 return Res + Type;
117 }
118 else
119 return URI + "dists/" + Dist + "/" + SourceIndexURISuffix(Type, Section);
120}
121
ab53c018
DK
122string debReleaseIndex::TranslationIndexURISuffix(const char *Type, const string &Section) const
123{
124 string Res ="";
125 if (Dist[Dist.size() - 1] != '/')
126 Res += Section + "/i18n/";
127 return Res + Type;
128}
129
130string debReleaseIndex::TranslationIndexURI(const char *Type, const string &Section) const
131{
132 string Res;
133 if (Dist[Dist.size() - 1] == '/')
134 {
135 if (Dist != "/")
136 Res = URI + Dist;
137 else
138 Res = URI;
139 return Res + Type;
140 }
141 else
142 return URI + "dists/" + Dist + "/" + TranslationIndexURISuffix(Type, Section);
143}
144
5dd4c8b8
DK
145debReleaseIndex::debReleaseIndex(string const &URI, string const &Dist) {
146 this->URI = URI;
147 this->Dist = Dist;
148 this->Indexes = NULL;
149 this->Type = "deb";
7db98ffc
MZ
150}
151
5dd4c8b8
DK
152debReleaseIndex::~debReleaseIndex() {
153 for (map<string, vector<debSectionEntry const*> >::const_iterator A = ArchEntries.begin();
154 A != ArchEntries.end(); ++A)
155 for (vector<const debSectionEntry *>::const_iterator S = A->second.begin();
156 S != A->second.end(); ++S)
157 delete *S;
7a9f09bd
MV
158}
159
5dd4c8b8
DK
160vector <struct IndexTarget *>* debReleaseIndex::ComputeIndexTargets() const {
161 vector <struct IndexTarget *>* IndexTargets = new vector <IndexTarget *>;
162
163 map<string, vector<debSectionEntry const*> >::const_iterator const src = ArchEntries.find("source");
164 if (src != ArchEntries.end()) {
165 vector<debSectionEntry const*> const SectionEntries = src->second;
166 for (vector<debSectionEntry const*>::const_iterator I = SectionEntries.begin();
167 I != SectionEntries.end(); ++I) {
168 IndexTarget * Target = new IndexTarget();
169 Target->ShortDesc = "Sources";
170 Target->MetaKey = SourceIndexURISuffix(Target->ShortDesc.c_str(), (*I)->Section);
171 Target->URI = SourceIndexURI(Target->ShortDesc.c_str(), (*I)->Section);
172 Target->Description = Info (Target->ShortDesc.c_str(), (*I)->Section);
173 IndexTargets->push_back (Target);
174 }
175 }
176
177 // Only source release
178 if (IndexTargets->empty() == false && ArchEntries.size() == 1)
179 return IndexTargets;
180
ab53c018 181 std::set<std::string> sections;
5dd4c8b8
DK
182 for (map<string, vector<debSectionEntry const*> >::const_iterator a = ArchEntries.begin();
183 a != ArchEntries.end(); ++a) {
184 if (a->first == "source")
185 continue;
186 for (vector <const debSectionEntry *>::const_iterator I = a->second.begin();
187 I != a->second.end(); ++I) {
188 IndexTarget * Target = new IndexTarget();
189 Target->ShortDesc = "Packages";
190 Target->MetaKey = IndexURISuffix(Target->ShortDesc.c_str(), (*I)->Section, a->first);
191 Target->URI = IndexURI(Target->ShortDesc.c_str(), (*I)->Section, a->first);
192 Target->Description = Info (Target->ShortDesc.c_str(), (*I)->Section, a->first);
193 IndexTargets->push_back (Target);
ab53c018
DK
194 sections.insert((*I)->Section);
195 }
196 }
197
05bb1e5d
DK
198 std::vector<std::string> const lang = APT::Configuration::getLanguages(true);
199 if (lang.empty() == true)
200 return IndexTargets;
201
ab53c018
DK
202 // get the Translations:
203 // - if its a dists-style repository get the i18n/Index first
204 // - if its flat try to acquire files by guessing
205 if (Dist[Dist.size() - 1] == '/') {
ab53c018
DK
206 for (std::set<std::string>::const_iterator s = sections.begin();
207 s != sections.end(); ++s) {
208 for (std::vector<std::string>::const_iterator l = lang.begin();
209 l != lang.end(); l++) {
210 if (*l == "none") continue;
211 IndexTarget * Target = new OptionalIndexTarget();
212 Target->ShortDesc = "Translation-" + *l;
213 Target->MetaKey = TranslationIndexURISuffix(l->c_str(), *s);
214 Target->URI = TranslationIndexURI(l->c_str(), *s);
215 Target->Description = Info (Target->ShortDesc.c_str(), *s);
216 IndexTargets->push_back(Target);
217 }
218 }
219 } else {
220 for (std::set<std::string>::const_iterator s = sections.begin();
221 s != sections.end(); ++s) {
222 IndexTarget * Target = new OptionalIndexTarget();
223 Target->ShortDesc = "TranslationIndex";
224 Target->MetaKey = TranslationIndexURISuffix("Index", *s);
225 Target->URI = TranslationIndexURI("Index", *s);
226 Target->Description = Info (Target->ShortDesc.c_str(), *s);
227 IndexTargets->push_back (Target);
5dd4c8b8
DK
228 }
229 }
230
231 return IndexTargets;
7db98ffc
MZ
232}
233 /*}}}*/
5dd4c8b8 234bool debReleaseIndex::GetIndexes(pkgAcquire *Owner, bool const &GetAll) const
7db98ffc
MZ
235{
236 // special case for --print-uris
237 if (GetAll) {
238 vector <struct IndexTarget *> *targets = ComputeIndexTargets();
239 for (vector <struct IndexTarget*>::const_iterator Target = targets->begin(); Target != targets->end(); Target++) {
240 new pkgAcqIndex(Owner, (*Target)->URI, (*Target)->Description,
495e5cb2 241 (*Target)->ShortDesc, HashString());
7db98ffc
MZ
242 }
243 }
8f9b141f 244
fe0f7911
DK
245 new pkgAcqMetaClearSig(Owner, MetaIndexURI("InRelease"),
246 MetaIndexInfo("InRelease"), "InRelease",
247 MetaIndexURI("Release"), MetaIndexInfo("Release"), "Release",
248 MetaIndexURI("Release.gpg"), MetaIndexInfo("Release.gpg"), "Release.gpg",
249 ComputeIndexTargets(),
250 new indexRecords (Dist));
251
5dd4c8b8 252 return true;
7db98ffc
MZ
253}
254
255bool debReleaseIndex::IsTrusted() const
256{
4e0ad446 257 if(_config->FindB("APT::Authentication::TrustCDROM", false))
e8cdc56a
MV
258 if(URI.substr(0,strlen("cdrom:")) == "cdrom:")
259 return true;
fe0f7911
DK
260
261 string VerifiedSigFile = _config->FindDir("Dir::State::lists") +
262 URItoFileName(MetaIndexURI("Release")) + ".gpg";
263
7db98ffc
MZ
264 if (FileExists(VerifiedSigFile))
265 return true;
fe0f7911
DK
266
267 VerifiedSigFile = _config->FindDir("Dir::State::lists") +
268 URItoFileName(MetaIndexURI("InRelease"));
269
270 return FileExists(VerifiedSigFile);
7db98ffc
MZ
271}
272
5dd4c8b8
DK
273vector <pkgIndexFile *> *debReleaseIndex::GetIndexFiles() {
274 if (Indexes != NULL)
275 return Indexes;
276
277 Indexes = new vector <pkgIndexFile*>;
278 map<string, vector<debSectionEntry const*> >::const_iterator const src = ArchEntries.find("source");
279 if (src != ArchEntries.end()) {
280 vector<debSectionEntry const*> const SectionEntries = src->second;
281 for (vector<debSectionEntry const*>::const_iterator I = SectionEntries.begin();
282 I != SectionEntries.end(); I++)
283 Indexes->push_back(new debSourcesIndex (URI, Dist, (*I)->Section, IsTrusted()));
284 }
285
286 // Only source release
287 if (Indexes->empty() == false && ArchEntries.size() == 1)
288 return Indexes;
289
290 std::vector<std::string> const lang = APT::Configuration::getLanguages(true);
291 map<string, set<string> > sections;
292 for (map<string, vector<debSectionEntry const*> >::const_iterator a = ArchEntries.begin();
293 a != ArchEntries.end(); ++a) {
294 if (a->first == "source")
295 continue;
296 for (vector<debSectionEntry const*>::const_iterator I = a->second.begin();
297 I != a->second.end(); I++) {
298 Indexes->push_back(new debPackagesIndex (URI, Dist, (*I)->Section, IsTrusted(), a->first));
299 sections[(*I)->Section].insert(lang.begin(), lang.end());
300 }
301 }
302
303 for (map<string, set<string> >::const_iterator s = sections.begin();
304 s != sections.end(); ++s)
305 for (set<string>::const_iterator l = s->second.begin();
1a31359b
DK
306 l != s->second.end(); l++) {
307 if (*l == "none") continue;
5dd4c8b8 308 Indexes->push_back(new debTranslationsIndex(URI,Dist,s->first,(*l).c_str()));
1a31359b 309 }
5dd4c8b8
DK
310
311 return Indexes;
312}
a7a5b0d9 313
5dd4c8b8
DK
314void debReleaseIndex::PushSectionEntry(vector<string> const &Archs, const debSectionEntry *Entry) {
315 for (vector<string>::const_iterator a = Archs.begin();
316 a != Archs.end(); ++a)
317 ArchEntries[*a].push_back(new debSectionEntry(Entry->Section, Entry->IsSrc));
318 delete Entry;
7db98ffc
MZ
319}
320
5dd4c8b8
DK
321void debReleaseIndex::PushSectionEntry(string const &Arch, const debSectionEntry *Entry) {
322 ArchEntries[Arch].push_back(Entry);
7db98ffc
MZ
323}
324
5dd4c8b8
DK
325void debReleaseIndex::PushSectionEntry(const debSectionEntry *Entry) {
326 if (Entry->IsSrc == true)
327 PushSectionEntry("source", Entry);
328 else {
329 for (map<string, vector<const debSectionEntry *> >::iterator a = ArchEntries.begin();
330 a != ArchEntries.end(); ++a) {
331 a->second.push_back(Entry);
332 }
333 }
7db98ffc
MZ
334}
335
5dd4c8b8
DK
336debReleaseIndex::debSectionEntry::debSectionEntry (string const &Section,
337 bool const &IsSrc): Section(Section), IsSrc(IsSrc)
338{}
339
7db98ffc
MZ
340class debSLTypeDebian : public pkgSourceList::Type
341{
342 protected:
343
5dd4c8b8
DK
344 bool CreateItemInternal(vector<metaIndex *> &List, string const &URI,
345 string const &Dist, string const &Section,
346 bool const &IsSrc, map<string, string> const &Options) const
7db98ffc 347 {
5dd4c8b8
DK
348 map<string, string>::const_iterator const arch = Options.find("arch");
349 vector<string> const Archs =
3f42500d 350 (arch != Options.end()) ? VectorizeString(arch->second, ',') :
5dd4c8b8
DK
351 APT::Configuration::getArchitectures();
352
353 for (vector<metaIndex *>::const_iterator I = List.begin();
7db98ffc
MZ
354 I != List.end(); I++)
355 {
5dd4c8b8
DK
356 // We only worry about debian entries here
357 if (strcmp((*I)->GetType(), "deb") != 0)
358 continue;
359
360 debReleaseIndex *Deb = (debReleaseIndex *) (*I);
361 /* This check insures that there will be only one Release file
362 queued for all the Packages files and Sources files it
363 corresponds to. */
364 if (Deb->GetURI() == URI && Deb->GetDist() == Dist)
7db98ffc 365 {
5dd4c8b8
DK
366 if (IsSrc == true)
367 Deb->PushSectionEntry("source", new debReleaseIndex::debSectionEntry(Section, IsSrc));
368 else
dd13742e
DK
369 {
370 if (Dist[Dist.size() - 1] == '/')
371 Deb->PushSectionEntry("any", new debReleaseIndex::debSectionEntry(Section, IsSrc));
372 else
373 Deb->PushSectionEntry(Archs, new debReleaseIndex::debSectionEntry(Section, IsSrc));
374 }
5dd4c8b8 375 return true;
7db98ffc
MZ
376 }
377 }
378 // No currently created Release file indexes this entry, so we create a new one.
379 // XXX determine whether this release is trusted or not
5dd4c8b8
DK
380 debReleaseIndex *Deb = new debReleaseIndex(URI, Dist);
381 if (IsSrc == true)
382 Deb->PushSectionEntry ("source", new debReleaseIndex::debSectionEntry(Section, IsSrc));
383 else
dd13742e
DK
384 {
385 if (Dist[Dist.size() - 1] == '/')
386 Deb->PushSectionEntry ("any", new debReleaseIndex::debSectionEntry(Section, IsSrc));
387 else
388 Deb->PushSectionEntry (Archs, new debReleaseIndex::debSectionEntry(Section, IsSrc));
389 }
7db98ffc
MZ
390 List.push_back(Deb);
391 return true;
392 }
393};
394
395class debSLTypeDeb : public debSLTypeDebian
396{
397 public:
398
5dd4c8b8
DK
399 bool CreateItem(vector<metaIndex *> &List, string const &URI,
400 string const &Dist, string const &Section,
401 std::map<string, string> const &Options) const
7db98ffc 402 {
5dd4c8b8 403 return CreateItemInternal(List, URI, Dist, Section, false, Options);
7db98ffc
MZ
404 }
405
406 debSLTypeDeb()
407 {
408 Name = "deb";
409 Label = "Standard Debian binary tree";
410 }
411};
412
413class debSLTypeDebSrc : public debSLTypeDebian
414{
415 public:
416
5dd4c8b8
DK
417 bool CreateItem(vector<metaIndex *> &List, string const &URI,
418 string const &Dist, string const &Section,
419 std::map<string, string> const &Options) const
7db98ffc 420 {
5dd4c8b8 421 return CreateItemInternal(List, URI, Dist, Section, true, Options);
7db98ffc
MZ
422 }
423
424 debSLTypeDebSrc()
425 {
426 Name = "deb-src";
427 Label = "Standard Debian source tree";
428 }
429};
430
431debSLTypeDeb _apt_DebType;
432debSLTypeDebSrc _apt_DebSrcType;