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