]>
Commit | Line | Data |
---|---|---|
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 | ||
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, | |
495e5cb2 | 147 | (*Target)->ShortDesc, HashString()); |
7db98ffc MZ |
148 | } |
149 | } | |
150 | new pkgAcqMetaSig(Owner, MetaIndexURI("Release.gpg"), | |
151 | MetaIndexInfo("Release.gpg"), "Release.gpg", | |
152 | MetaIndexURI("Release"), MetaIndexInfo("Release"), "Release", | |
153 | ComputeIndexTargets(), | |
154 | new indexRecords (Dist)); | |
155 | ||
97234432 MV |
156 | // Queue the translations |
157 | for (vector<const debSectionEntry *>::const_iterator I = SectionEntries.begin(); | |
158 | I != SectionEntries.end(); I++) { | |
159 | ||
fb603534 MV |
160 | if((*I)->IsSrc) |
161 | continue; | |
97234432 MV |
162 | debTranslationsIndex i = debTranslationsIndex(URI,Dist,(*I)->Section); |
163 | i.GetIndexes(Owner); | |
164 | } | |
165 | ||
7db98ffc MZ |
166 | return true; |
167 | } | |
168 | ||
169 | bool debReleaseIndex::IsTrusted() const | |
170 | { | |
171 | string VerifiedSigFile = _config->FindDir("Dir::State::lists") + | |
172 | URItoFileName(MetaIndexURI("Release")) + ".gpg"; | |
173 | ||
4e0ad446 | 174 | if(_config->FindB("APT::Authentication::TrustCDROM", false)) |
e8cdc56a MV |
175 | if(URI.substr(0,strlen("cdrom:")) == "cdrom:") |
176 | return true; | |
177 | ||
7db98ffc MZ |
178 | if (FileExists(VerifiedSigFile)) |
179 | return true; | |
180 | return false; | |
181 | } | |
182 | ||
183 | vector <pkgIndexFile *> *debReleaseIndex::GetIndexFiles() | |
184 | { | |
185 | if (Indexes != NULL) | |
186 | return Indexes; | |
187 | ||
188 | Indexes = new vector <pkgIndexFile*>; | |
189 | for (vector<const debSectionEntry *>::const_iterator I = SectionEntries.begin(); | |
a7a5b0d9 | 190 | I != SectionEntries.end(); I++) { |
7db98ffc MZ |
191 | if ((*I)->IsSrc) |
192 | Indexes->push_back(new debSourcesIndex (URI, Dist, (*I)->Section, IsTrusted())); | |
193 | else | |
770c32ec | 194 | { |
7db98ffc | 195 | Indexes->push_back(new debPackagesIndex (URI, Dist, (*I)->Section, IsTrusted())); |
770c32ec MV |
196 | Indexes->push_back(new debTranslationsIndex(URI, Dist, (*I)->Section)); |
197 | } | |
a7a5b0d9 OS |
198 | } |
199 | ||
7db98ffc MZ |
200 | return Indexes; |
201 | } | |
202 | ||
203 | void debReleaseIndex::PushSectionEntry(const debSectionEntry *Entry) | |
204 | { | |
205 | SectionEntries.push_back(Entry); | |
206 | } | |
207 | ||
208 | debReleaseIndex::debSectionEntry::debSectionEntry (string Section, bool IsSrc): Section(Section) | |
209 | { | |
210 | this->IsSrc = IsSrc; | |
211 | } | |
212 | ||
213 | class debSLTypeDebian : public pkgSourceList::Type | |
214 | { | |
215 | protected: | |
216 | ||
217 | bool CreateItemInternal(vector<metaIndex *> &List,string URI, | |
218 | string Dist,string Section, | |
219 | bool IsSrc) const | |
220 | { | |
221 | for (vector<metaIndex *>::const_iterator I = List.begin(); | |
222 | I != List.end(); I++) | |
223 | { | |
224 | // This check insures that there will be only one Release file | |
225 | // queued for all the Packages files and Sources files it | |
226 | // corresponds to. | |
227 | if ((*I)->GetType() == "deb") | |
228 | { | |
229 | debReleaseIndex *Deb = (debReleaseIndex *) (*I); | |
230 | // This check insures that there will be only one Release file | |
231 | // queued for all the Packages files and Sources files it | |
232 | // corresponds to. | |
233 | if (Deb->GetURI() == URI && Deb->GetDist() == Dist) | |
234 | { | |
235 | Deb->PushSectionEntry(new debReleaseIndex::debSectionEntry(Section, IsSrc)); | |
236 | return true; | |
237 | } | |
238 | } | |
239 | } | |
240 | // No currently created Release file indexes this entry, so we create a new one. | |
241 | // XXX determine whether this release is trusted or not | |
242 | debReleaseIndex *Deb = new debReleaseIndex(URI,Dist); | |
243 | Deb->PushSectionEntry (new debReleaseIndex::debSectionEntry(Section, IsSrc)); | |
244 | List.push_back(Deb); | |
245 | return true; | |
246 | } | |
247 | }; | |
248 | ||
249 | class debSLTypeDeb : public debSLTypeDebian | |
250 | { | |
251 | public: | |
252 | ||
253 | bool CreateItem(vector<metaIndex *> &List,string URI, | |
254 | string Dist,string Section) const | |
255 | { | |
256 | return CreateItemInternal(List, URI, Dist, Section, false); | |
257 | } | |
258 | ||
259 | debSLTypeDeb() | |
260 | { | |
261 | Name = "deb"; | |
262 | Label = "Standard Debian binary tree"; | |
263 | } | |
264 | }; | |
265 | ||
266 | class debSLTypeDebSrc : public debSLTypeDebian | |
267 | { | |
268 | public: | |
269 | ||
270 | bool CreateItem(vector<metaIndex *> &List,string URI, | |
271 | string Dist,string Section) const | |
272 | { | |
273 | return CreateItemInternal(List, URI, Dist, Section, true); | |
274 | } | |
275 | ||
276 | debSLTypeDebSrc() | |
277 | { | |
278 | Name = "deb-src"; | |
279 | Label = "Standard Debian source tree"; | |
280 | } | |
281 | }; | |
282 | ||
283 | debSLTypeDeb _apt_DebType; | |
284 | debSLTypeDebSrc _apt_DebSrcType; |