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