]> git.saurik.com Git - apt.git/blame - apt-pkg/deb/debmetaindex.cc
* merged from the auto-install branch
[apt.git] / apt-pkg / deb / debmetaindex.cc
CommitLineData
7db98ffc
MZ
1// ijones, walters
2
3#ifdef __GNUG__
4#pragma implementation "apt-pkg/debmetaindex.h"
5#endif
6
7#include <apt-pkg/debmetaindex.h>
8#include <apt-pkg/debindexfile.h>
9#include <apt-pkg/strutl.h>
10#include <apt-pkg/acquire-item.h>
11#include <apt-pkg/configuration.h>
12#include <apt-pkg/error.h>
13
14using namespace std;
15
16string debReleaseIndex::Info(const char *Type, const string Section) const
17{
18 string Info = ::URI::SiteOnly(URI) + ' ';
19 if (Dist[Dist.size() - 1] == '/')
20 {
21 if (Dist != "/")
22 Info += Dist;
23 }
24 else
25 Info += Dist + '/' + Section;
26 Info += " ";
27 Info += Type;
28 return Info;
29}
30
31string debReleaseIndex::MetaIndexInfo(const char *Type) const
32{
33 string Info = ::URI::SiteOnly(URI) + ' ';
34 if (Dist[Dist.size() - 1] == '/')
35 {
36 if (Dist != "/")
37 Info += Dist;
38 }
39 else
40 Info += Dist;
41 Info += " ";
42 Info += Type;
43 return Info;
44}
45
46string debReleaseIndex::MetaIndexFile(const char *Type) const
47{
48 return _config->FindDir("Dir::State::lists") +
49 URItoFileName(MetaIndexURI(Type));
50}
51
52string debReleaseIndex::MetaIndexURI(const char *Type) const
53{
54 string Res;
55
56 if (Dist == "/")
57 Res = URI;
58 else if (Dist[Dist.size()-1] == '/')
59 Res = URI + Dist;
60 else
61 Res = URI + "dists/" + Dist + "/";
62
63 Res += Type;
64 return Res;
65}
66
67string debReleaseIndex::IndexURISuffix(const char *Type, const string Section) const
68{
69 string Res ="";
70 if (Dist[Dist.size() - 1] != '/')
71 Res += Section + "/binary-" + _config->Find("APT::Architecture") + '/';
72 return Res + Type;
73}
74
75
76string debReleaseIndex::IndexURI(const char *Type, const string Section) const
77{
78 if (Dist[Dist.size() - 1] == '/')
79 {
80 string Res;
81 if (Dist != "/")
82 Res = URI + Dist;
83 else
84 Res = URI;
85 return Res + Type;
86 }
87 else
88 return URI + "dists/" + Dist + '/' + IndexURISuffix(Type, Section);
89 }
90
91string debReleaseIndex::SourceIndexURISuffix(const char *Type, const string Section) const
92{
93 string Res ="";
94 if (Dist[Dist.size() - 1] != '/')
95 Res += Section + "/source/";
96 return Res + Type;
97}
98
99string debReleaseIndex::SourceIndexURI(const char *Type, const string Section) const
100{
101 string Res;
102 if (Dist[Dist.size() - 1] == '/')
103 {
104 if (Dist != "/")
105 Res = URI + Dist;
106 else
107 Res = URI;
108 return Res + Type;
109 }
110 else
111 return URI + "dists/" + Dist + "/" + SourceIndexURISuffix(Type, Section);
112}
113
114debReleaseIndex::debReleaseIndex(string URI,string Dist)
115{
116 this->URI = URI;
117 this->Dist = Dist;
118 this->Indexes = NULL;
119 this->Type = "deb";
120}
121
122vector <struct IndexTarget *>* debReleaseIndex::ComputeIndexTargets() const
123{
124 vector <struct IndexTarget *>* IndexTargets = new vector <IndexTarget *>;
125 for (vector <const debSectionEntry *>::const_iterator I = SectionEntries.begin();
126 I != SectionEntries.end();
127 I++)
128 {
129 IndexTarget * Target = new IndexTarget();
130 Target->ShortDesc = (*I)->IsSrc ? "Sources" : "Packages";
131 Target->MetaKey
132 = (*I)->IsSrc ? SourceIndexURISuffix(Target->ShortDesc.c_str(), (*I)->Section)
133 : IndexURISuffix(Target->ShortDesc.c_str(), (*I)->Section);
134 Target->URI
135 = (*I)->IsSrc ? SourceIndexURI(Target->ShortDesc.c_str(), (*I)->Section)
136 : IndexURI(Target->ShortDesc.c_str(), (*I)->Section);
137
138 Target->Description = Info (Target->ShortDesc.c_str(), (*I)->Section);
139 IndexTargets->push_back (Target);
140 }
141 return IndexTargets;
142}
143 /*}}}*/
144bool debReleaseIndex::GetIndexes(pkgAcquire *Owner, bool GetAll) const
145{
146 // special case for --print-uris
147 if (GetAll) {
148 vector <struct IndexTarget *> *targets = ComputeIndexTargets();
149 for (vector <struct IndexTarget*>::const_iterator Target = targets->begin(); Target != targets->end(); Target++) {
150 new pkgAcqIndex(Owner, (*Target)->URI, (*Target)->Description,
151 (*Target)->ShortDesc, "");
152 }
153 }
154 new pkgAcqMetaSig(Owner, MetaIndexURI("Release.gpg"),
155 MetaIndexInfo("Release.gpg"), "Release.gpg",
156 MetaIndexURI("Release"), MetaIndexInfo("Release"), "Release",
157 ComputeIndexTargets(),
158 new indexRecords (Dist));
159
97234432
MV
160 // Queue the translations
161 for (vector<const debSectionEntry *>::const_iterator I = SectionEntries.begin();
162 I != SectionEntries.end(); I++) {
163
fb603534
MV
164 if((*I)->IsSrc)
165 continue;
97234432
MV
166 debTranslationsIndex i = debTranslationsIndex(URI,Dist,(*I)->Section);
167 i.GetIndexes(Owner);
168 }
169
7db98ffc
MZ
170 return true;
171}
172
173bool debReleaseIndex::IsTrusted() const
174{
175 string VerifiedSigFile = _config->FindDir("Dir::State::lists") +
176 URItoFileName(MetaIndexURI("Release")) + ".gpg";
177
5d4aff08
MV
178 if(_config->FindB("APT::Authentication::TrustCDROM", false))
179 if(URI.substr(0,strlen("cdrom:")) == "cdrom:")
180 return true;
181
7db98ffc
MZ
182 if (FileExists(VerifiedSigFile))
183 return true;
184 return false;
185}
186
187vector <pkgIndexFile *> *debReleaseIndex::GetIndexFiles()
188{
189 if (Indexes != NULL)
190 return Indexes;
191
192 Indexes = new vector <pkgIndexFile*>;
193 for (vector<const debSectionEntry *>::const_iterator I = SectionEntries.begin();
a7a5b0d9 194 I != SectionEntries.end(); I++) {
7db98ffc
MZ
195 if ((*I)->IsSrc)
196 Indexes->push_back(new debSourcesIndex (URI, Dist, (*I)->Section, IsTrusted()));
197 else
770c32ec 198 {
7db98ffc 199 Indexes->push_back(new debPackagesIndex (URI, Dist, (*I)->Section, IsTrusted()));
770c32ec
MV
200 Indexes->push_back(new debTranslationsIndex(URI, Dist, (*I)->Section));
201 }
a7a5b0d9
OS
202 }
203
7db98ffc
MZ
204 return Indexes;
205}
206
207void debReleaseIndex::PushSectionEntry(const debSectionEntry *Entry)
208{
209 SectionEntries.push_back(Entry);
210}
211
212debReleaseIndex::debSectionEntry::debSectionEntry (string Section, bool IsSrc): Section(Section)
213{
214 this->IsSrc = IsSrc;
215}
216
217class debSLTypeDebian : public pkgSourceList::Type
218{
219 protected:
220
221 bool CreateItemInternal(vector<metaIndex *> &List,string URI,
222 string Dist,string Section,
223 bool IsSrc) const
224 {
225 for (vector<metaIndex *>::const_iterator I = List.begin();
226 I != List.end(); I++)
227 {
228 // This check insures that there will be only one Release file
229 // queued for all the Packages files and Sources files it
230 // corresponds to.
231 if ((*I)->GetType() == "deb")
232 {
233 debReleaseIndex *Deb = (debReleaseIndex *) (*I);
234 // This check insures that there will be only one Release file
235 // queued for all the Packages files and Sources files it
236 // corresponds to.
237 if (Deb->GetURI() == URI && Deb->GetDist() == Dist)
238 {
239 Deb->PushSectionEntry(new debReleaseIndex::debSectionEntry(Section, IsSrc));
240 return true;
241 }
242 }
243 }
244 // No currently created Release file indexes this entry, so we create a new one.
245 // XXX determine whether this release is trusted or not
246 debReleaseIndex *Deb = new debReleaseIndex(URI,Dist);
247 Deb->PushSectionEntry (new debReleaseIndex::debSectionEntry(Section, IsSrc));
248 List.push_back(Deb);
249 return true;
250 }
251};
252
253class debSLTypeDeb : public debSLTypeDebian
254{
255 public:
256
257 bool CreateItem(vector<metaIndex *> &List,string URI,
258 string Dist,string Section) const
259 {
260 return CreateItemInternal(List, URI, Dist, Section, false);
261 }
262
263 debSLTypeDeb()
264 {
265 Name = "deb";
266 Label = "Standard Debian binary tree";
267 }
268};
269
270class debSLTypeDebSrc : public debSLTypeDebian
271{
272 public:
273
274 bool CreateItem(vector<metaIndex *> &List,string URI,
275 string Dist,string Section) const
276 {
277 return CreateItemInternal(List, URI, Dist, Section, true);
278 }
279
280 debSLTypeDebSrc()
281 {
282 Name = "deb-src";
283 Label = "Standard Debian source tree";
284 }
285};
286
287debSLTypeDeb _apt_DebType;
288debSLTypeDebSrc _apt_DebSrcType;