]>
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 DK |
11 | #include <set> |
12 | ||
7db98ffc MZ |
13 | using namespace std; |
14 | ||
5dd4c8b8 | 15 | string 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 | ||
34 | string 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 | ||
49 | string debReleaseIndex::MetaIndexFile(const char *Type) const | |
50 | { | |
51 | return _config->FindDir("Dir::State::lists") + | |
52 | URItoFileName(MetaIndexURI(Type)); | |
53 | } | |
54 | ||
55 | string 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 | 70 | string 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 | 84 | string 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 | 99 | string 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 | 107 | string 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 | ||
5dd4c8b8 DK |
122 | debReleaseIndex::debReleaseIndex(string const &URI, string const &Dist) { |
123 | this->URI = URI; | |
124 | this->Dist = Dist; | |
125 | this->Indexes = NULL; | |
126 | this->Type = "deb"; | |
7db98ffc MZ |
127 | } |
128 | ||
5dd4c8b8 DK |
129 | debReleaseIndex::~debReleaseIndex() { |
130 | for (map<string, vector<debSectionEntry const*> >::const_iterator A = ArchEntries.begin(); | |
131 | A != ArchEntries.end(); ++A) | |
132 | for (vector<const debSectionEntry *>::const_iterator S = A->second.begin(); | |
133 | S != A->second.end(); ++S) | |
134 | delete *S; | |
7a9f09bd MV |
135 | } |
136 | ||
5dd4c8b8 DK |
137 | vector <struct IndexTarget *>* debReleaseIndex::ComputeIndexTargets() const { |
138 | vector <struct IndexTarget *>* IndexTargets = new vector <IndexTarget *>; | |
139 | ||
140 | map<string, vector<debSectionEntry const*> >::const_iterator const src = ArchEntries.find("source"); | |
141 | if (src != ArchEntries.end()) { | |
142 | vector<debSectionEntry const*> const SectionEntries = src->second; | |
143 | for (vector<debSectionEntry const*>::const_iterator I = SectionEntries.begin(); | |
144 | I != SectionEntries.end(); ++I) { | |
145 | IndexTarget * Target = new IndexTarget(); | |
146 | Target->ShortDesc = "Sources"; | |
147 | Target->MetaKey = SourceIndexURISuffix(Target->ShortDesc.c_str(), (*I)->Section); | |
148 | Target->URI = SourceIndexURI(Target->ShortDesc.c_str(), (*I)->Section); | |
149 | Target->Description = Info (Target->ShortDesc.c_str(), (*I)->Section); | |
150 | IndexTargets->push_back (Target); | |
151 | } | |
152 | } | |
153 | ||
154 | // Only source release | |
155 | if (IndexTargets->empty() == false && ArchEntries.size() == 1) | |
156 | return IndexTargets; | |
157 | ||
158 | for (map<string, vector<debSectionEntry const*> >::const_iterator a = ArchEntries.begin(); | |
159 | a != ArchEntries.end(); ++a) { | |
160 | if (a->first == "source") | |
161 | continue; | |
162 | for (vector <const debSectionEntry *>::const_iterator I = a->second.begin(); | |
163 | I != a->second.end(); ++I) { | |
164 | IndexTarget * Target = new IndexTarget(); | |
165 | Target->ShortDesc = "Packages"; | |
166 | Target->MetaKey = IndexURISuffix(Target->ShortDesc.c_str(), (*I)->Section, a->first); | |
167 | Target->URI = IndexURI(Target->ShortDesc.c_str(), (*I)->Section, a->first); | |
168 | Target->Description = Info (Target->ShortDesc.c_str(), (*I)->Section, a->first); | |
169 | IndexTargets->push_back (Target); | |
170 | } | |
171 | } | |
172 | ||
173 | return IndexTargets; | |
7db98ffc MZ |
174 | } |
175 | /*}}}*/ | |
5dd4c8b8 | 176 | bool debReleaseIndex::GetIndexes(pkgAcquire *Owner, bool const &GetAll) const |
7db98ffc MZ |
177 | { |
178 | // special case for --print-uris | |
179 | if (GetAll) { | |
180 | vector <struct IndexTarget *> *targets = ComputeIndexTargets(); | |
181 | for (vector <struct IndexTarget*>::const_iterator Target = targets->begin(); Target != targets->end(); Target++) { | |
182 | new pkgAcqIndex(Owner, (*Target)->URI, (*Target)->Description, | |
495e5cb2 | 183 | (*Target)->ShortDesc, HashString()); |
7db98ffc MZ |
184 | } |
185 | } | |
8f9b141f | 186 | |
fe0f7911 DK |
187 | new pkgAcqMetaClearSig(Owner, MetaIndexURI("InRelease"), |
188 | MetaIndexInfo("InRelease"), "InRelease", | |
189 | MetaIndexURI("Release"), MetaIndexInfo("Release"), "Release", | |
190 | MetaIndexURI("Release.gpg"), MetaIndexInfo("Release.gpg"), "Release.gpg", | |
191 | ComputeIndexTargets(), | |
192 | new indexRecords (Dist)); | |
193 | ||
7db98ffc | 194 | |
5dd4c8b8 DK |
195 | // Queue the translations |
196 | std::vector<std::string> const lang = APT::Configuration::getLanguages(true); | |
197 | map<string, set<string> > sections; | |
198 | for (map<string, vector<debSectionEntry const*> >::const_iterator a = ArchEntries.begin(); | |
199 | a != ArchEntries.end(); ++a) { | |
200 | if (a->first == "source") | |
201 | continue; | |
202 | for (vector<debSectionEntry const*>::const_iterator I = a->second.begin(); | |
203 | I != a->second.end(); I++) | |
204 | sections[(*I)->Section].insert(lang.begin(), lang.end()); | |
205 | } | |
206 | ||
207 | for (map<string, set<string> >::const_iterator s = sections.begin(); | |
208 | s != sections.end(); ++s) | |
209 | for (set<string>::const_iterator l = s->second.begin(); | |
210 | l != s->second.end(); l++) { | |
1a31359b | 211 | if (*l == "none") continue; |
5dd4c8b8 DK |
212 | debTranslationsIndex i = debTranslationsIndex(URI,Dist,s->first,(*l).c_str()); |
213 | i.GetIndexes(Owner); | |
214 | } | |
215 | ||
216 | return true; | |
7db98ffc MZ |
217 | } |
218 | ||
219 | bool debReleaseIndex::IsTrusted() const | |
220 | { | |
4e0ad446 | 221 | if(_config->FindB("APT::Authentication::TrustCDROM", false)) |
e8cdc56a MV |
222 | if(URI.substr(0,strlen("cdrom:")) == "cdrom:") |
223 | return true; | |
fe0f7911 DK |
224 | |
225 | string VerifiedSigFile = _config->FindDir("Dir::State::lists") + | |
226 | URItoFileName(MetaIndexURI("Release")) + ".gpg"; | |
227 | ||
7db98ffc MZ |
228 | if (FileExists(VerifiedSigFile)) |
229 | return true; | |
fe0f7911 DK |
230 | |
231 | VerifiedSigFile = _config->FindDir("Dir::State::lists") + | |
232 | URItoFileName(MetaIndexURI("InRelease")); | |
233 | ||
234 | return FileExists(VerifiedSigFile); | |
7db98ffc MZ |
235 | } |
236 | ||
5dd4c8b8 DK |
237 | vector <pkgIndexFile *> *debReleaseIndex::GetIndexFiles() { |
238 | if (Indexes != NULL) | |
239 | return Indexes; | |
240 | ||
241 | Indexes = new vector <pkgIndexFile*>; | |
242 | map<string, vector<debSectionEntry const*> >::const_iterator const src = ArchEntries.find("source"); | |
243 | if (src != ArchEntries.end()) { | |
244 | vector<debSectionEntry const*> const SectionEntries = src->second; | |
245 | for (vector<debSectionEntry const*>::const_iterator I = SectionEntries.begin(); | |
246 | I != SectionEntries.end(); I++) | |
247 | Indexes->push_back(new debSourcesIndex (URI, Dist, (*I)->Section, IsTrusted())); | |
248 | } | |
249 | ||
250 | // Only source release | |
251 | if (Indexes->empty() == false && ArchEntries.size() == 1) | |
252 | return Indexes; | |
253 | ||
254 | std::vector<std::string> const lang = APT::Configuration::getLanguages(true); | |
255 | map<string, set<string> > sections; | |
256 | for (map<string, vector<debSectionEntry const*> >::const_iterator a = ArchEntries.begin(); | |
257 | a != ArchEntries.end(); ++a) { | |
258 | if (a->first == "source") | |
259 | continue; | |
260 | for (vector<debSectionEntry const*>::const_iterator I = a->second.begin(); | |
261 | I != a->second.end(); I++) { | |
262 | Indexes->push_back(new debPackagesIndex (URI, Dist, (*I)->Section, IsTrusted(), a->first)); | |
263 | sections[(*I)->Section].insert(lang.begin(), lang.end()); | |
264 | } | |
265 | } | |
266 | ||
267 | for (map<string, set<string> >::const_iterator s = sections.begin(); | |
268 | s != sections.end(); ++s) | |
269 | for (set<string>::const_iterator l = s->second.begin(); | |
1a31359b DK |
270 | l != s->second.end(); l++) { |
271 | if (*l == "none") continue; | |
5dd4c8b8 | 272 | Indexes->push_back(new debTranslationsIndex(URI,Dist,s->first,(*l).c_str())); |
1a31359b | 273 | } |
5dd4c8b8 DK |
274 | |
275 | return Indexes; | |
276 | } | |
a7a5b0d9 | 277 | |
5dd4c8b8 DK |
278 | void debReleaseIndex::PushSectionEntry(vector<string> const &Archs, const debSectionEntry *Entry) { |
279 | for (vector<string>::const_iterator a = Archs.begin(); | |
280 | a != Archs.end(); ++a) | |
281 | ArchEntries[*a].push_back(new debSectionEntry(Entry->Section, Entry->IsSrc)); | |
282 | delete Entry; | |
7db98ffc MZ |
283 | } |
284 | ||
5dd4c8b8 DK |
285 | void debReleaseIndex::PushSectionEntry(string const &Arch, const debSectionEntry *Entry) { |
286 | ArchEntries[Arch].push_back(Entry); | |
7db98ffc MZ |
287 | } |
288 | ||
5dd4c8b8 DK |
289 | void debReleaseIndex::PushSectionEntry(const debSectionEntry *Entry) { |
290 | if (Entry->IsSrc == true) | |
291 | PushSectionEntry("source", Entry); | |
292 | else { | |
293 | for (map<string, vector<const debSectionEntry *> >::iterator a = ArchEntries.begin(); | |
294 | a != ArchEntries.end(); ++a) { | |
295 | a->second.push_back(Entry); | |
296 | } | |
297 | } | |
7db98ffc MZ |
298 | } |
299 | ||
5dd4c8b8 DK |
300 | debReleaseIndex::debSectionEntry::debSectionEntry (string const &Section, |
301 | bool const &IsSrc): Section(Section), IsSrc(IsSrc) | |
302 | {} | |
303 | ||
7db98ffc MZ |
304 | class debSLTypeDebian : public pkgSourceList::Type |
305 | { | |
306 | protected: | |
307 | ||
5dd4c8b8 DK |
308 | bool CreateItemInternal(vector<metaIndex *> &List, string const &URI, |
309 | string const &Dist, string const &Section, | |
310 | bool const &IsSrc, map<string, string> const &Options) const | |
7db98ffc | 311 | { |
5dd4c8b8 DK |
312 | map<string, string>::const_iterator const arch = Options.find("arch"); |
313 | vector<string> const Archs = | |
3f42500d | 314 | (arch != Options.end()) ? VectorizeString(arch->second, ',') : |
5dd4c8b8 DK |
315 | APT::Configuration::getArchitectures(); |
316 | ||
317 | for (vector<metaIndex *>::const_iterator I = List.begin(); | |
7db98ffc MZ |
318 | I != List.end(); I++) |
319 | { | |
5dd4c8b8 DK |
320 | // We only worry about debian entries here |
321 | if (strcmp((*I)->GetType(), "deb") != 0) | |
322 | continue; | |
323 | ||
324 | debReleaseIndex *Deb = (debReleaseIndex *) (*I); | |
325 | /* This check insures that there will be only one Release file | |
326 | queued for all the Packages files and Sources files it | |
327 | corresponds to. */ | |
328 | if (Deb->GetURI() == URI && Deb->GetDist() == Dist) | |
7db98ffc | 329 | { |
5dd4c8b8 DK |
330 | if (IsSrc == true) |
331 | Deb->PushSectionEntry("source", new debReleaseIndex::debSectionEntry(Section, IsSrc)); | |
332 | else | |
dd13742e DK |
333 | { |
334 | if (Dist[Dist.size() - 1] == '/') | |
335 | Deb->PushSectionEntry("any", new debReleaseIndex::debSectionEntry(Section, IsSrc)); | |
336 | else | |
337 | Deb->PushSectionEntry(Archs, new debReleaseIndex::debSectionEntry(Section, IsSrc)); | |
338 | } | |
5dd4c8b8 | 339 | return true; |
7db98ffc MZ |
340 | } |
341 | } | |
342 | // No currently created Release file indexes this entry, so we create a new one. | |
343 | // XXX determine whether this release is trusted or not | |
5dd4c8b8 DK |
344 | debReleaseIndex *Deb = new debReleaseIndex(URI, Dist); |
345 | if (IsSrc == true) | |
346 | Deb->PushSectionEntry ("source", new debReleaseIndex::debSectionEntry(Section, IsSrc)); | |
347 | else | |
dd13742e DK |
348 | { |
349 | if (Dist[Dist.size() - 1] == '/') | |
350 | Deb->PushSectionEntry ("any", new debReleaseIndex::debSectionEntry(Section, IsSrc)); | |
351 | else | |
352 | Deb->PushSectionEntry (Archs, new debReleaseIndex::debSectionEntry(Section, IsSrc)); | |
353 | } | |
7db98ffc MZ |
354 | List.push_back(Deb); |
355 | return true; | |
356 | } | |
357 | }; | |
358 | ||
359 | class debSLTypeDeb : public debSLTypeDebian | |
360 | { | |
361 | public: | |
362 | ||
5dd4c8b8 DK |
363 | bool CreateItem(vector<metaIndex *> &List, string const &URI, |
364 | string const &Dist, string const &Section, | |
365 | std::map<string, string> const &Options) const | |
7db98ffc | 366 | { |
5dd4c8b8 | 367 | return CreateItemInternal(List, URI, Dist, Section, false, Options); |
7db98ffc MZ |
368 | } |
369 | ||
370 | debSLTypeDeb() | |
371 | { | |
372 | Name = "deb"; | |
373 | Label = "Standard Debian binary tree"; | |
374 | } | |
375 | }; | |
376 | ||
377 | class debSLTypeDebSrc : public debSLTypeDebian | |
378 | { | |
379 | public: | |
380 | ||
5dd4c8b8 DK |
381 | bool CreateItem(vector<metaIndex *> &List, string const &URI, |
382 | string const &Dist, string const &Section, | |
383 | std::map<string, string> const &Options) const | |
7db98ffc | 384 | { |
5dd4c8b8 | 385 | return CreateItemInternal(List, URI, Dist, Section, true, Options); |
7db98ffc MZ |
386 | } |
387 | ||
388 | debSLTypeDebSrc() | |
389 | { | |
390 | Name = "deb-src"; | |
391 | Label = "Standard Debian source tree"; | |
392 | } | |
393 | }; | |
394 | ||
395 | debSLTypeDeb _apt_DebType; | |
396 | debSLTypeDebSrc _apt_DebSrcType; |