]> git.saurik.com Git - apt.git/blob - apt-pkg/deb/debmetaindex.cc
* cmdline/apt-key:
[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/error.h>
9
10 using namespace std;
11
12 string 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
27 string 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
42 string debReleaseIndex::MetaIndexFile(const char *Type) const
43 {
44 return _config->FindDir("Dir::State::lists") +
45 URItoFileName(MetaIndexURI(Type));
46 }
47
48 string 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
63 string 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
72 string 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
87 string 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
95 string 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
110 debReleaseIndex::debReleaseIndex(string URI,string Dist)
111 {
112 this->URI = URI;
113 this->Dist = Dist;
114 this->Indexes = NULL;
115 this->Type = "deb";
116 }
117
118 vector <struct IndexTarget *>* debReleaseIndex::ComputeIndexTargets() const
119 {
120 vector <struct IndexTarget *>* IndexTargets = new vector <IndexTarget *>;
121 for (vector <const debSectionEntry *>::const_iterator I = SectionEntries.begin();
122 I != SectionEntries.end();
123 I++)
124 {
125 IndexTarget * Target = new IndexTarget();
126 Target->ShortDesc = (*I)->IsSrc ? "Sources" : "Packages";
127 Target->MetaKey
128 = (*I)->IsSrc ? SourceIndexURISuffix(Target->ShortDesc.c_str(), (*I)->Section)
129 : IndexURISuffix(Target->ShortDesc.c_str(), (*I)->Section);
130 Target->URI
131 = (*I)->IsSrc ? SourceIndexURI(Target->ShortDesc.c_str(), (*I)->Section)
132 : IndexURI(Target->ShortDesc.c_str(), (*I)->Section);
133
134 Target->Description = Info (Target->ShortDesc.c_str(), (*I)->Section);
135 IndexTargets->push_back (Target);
136 }
137 return IndexTargets;
138 }
139 /*}}}*/
140 bool debReleaseIndex::GetIndexes(pkgAcquire *Owner, bool GetAll) const
141 {
142 // special case for --print-uris
143 if (GetAll) {
144 vector <struct IndexTarget *> *targets = ComputeIndexTargets();
145 for (vector <struct IndexTarget*>::const_iterator Target = targets->begin(); Target != targets->end(); Target++) {
146 new pkgAcqIndex(Owner, (*Target)->URI, (*Target)->Description,
147 (*Target)->ShortDesc, HashString());
148 }
149 // this is normally created in pkgAcqMetaSig, but if we run
150 // in --print-uris mode, we add it here
151 new pkgAcqMetaIndex(Owner, MetaIndexURI("Release"),
152 MetaIndexInfo("Release"), "Release",
153 MetaIndexURI("Release.gpg"),
154 ComputeIndexTargets(),
155 new indexRecords (Dist));
156
157 }
158
159 new pkgAcqMetaSig(Owner, MetaIndexURI("Release.gpg"),
160 MetaIndexInfo("Release.gpg"), "Release.gpg",
161 MetaIndexURI("Release"), MetaIndexInfo("Release"), "Release",
162 ComputeIndexTargets(),
163 new indexRecords (Dist));
164
165 // Queue the translations
166 for (vector<const debSectionEntry *>::const_iterator I = SectionEntries.begin();
167 I != SectionEntries.end(); I++) {
168
169 if((*I)->IsSrc)
170 continue;
171 debTranslationsIndex i = debTranslationsIndex(URI,Dist,(*I)->Section);
172 i.GetIndexes(Owner);
173 }
174
175 return true;
176 }
177
178 bool debReleaseIndex::IsTrusted() const
179 {
180 string VerifiedSigFile = _config->FindDir("Dir::State::lists") +
181 URItoFileName(MetaIndexURI("Release")) + ".gpg";
182
183 if(_config->FindB("APT::Authentication::TrustCDROM", false))
184 if(URI.substr(0,strlen("cdrom:")) == "cdrom:")
185 return true;
186
187 if (FileExists(VerifiedSigFile))
188 return true;
189 return false;
190 }
191
192 vector <pkgIndexFile *> *debReleaseIndex::GetIndexFiles()
193 {
194 if (Indexes != NULL)
195 return Indexes;
196
197 Indexes = new vector <pkgIndexFile*>;
198 for (vector<const debSectionEntry *>::const_iterator I = SectionEntries.begin();
199 I != SectionEntries.end(); I++) {
200 if ((*I)->IsSrc)
201 Indexes->push_back(new debSourcesIndex (URI, Dist, (*I)->Section, IsTrusted()));
202 else
203 {
204 Indexes->push_back(new debPackagesIndex (URI, Dist, (*I)->Section, IsTrusted()));
205 Indexes->push_back(new debTranslationsIndex(URI, Dist, (*I)->Section));
206 }
207 }
208
209 return Indexes;
210 }
211
212 void debReleaseIndex::PushSectionEntry(const debSectionEntry *Entry)
213 {
214 SectionEntries.push_back(Entry);
215 }
216
217 debReleaseIndex::debSectionEntry::debSectionEntry (string Section, bool IsSrc): Section(Section)
218 {
219 this->IsSrc = IsSrc;
220 }
221
222 class debSLTypeDebian : public pkgSourceList::Type
223 {
224 protected:
225
226 bool CreateItemInternal(vector<metaIndex *> &List,string URI,
227 string Dist,string Section,
228 bool IsSrc) const
229 {
230 for (vector<metaIndex *>::const_iterator I = List.begin();
231 I != List.end(); I++)
232 {
233 // This check insures that there will be only one Release file
234 // queued for all the Packages files and Sources files it
235 // corresponds to.
236 if (strcmp((*I)->GetType(), "deb") == 0)
237 {
238 debReleaseIndex *Deb = (debReleaseIndex *) (*I);
239 // This check insures that there will be only one Release file
240 // queued for all the Packages files and Sources files it
241 // corresponds to.
242 if (Deb->GetURI() == URI && Deb->GetDist() == Dist)
243 {
244 Deb->PushSectionEntry(new debReleaseIndex::debSectionEntry(Section, IsSrc));
245 return true;
246 }
247 }
248 }
249 // No currently created Release file indexes this entry, so we create a new one.
250 // XXX determine whether this release is trusted or not
251 debReleaseIndex *Deb = new debReleaseIndex(URI,Dist);
252 Deb->PushSectionEntry (new debReleaseIndex::debSectionEntry(Section, IsSrc));
253 List.push_back(Deb);
254 return true;
255 }
256 };
257
258 class debSLTypeDeb : public debSLTypeDebian
259 {
260 public:
261
262 bool CreateItem(vector<metaIndex *> &List,string URI,
263 string Dist,string Section) const
264 {
265 return CreateItemInternal(List, URI, Dist, Section, false);
266 }
267
268 debSLTypeDeb()
269 {
270 Name = "deb";
271 Label = "Standard Debian binary tree";
272 }
273 };
274
275 class debSLTypeDebSrc : public debSLTypeDebian
276 {
277 public:
278
279 bool CreateItem(vector<metaIndex *> &List,string URI,
280 string Dist,string Section) const
281 {
282 return CreateItemInternal(List, URI, Dist, Section, true);
283 }
284
285 debSLTypeDebSrc()
286 {
287 Name = "deb-src";
288 Label = "Standard Debian source tree";
289 }
290 };
291
292 debSLTypeDeb _apt_DebType;
293 debSLTypeDebSrc _apt_DebSrcType;