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