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