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