]> git.saurik.com Git - apt.git/blob - apt-pkg/deb/debmetaindex.cc
Fix a segfault in the version merger introduced in the previous patch:
[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 if (*l == "none") continue;
185 debTranslationsIndex i = debTranslationsIndex(URI,Dist,(*I)->Section,(*l).c_str());
186 i.GetIndexes(Owner);
187 }
188 }
189
190 return true;
191 }
192
193 bool debReleaseIndex::IsTrusted() const
194 {
195 string VerifiedSigFile = _config->FindDir("Dir::State::lists") +
196 URItoFileName(MetaIndexURI("Release")) + ".gpg";
197
198 if(_config->FindB("APT::Authentication::TrustCDROM", false))
199 if(URI.substr(0,strlen("cdrom:")) == "cdrom:")
200 return true;
201
202 if (FileExists(VerifiedSigFile))
203 return true;
204 return false;
205 }
206
207 vector <pkgIndexFile *> *debReleaseIndex::GetIndexFiles()
208 {
209 if (Indexes != NULL)
210 return Indexes;
211
212 Indexes = new vector <pkgIndexFile*>;
213 std::vector<std::string> const lang = APT::Configuration::getLanguages(true);
214 for (vector<const debSectionEntry *>::const_iterator I = SectionEntries.begin();
215 I != SectionEntries.end(); I++) {
216 if ((*I)->IsSrc)
217 Indexes->push_back(new debSourcesIndex (URI, Dist, (*I)->Section, IsTrusted()));
218 else
219 {
220 Indexes->push_back(new debPackagesIndex (URI, Dist, (*I)->Section, IsTrusted()));
221
222 for (vector<string>::const_iterator l = lang.begin();
223 l != lang.end(); l++) {
224 if (*l == "none") continue;
225 Indexes->push_back(new debTranslationsIndex(URI,Dist,(*I)->Section,(*l).c_str()));
226 }
227 }
228 }
229
230 return Indexes;
231 }
232
233 void debReleaseIndex::PushSectionEntry(const debSectionEntry *Entry)
234 {
235 SectionEntries.push_back(Entry);
236 }
237
238 debReleaseIndex::debSectionEntry::debSectionEntry (string Section, bool IsSrc): Section(Section)
239 {
240 this->IsSrc = IsSrc;
241 }
242
243 class debSLTypeDebian : public pkgSourceList::Type
244 {
245 protected:
246
247 bool CreateItemInternal(vector<metaIndex *> &List,string URI,
248 string Dist,string Section,
249 bool IsSrc) const
250 {
251 for (vector<metaIndex *>::const_iterator I = List.begin();
252 I != List.end(); I++)
253 {
254 // This check insures that there will be only one Release file
255 // queued for all the Packages files and Sources files it
256 // corresponds to.
257 if (strcmp((*I)->GetType(), "deb") == 0)
258 {
259 debReleaseIndex *Deb = (debReleaseIndex *) (*I);
260 // This check insures that there will be only one Release file
261 // queued for all the Packages files and Sources files it
262 // corresponds to.
263 if (Deb->GetURI() == URI && Deb->GetDist() == Dist)
264 {
265 Deb->PushSectionEntry(new debReleaseIndex::debSectionEntry(Section, IsSrc));
266 return true;
267 }
268 }
269 }
270 // No currently created Release file indexes this entry, so we create a new one.
271 // XXX determine whether this release is trusted or not
272 debReleaseIndex *Deb = new debReleaseIndex(URI,Dist);
273 Deb->PushSectionEntry (new debReleaseIndex::debSectionEntry(Section, IsSrc));
274 List.push_back(Deb);
275 return true;
276 }
277 };
278
279 class debSLTypeDeb : public debSLTypeDebian
280 {
281 public:
282
283 bool CreateItem(vector<metaIndex *> &List,string URI,
284 string Dist,string Section) const
285 {
286 return CreateItemInternal(List, URI, Dist, Section, false);
287 }
288
289 debSLTypeDeb()
290 {
291 Name = "deb";
292 Label = "Standard Debian binary tree";
293 }
294 };
295
296 class debSLTypeDebSrc : public debSLTypeDebian
297 {
298 public:
299
300 bool CreateItem(vector<metaIndex *> &List,string URI,
301 string Dist,string Section) const
302 {
303 return CreateItemInternal(List, URI, Dist, Section, true);
304 }
305
306 debSLTypeDebSrc()
307 {
308 Name = "deb-src";
309 Label = "Standard Debian source tree";
310 }
311 };
312
313 debSLTypeDeb _apt_DebType;
314 debSLTypeDebSrc _apt_DebSrcType;