]>
Commit | Line | Data |
---|---|---|
ea542140 | 1 | #include <config.h> |
7db98ffc | 2 | |
b07aeb1a | 3 | #include <apt-pkg/error.h> |
7db98ffc MZ |
4 | #include <apt-pkg/debmetaindex.h> |
5 | #include <apt-pkg/debindexfile.h> | |
6 | #include <apt-pkg/strutl.h> | |
472ff00e | 7 | #include <apt-pkg/fileutl.h> |
7db98ffc MZ |
8 | #include <apt-pkg/acquire-item.h> |
9 | #include <apt-pkg/configuration.h> | |
45df0ad2 | 10 | #include <apt-pkg/aptconfiguration.h> |
472ff00e DK |
11 | #include <apt-pkg/indexrecords.h> |
12 | #include <apt-pkg/sourcelist.h> | |
453b82a3 | 13 | #include <apt-pkg/hashes.h> |
453b82a3 | 14 | #include <apt-pkg/metaindex.h> |
b07aeb1a DK |
15 | #include <apt-pkg/pkgcachegen.h> |
16 | #include <apt-pkg/tagfile.h> | |
17 | #include <apt-pkg/gpgv.h> | |
18 | #include <apt-pkg/macros.h> | |
7db98ffc | 19 | |
453b82a3 DK |
20 | #include <map> |
21 | #include <string> | |
22 | #include <utility> | |
23 | #include <vector> | |
5dd4c8b8 | 24 | #include <set> |
7cb28948 | 25 | #include <algorithm> |
5dd4c8b8 | 26 | |
b07aeb1a DK |
27 | #include <sys/types.h> |
28 | #include <sys/stat.h> | |
29 | #include <unistd.h> | |
30 | #include <string.h> | |
31 | ||
7db98ffc MZ |
32 | using namespace std; |
33 | ||
7db98ffc MZ |
34 | string debReleaseIndex::MetaIndexInfo(const char *Type) const |
35 | { | |
1da3b7b8 | 36 | string Info = ::URI::ArchiveOnly(URI) + ' '; |
7db98ffc MZ |
37 | if (Dist[Dist.size() - 1] == '/') |
38 | { | |
39 | if (Dist != "/") | |
40 | Info += Dist; | |
41 | } | |
42 | else | |
43 | Info += Dist; | |
44 | Info += " "; | |
45 | Info += Type; | |
46 | return Info; | |
47 | } | |
b07aeb1a DK |
48 | std::string debReleaseIndex::Describe() const |
49 | { | |
50 | return MetaIndexInfo("Release"); | |
51 | } | |
7db98ffc MZ |
52 | |
53 | string debReleaseIndex::MetaIndexFile(const char *Type) const | |
54 | { | |
55 | return _config->FindDir("Dir::State::lists") + | |
56 | URItoFileName(MetaIndexURI(Type)); | |
57 | } | |
58 | ||
59 | string debReleaseIndex::MetaIndexURI(const char *Type) const | |
60 | { | |
61 | string Res; | |
62 | ||
63 | if (Dist == "/") | |
64 | Res = URI; | |
65 | else if (Dist[Dist.size()-1] == '/') | |
66 | Res = URI + Dist; | |
67 | else | |
68 | Res = URI + "dists/" + Dist + "/"; | |
69 | ||
70 | Res += Type; | |
71 | return Res; | |
72 | } | |
73 | ||
7014e148 MV |
74 | std::string debReleaseIndex::LocalFileName() const |
75 | { | |
76 | // see if we have a InRelease file | |
77 | std::string PathInRelease = MetaIndexFile("InRelease"); | |
78 | if (FileExists(PathInRelease)) | |
79 | return PathInRelease; | |
80 | ||
81 | // and if not return the normal one | |
82 | if (FileExists(PathInRelease)) | |
83 | return MetaIndexFile("Release"); | |
84 | ||
85 | return ""; | |
86 | } | |
7014e148 | 87 | |
4b42f43b DK |
88 | debReleaseIndex::debReleaseIndex(string const &URI, string const &Dist) : |
89 | metaIndex(URI, Dist, "deb"), Trusted(CHECK_TRUST) | |
90 | {} | |
91 | ||
92 | debReleaseIndex::debReleaseIndex(string const &URI, string const &Dist, bool const Trusted) : | |
93 | metaIndex(URI, Dist, "deb") { | |
94 | SetTrusted(Trusted); | |
7db98ffc MZ |
95 | } |
96 | ||
5dd4c8b8 DK |
97 | debReleaseIndex::~debReleaseIndex() { |
98 | for (map<string, vector<debSectionEntry const*> >::const_iterator A = ArchEntries.begin(); | |
99 | A != ArchEntries.end(); ++A) | |
100 | for (vector<const debSectionEntry *>::const_iterator S = A->second.begin(); | |
101 | S != A->second.end(); ++S) | |
102 | delete *S; | |
7a9f09bd MV |
103 | } |
104 | ||
59148d96 DK |
105 | template<typename CallC> |
106 | void foreachTarget(std::string const URI, std::string const Dist, | |
107 | std::map<std::string, std::vector<debReleaseIndex::debSectionEntry const *> > const &ArchEntries, | |
dcbbb14d | 108 | CallC &Call) |
1e0f0f28 | 109 | { |
1e0f0f28 DK |
110 | bool const flatArchive = (Dist[Dist.length() - 1] == '/'); |
111 | std::string baseURI = URI; | |
112 | if (flatArchive) | |
113 | { | |
114 | if (Dist != "/") | |
115 | baseURI += Dist; | |
116 | } | |
117 | else | |
118 | baseURI += "dists/" + Dist + "/"; | |
119 | std::string const Release = (Dist == "/") ? "" : Dist; | |
1da3b7b8 | 120 | std::string const Site = ::URI::ArchiveOnly(URI); |
1e0f0f28 DK |
121 | std::vector<std::string> lang = APT::Configuration::getLanguages(true); |
122 | if (lang.empty()) | |
123 | lang.push_back("none"); | |
59148d96 | 124 | map<string, vector<debReleaseIndex::debSectionEntry const*> >::const_iterator const src = ArchEntries.find("source"); |
1e0f0f28 DK |
125 | if (src != ArchEntries.end()) |
126 | { | |
127 | std::vector<std::string> const targets = _config->FindVector("APT::Acquire::Targets::deb-src", "", true); | |
128 | for (std::vector<std::string>::const_iterator T = targets.begin(); T != targets.end(); ++T) | |
129 | { | |
130 | #define APT_T_CONFIG(X) _config->Find(std::string("APT::Acquire::Targets::deb-src::") + *T + "::" + (X)) | |
d3a869e3 | 131 | std::string const MetaKey = APT_T_CONFIG(flatArchive ? "flatMetaKey" : "MetaKey"); |
1e0f0f28 DK |
132 | std::string const ShortDesc = APT_T_CONFIG("ShortDescription"); |
133 | std::string const LongDesc = APT_T_CONFIG(flatArchive ? "flatDescription" : "Description"); | |
134 | bool const IsOptional = _config->FindB(std::string("APT::Acquire::Targets::deb-src::") + *T + "::Optional", true); | |
135 | #undef APT_T_CONFIG | |
d3a869e3 | 136 | if (MetaKey.empty()) |
1e0f0f28 DK |
137 | continue; |
138 | ||
59148d96 DK |
139 | vector<debReleaseIndex::debSectionEntry const*> const SectionEntries = src->second; |
140 | for (vector<debReleaseIndex::debSectionEntry const*>::const_iterator I = SectionEntries.begin(); | |
1e0f0f28 DK |
141 | I != SectionEntries.end(); ++I) |
142 | { | |
143 | for (vector<std::string>::const_iterator l = lang.begin(); l != lang.end(); ++l) | |
144 | { | |
d3a869e3 | 145 | if (*l == "none" && MetaKey.find("$(LANGUAGE)") != std::string::npos) |
1e0f0f28 DK |
146 | continue; |
147 | ||
d3a869e3 DK |
148 | std::map<std::string, std::string> Options; |
149 | Options.insert(std::make_pair("SITE", Site)); | |
150 | Options.insert(std::make_pair("RELEASE", Release)); | |
8881b11e DK |
151 | if (MetaKey.find("$(COMPONENT)") != std::string::npos) |
152 | Options.insert(std::make_pair("COMPONENT", (*I)->Section)); | |
153 | if (MetaKey.find("$(LANGUAGE)") != std::string::npos) | |
154 | Options.insert(std::make_pair("LANGUAGE", *l)); | |
d3a869e3 DK |
155 | Options.insert(std::make_pair("ARCHITECTURE", "source")); |
156 | Options.insert(std::make_pair("BASE_URI", baseURI)); | |
e3c1cfc7 | 157 | Options.insert(std::make_pair("REPO_URI", URI)); |
8881b11e | 158 | Options.insert(std::make_pair("TARGET_OF", "deb-src")); |
d3a869e3 DK |
159 | Options.insert(std::make_pair("CREATED_BY", *T)); |
160 | Call(MetaKey, ShortDesc, LongDesc, IsOptional, Options); | |
161 | ||
162 | if (MetaKey.find("$(LANGUAGE)") == std::string::npos) | |
1e0f0f28 DK |
163 | break; |
164 | } | |
165 | ||
d3a869e3 | 166 | if (MetaKey.find("$(COMPONENT)") == std::string::npos) |
1e0f0f28 DK |
167 | break; |
168 | } | |
169 | } | |
170 | } | |
5dd4c8b8 | 171 | |
1e0f0f28 DK |
172 | std::vector<std::string> const targets = _config->FindVector("APT::Acquire::Targets::deb", "", true); |
173 | for (std::vector<std::string>::const_iterator T = targets.begin(); T != targets.end(); ++T) | |
174 | { | |
175 | #define APT_T_CONFIG(X) _config->Find(std::string("APT::Acquire::Targets::deb::") + *T + "::" + (X)) | |
d3a869e3 | 176 | std::string const MetaKey = APT_T_CONFIG(flatArchive ? "flatMetaKey" : "MetaKey"); |
1e0f0f28 DK |
177 | std::string const ShortDesc = APT_T_CONFIG("ShortDescription"); |
178 | std::string const LongDesc = APT_T_CONFIG(flatArchive ? "flatDescription" : "Description"); | |
179 | bool const IsOptional = _config->FindB(std::string("APT::Acquire::Targets::deb::") + *T + "::Optional", true); | |
180 | #undef APT_T_CONFIG | |
d3a869e3 | 181 | if (MetaKey.empty()) |
1e0f0f28 DK |
182 | continue; |
183 | ||
59148d96 | 184 | for (map<string, vector<debReleaseIndex::debSectionEntry const*> >::const_iterator a = ArchEntries.begin(); |
1e0f0f28 DK |
185 | a != ArchEntries.end(); ++a) |
186 | { | |
187 | if (a->first == "source") | |
188 | continue; | |
189 | ||
59148d96 | 190 | for (vector <const debReleaseIndex::debSectionEntry *>::const_iterator I = a->second.begin(); |
1e0f0f28 DK |
191 | I != a->second.end(); ++I) { |
192 | ||
193 | for (vector<std::string>::const_iterator l = lang.begin(); l != lang.end(); ++l) | |
194 | { | |
d3a869e3 | 195 | if (*l == "none" && MetaKey.find("$(LANGUAGE)") != std::string::npos) |
1e0f0f28 DK |
196 | continue; |
197 | ||
d3a869e3 DK |
198 | std::map<std::string, std::string> Options; |
199 | Options.insert(std::make_pair("SITE", Site)); | |
200 | Options.insert(std::make_pair("RELEASE", Release)); | |
8881b11e DK |
201 | if (MetaKey.find("$(COMPONENT)") != std::string::npos) |
202 | Options.insert(std::make_pair("COMPONENT", (*I)->Section)); | |
203 | if (MetaKey.find("$(LANGUAGE)") != std::string::npos) | |
204 | Options.insert(std::make_pair("LANGUAGE", *l)); | |
205 | if (MetaKey.find("$(ARCHITECTURE)") != std::string::npos) | |
206 | Options.insert(std::make_pair("ARCHITECTURE", a->first)); | |
d3a869e3 | 207 | Options.insert(std::make_pair("BASE_URI", baseURI)); |
e3c1cfc7 | 208 | Options.insert(std::make_pair("REPO_URI", URI)); |
8881b11e | 209 | Options.insert(std::make_pair("TARGET_OF", "deb")); |
d3a869e3 DK |
210 | Options.insert(std::make_pair("CREATED_BY", *T)); |
211 | Call(MetaKey, ShortDesc, LongDesc, IsOptional, Options); | |
212 | ||
213 | if (MetaKey.find("$(LANGUAGE)") == std::string::npos) | |
1e0f0f28 DK |
214 | break; |
215 | } | |
216 | ||
d3a869e3 | 217 | if (MetaKey.find("$(COMPONENT)") == std::string::npos) |
1e0f0f28 DK |
218 | break; |
219 | } | |
220 | ||
d3a869e3 | 221 | if (MetaKey.find("$(ARCHITECTURE)") == std::string::npos) |
1e0f0f28 DK |
222 | break; |
223 | } | |
224 | } | |
59148d96 DK |
225 | } |
226 | ||
227 | ||
228 | struct ComputeIndexTargetsClass | |
229 | { | |
dcbbb14d | 230 | vector <IndexTarget> IndexTargets; |
59148d96 | 231 | |
d3a869e3 DK |
232 | void operator()(std::string MetaKey, std::string ShortDesc, std::string LongDesc, |
233 | bool const IsOptional, std::map<std::string, std::string> Options) | |
59148d96 | 234 | { |
d3a869e3 | 235 | for (std::map<std::string, std::string>::const_iterator O = Options.begin(); O != Options.end(); ++O) |
59148d96 | 236 | { |
d3a869e3 DK |
237 | MetaKey = SubstVar(MetaKey, std::string("$(") + O->first + ")", O->second); |
238 | ShortDesc = SubstVar(ShortDesc, std::string("$(") + O->first + ")", O->second); | |
239 | LongDesc = SubstVar(LongDesc, std::string("$(") + O->first + ")", O->second); | |
59148d96 | 240 | } |
dcbbb14d | 241 | IndexTarget Target( |
d3a869e3 DK |
242 | MetaKey, |
243 | ShortDesc, | |
244 | LongDesc, | |
245 | Options.find("BASE_URI")->second + MetaKey, | |
246 | IsOptional, | |
247 | Options | |
248 | ); | |
dcbbb14d | 249 | IndexTargets.push_back(Target); |
59148d96 | 250 | } |
59148d96 DK |
251 | }; |
252 | ||
261727f0 | 253 | std::vector<IndexTarget> debReleaseIndex::GetIndexTargets() const |
59148d96 DK |
254 | { |
255 | ComputeIndexTargetsClass comp; | |
256 | foreachTarget(URI, Dist, ArchEntries, comp); | |
257 | return comp.IndexTargets; | |
7db98ffc | 258 | } |
59148d96 DK |
259 | |
260 | ||
7db98ffc | 261 | /*}}}*/ |
5dd4c8b8 | 262 | bool debReleaseIndex::GetIndexes(pkgAcquire *Owner, bool const &GetAll) const |
7db98ffc | 263 | { |
07cb47e7 DK |
264 | indexRecords * const iR = new indexRecords(Dist); |
265 | if (Trusted == ALWAYS_TRUSTED) | |
266 | iR->SetTrusted(true); | |
267 | else if (Trusted == NEVER_TRUSTED) | |
268 | iR->SetTrusted(false); | |
269 | ||
7db98ffc | 270 | // special case for --print-uris |
261727f0 | 271 | std::vector<IndexTarget> const targets = GetIndexTargets(); |
d3a869e3 | 272 | #define APT_TARGET(X) IndexTarget("", X, MetaIndexInfo(X), MetaIndexURI(X), false, std::map<std::string,std::string>()) |
448c38bd DK |
273 | pkgAcqMetaBase * const TransactionManager = new pkgAcqMetaClearSig(Owner, |
274 | APT_TARGET("InRelease"), APT_TARGET("Release"), APT_TARGET("Release.gpg"), | |
275 | targets, iR); | |
276 | #undef APT_TARGET | |
277 | if (GetAll) | |
278 | { | |
dcbbb14d | 279 | for (std::vector<IndexTarget>::const_iterator Target = targets.begin(); Target != targets.end(); ++Target) |
448c38bd | 280 | new pkgAcqIndex(Owner, TransactionManager, *Target); |
7db98ffc | 281 | } |
fe0f7911 | 282 | |
55971004 | 283 | return true; |
7db98ffc MZ |
284 | } |
285 | ||
4b42f43b DK |
286 | void debReleaseIndex::SetTrusted(bool const Trusted) |
287 | { | |
288 | if (Trusted == true) | |
289 | this->Trusted = ALWAYS_TRUSTED; | |
290 | else | |
291 | this->Trusted = NEVER_TRUSTED; | |
292 | } | |
293 | ||
7db98ffc MZ |
294 | bool debReleaseIndex::IsTrusted() const |
295 | { | |
4b42f43b DK |
296 | if (Trusted == ALWAYS_TRUSTED) |
297 | return true; | |
298 | else if (Trusted == NEVER_TRUSTED) | |
299 | return false; | |
300 | ||
301 | ||
4e0ad446 | 302 | if(_config->FindB("APT::Authentication::TrustCDROM", false)) |
e8cdc56a MV |
303 | if(URI.substr(0,strlen("cdrom:")) == "cdrom:") |
304 | return true; | |
fe0f7911 DK |
305 | |
306 | string VerifiedSigFile = _config->FindDir("Dir::State::lists") + | |
307 | URItoFileName(MetaIndexURI("Release")) + ".gpg"; | |
308 | ||
7db98ffc MZ |
309 | if (FileExists(VerifiedSigFile)) |
310 | return true; | |
fe0f7911 DK |
311 | |
312 | VerifiedSigFile = _config->FindDir("Dir::State::lists") + | |
313 | URItoFileName(MetaIndexURI("InRelease")); | |
314 | ||
315 | return FileExists(VerifiedSigFile); | |
7db98ffc MZ |
316 | } |
317 | ||
e3c1cfc7 | 318 | std::vector <pkgIndexFile *> *debReleaseIndex::GetIndexFiles() |
59148d96 | 319 | { |
e3c1cfc7 DK |
320 | if (Indexes != NULL) |
321 | return Indexes; | |
59148d96 | 322 | |
e3c1cfc7 DK |
323 | Indexes = new std::vector<pkgIndexFile*>(); |
324 | std::vector<IndexTarget> const Targets = GetIndexTargets(); | |
325 | bool const istrusted = IsTrusted(); | |
326 | for (std::vector<IndexTarget>::const_iterator T = Targets.begin(); T != Targets.end(); ++T) | |
59148d96 | 327 | { |
001c76fe | 328 | std::string const TargetName = T->Option(IndexTarget::CREATED_BY); |
59148d96 | 329 | if (TargetName == "Packages") |
e3c1cfc7 | 330 | Indexes->push_back(new debPackagesIndex(*T, istrusted)); |
59148d96 | 331 | else if (TargetName == "Sources") |
e3c1cfc7 | 332 | Indexes->push_back(new debSourcesIndex(*T, istrusted)); |
59148d96 | 333 | else if (TargetName == "Translations") |
e3c1cfc7 | 334 | Indexes->push_back(new debTranslationsIndex(*T)); |
59148d96 | 335 | } |
e3c1cfc7 | 336 | return Indexes; |
5dd4c8b8 | 337 | } |
a7a5b0d9 | 338 | |
5dd4c8b8 DK |
339 | void debReleaseIndex::PushSectionEntry(vector<string> const &Archs, const debSectionEntry *Entry) { |
340 | for (vector<string>::const_iterator a = Archs.begin(); | |
341 | a != Archs.end(); ++a) | |
342 | ArchEntries[*a].push_back(new debSectionEntry(Entry->Section, Entry->IsSrc)); | |
343 | delete Entry; | |
7db98ffc MZ |
344 | } |
345 | ||
5dd4c8b8 DK |
346 | void debReleaseIndex::PushSectionEntry(string const &Arch, const debSectionEntry *Entry) { |
347 | ArchEntries[Arch].push_back(Entry); | |
7db98ffc MZ |
348 | } |
349 | ||
5dd4c8b8 DK |
350 | debReleaseIndex::debSectionEntry::debSectionEntry (string const &Section, |
351 | bool const &IsSrc): Section(Section), IsSrc(IsSrc) | |
352 | {} | |
353 | ||
b07aeb1a DK |
354 | static bool ReleaseFileName(debReleaseIndex const * const That, std::string &ReleaseFile) |
355 | { | |
356 | ReleaseFile = That->MetaIndexFile("InRelease"); | |
357 | bool releaseExists = false; | |
358 | if (FileExists(ReleaseFile) == true) | |
359 | releaseExists = true; | |
360 | else | |
361 | { | |
362 | ReleaseFile = That->MetaIndexFile("Release"); | |
363 | if (FileExists(ReleaseFile)) | |
364 | releaseExists = true; | |
365 | } | |
366 | return releaseExists; | |
367 | } | |
368 | ||
369 | bool debReleaseIndex::Merge(pkgCacheGenerator &Gen,OpProgress * /*Prog*/) const/*{{{*/ | |
370 | { | |
371 | std::string ReleaseFile; | |
372 | bool const releaseExists = ReleaseFileName(this, ReleaseFile); | |
373 | ||
374 | ::URI Tmp(URI); | |
375 | if (Gen.SelectReleaseFile(ReleaseFile, Tmp.Host) == false) | |
376 | return _error->Error("Problem with SelectReleaseFile %s", ReleaseFile.c_str()); | |
377 | ||
378 | if (releaseExists == false) | |
379 | return true; | |
380 | ||
381 | FileFd Rel; | |
382 | // Beware: The 'Release' file might be clearsigned in case the | |
383 | // signature for an 'InRelease' file couldn't be checked | |
384 | if (OpenMaybeClearSignedFile(ReleaseFile, Rel) == false) | |
385 | return false; | |
386 | if (_error->PendingError() == true) | |
387 | return false; | |
388 | ||
389 | // Store the IMS information | |
390 | pkgCache::RlsFileIterator File = Gen.GetCurRlsFile(); | |
391 | pkgCacheGenerator::Dynamic<pkgCache::RlsFileIterator> DynFile(File); | |
392 | // Rel can't be used as this is potentially a temporary file | |
393 | struct stat Buf; | |
394 | if (stat(ReleaseFile.c_str(), &Buf) != 0) | |
395 | return _error->Errno("fstat", "Unable to stat file %s", ReleaseFile.c_str()); | |
396 | File->Size = Buf.st_size; | |
397 | File->mtime = Buf.st_mtime; | |
398 | ||
399 | pkgTagFile TagFile(&Rel, Rel.Size()); | |
400 | pkgTagSection Section; | |
401 | if (_error->PendingError() == true || TagFile.Step(Section) == false) | |
402 | return false; | |
403 | ||
404 | std::string data; | |
405 | #define APT_INRELEASE(TYPE, TAG, STORE) \ | |
406 | data = Section.FindS(TAG); \ | |
407 | if (data.empty() == false) \ | |
408 | { \ | |
409 | map_stringitem_t const storage = Gen.StoreString(pkgCacheGenerator::TYPE, data); \ | |
410 | STORE = storage; \ | |
411 | } | |
412 | APT_INRELEASE(MIXED, "Suite", File->Archive) | |
413 | APT_INRELEASE(VERSIONNUMBER, "Version", File->Version) | |
414 | APT_INRELEASE(MIXED, "Origin", File->Origin) | |
415 | APT_INRELEASE(MIXED, "Codename", File->Codename) | |
416 | APT_INRELEASE(MIXED, "Label", File->Label) | |
417 | #undef APT_INRELEASE | |
418 | Section.FindFlag("NotAutomatic", File->Flags, pkgCache::Flag::NotAutomatic); | |
419 | Section.FindFlag("ButAutomaticUpgrades", File->Flags, pkgCache::Flag::ButAutomaticUpgrades); | |
420 | ||
421 | return !_error->PendingError(); | |
422 | } | |
423 | /*}}}*/ | |
424 | // ReleaseIndex::FindInCache - Find this index /*{{{*/ | |
425 | pkgCache::RlsFileIterator debReleaseIndex::FindInCache(pkgCache &Cache) const | |
426 | { | |
427 | std::string ReleaseFile; | |
428 | bool const releaseExists = ReleaseFileName(this, ReleaseFile); | |
429 | ||
430 | pkgCache::RlsFileIterator File = Cache.RlsFileBegin(); | |
431 | for (; File.end() == false; ++File) | |
432 | { | |
433 | if (File->FileName == 0 || ReleaseFile != File.FileName()) | |
434 | continue; | |
435 | ||
436 | // empty means the file does not exist by "design" | |
437 | if (releaseExists == false && File->Size == 0) | |
438 | return File; | |
439 | ||
440 | struct stat St; | |
441 | if (stat(File.FileName(),&St) != 0) | |
442 | { | |
443 | if (_config->FindB("Debug::pkgCacheGen", false)) | |
444 | std::clog << "ReleaseIndex::FindInCache - stat failed on " << File.FileName() << std::endl; | |
445 | return pkgCache::RlsFileIterator(Cache); | |
446 | } | |
447 | if ((unsigned)St.st_size != File->Size || St.st_mtime != File->mtime) | |
448 | { | |
449 | if (_config->FindB("Debug::pkgCacheGen", false)) | |
450 | std::clog << "ReleaseIndex::FindInCache - size (" << St.st_size << " <> " << File->Size | |
451 | << ") or mtime (" << St.st_mtime << " <> " << File->mtime | |
452 | << ") doesn't match for " << File.FileName() << std::endl; | |
453 | return pkgCache::RlsFileIterator(Cache); | |
454 | } | |
455 | return File; | |
456 | } | |
457 | ||
458 | return File; | |
459 | } | |
460 | /*}}}*/ | |
461 | ||
dce45dbe | 462 | class APT_HIDDEN debSLTypeDebian : public pkgSourceList::Type |
7db98ffc MZ |
463 | { |
464 | protected: | |
465 | ||
5dd4c8b8 DK |
466 | bool CreateItemInternal(vector<metaIndex *> &List, string const &URI, |
467 | string const &Dist, string const &Section, | |
468 | bool const &IsSrc, map<string, string> const &Options) const | |
7db98ffc | 469 | { |
3d1be93d DK |
470 | // parse arch=, arch+= and arch-= settings |
471 | map<string, string>::const_iterator arch = Options.find("arch"); | |
2b4cead3 DK |
472 | vector<string> Archs; |
473 | if (arch != Options.end()) | |
474 | Archs = VectorizeString(arch->second, ','); | |
475 | else | |
476 | Archs = APT::Configuration::getArchitectures(); | |
477 | ||
3d1be93d DK |
478 | if ((arch = Options.find("arch+")) != Options.end()) |
479 | { | |
480 | std::vector<std::string> const plusArch = VectorizeString(arch->second, ','); | |
481 | for (std::vector<std::string>::const_iterator plus = plusArch.begin(); plus != plusArch.end(); ++plus) | |
482 | if (std::find(Archs.begin(), Archs.end(), *plus) == Archs.end()) | |
483 | Archs.push_back(*plus); | |
484 | } | |
485 | if ((arch = Options.find("arch-")) != Options.end()) | |
486 | { | |
487 | std::vector<std::string> const minusArch = VectorizeString(arch->second, ','); | |
488 | for (std::vector<std::string>::const_iterator minus = minusArch.begin(); minus != minusArch.end(); ++minus) | |
489 | { | |
490 | std::vector<std::string>::iterator kill = std::find(Archs.begin(), Archs.end(), *minus); | |
491 | if (kill != Archs.end()) | |
492 | Archs.erase(kill); | |
493 | } | |
494 | } | |
495 | ||
4b42f43b | 496 | map<string, string>::const_iterator const trusted = Options.find("trusted"); |
5dd4c8b8 | 497 | |
261727f0 | 498 | debReleaseIndex *Deb = NULL; |
5dd4c8b8 | 499 | for (vector<metaIndex *>::const_iterator I = List.begin(); |
f7f0d6c7 | 500 | I != List.end(); ++I) |
7db98ffc | 501 | { |
5dd4c8b8 DK |
502 | // We only worry about debian entries here |
503 | if (strcmp((*I)->GetType(), "deb") != 0) | |
504 | continue; | |
505 | ||
5dd4c8b8 DK |
506 | /* This check insures that there will be only one Release file |
507 | queued for all the Packages files and Sources files it | |
508 | corresponds to. */ | |
261727f0 | 509 | if ((*I)->GetURI() == URI && (*I)->GetDist() == Dist) |
7db98ffc | 510 | { |
261727f0 DK |
511 | Deb = dynamic_cast<debReleaseIndex*>(*I); |
512 | if (Deb != NULL) | |
513 | break; | |
7db98ffc MZ |
514 | } |
515 | } | |
4b42f43b | 516 | |
7db98ffc | 517 | // No currently created Release file indexes this entry, so we create a new one. |
261727f0 DK |
518 | if (Deb == NULL) |
519 | { | |
4b42f43b | 520 | Deb = new debReleaseIndex(URI, Dist); |
261727f0 DK |
521 | List.push_back(Deb); |
522 | } | |
4b42f43b | 523 | |
5dd4c8b8 DK |
524 | if (IsSrc == true) |
525 | Deb->PushSectionEntry ("source", new debReleaseIndex::debSectionEntry(Section, IsSrc)); | |
526 | else | |
dd13742e DK |
527 | { |
528 | if (Dist[Dist.size() - 1] == '/') | |
529 | Deb->PushSectionEntry ("any", new debReleaseIndex::debSectionEntry(Section, IsSrc)); | |
530 | else | |
531 | Deb->PushSectionEntry (Archs, new debReleaseIndex::debSectionEntry(Section, IsSrc)); | |
532 | } | |
261727f0 DK |
533 | |
534 | if (trusted != Options.end()) | |
535 | Deb->SetTrusted(StringToBool(trusted->second, false)); | |
536 | ||
7db98ffc MZ |
537 | return true; |
538 | } | |
539 | }; | |
540 | ||
0d29b9d4 MV |
541 | debDebFileMetaIndex::debDebFileMetaIndex(std::string const &DebFile) |
542 | : metaIndex(DebFile, "local-uri", "deb-dist"), DebFile(DebFile) | |
543 | { | |
544 | DebIndex = new debDebPkgFileIndex(DebFile); | |
545 | Indexes = new vector<pkgIndexFile *>(); | |
546 | Indexes->push_back(DebIndex); | |
547 | } | |
548 | ||
549 | ||
dce45dbe | 550 | class APT_HIDDEN debSLTypeDeb : public debSLTypeDebian |
7db98ffc MZ |
551 | { |
552 | public: | |
553 | ||
5dd4c8b8 DK |
554 | bool CreateItem(vector<metaIndex *> &List, string const &URI, |
555 | string const &Dist, string const &Section, | |
556 | std::map<string, string> const &Options) const | |
7db98ffc | 557 | { |
5dd4c8b8 | 558 | return CreateItemInternal(List, URI, Dist, Section, false, Options); |
7db98ffc MZ |
559 | } |
560 | ||
561 | debSLTypeDeb() | |
562 | { | |
563 | Name = "deb"; | |
564 | Label = "Standard Debian binary tree"; | |
565 | } | |
566 | }; | |
567 | ||
dce45dbe | 568 | class APT_HIDDEN debSLTypeDebSrc : public debSLTypeDebian |
7db98ffc MZ |
569 | { |
570 | public: | |
571 | ||
5dd4c8b8 DK |
572 | bool CreateItem(vector<metaIndex *> &List, string const &URI, |
573 | string const &Dist, string const &Section, | |
574 | std::map<string, string> const &Options) const | |
7db98ffc | 575 | { |
5dd4c8b8 | 576 | return CreateItemInternal(List, URI, Dist, Section, true, Options); |
7db98ffc MZ |
577 | } |
578 | ||
579 | debSLTypeDebSrc() | |
580 | { | |
581 | Name = "deb-src"; | |
582 | Label = "Standard Debian source tree"; | |
583 | } | |
584 | }; | |
585 | ||
dce45dbe | 586 | class APT_HIDDEN debSLTypeDebFile : public pkgSourceList::Type |
eafc5435 MV |
587 | { |
588 | public: | |
589 | ||
590 | bool CreateItem(vector<metaIndex *> &List, string const &URI, | |
070536e6 MV |
591 | string const &/*Dist*/, string const &/*Section*/, |
592 | std::map<string, string> const &/*Options*/) const | |
eafc5435 MV |
593 | { |
594 | metaIndex *mi = new debDebFileMetaIndex(URI); | |
595 | List.push_back(mi); | |
596 | return true; | |
597 | } | |
598 | ||
599 | debSLTypeDebFile() | |
600 | { | |
601 | Name = "deb-file"; | |
602 | Label = "Debian Deb File"; | |
603 | } | |
604 | }; | |
dce45dbe DK |
605 | |
606 | APT_HIDDEN debSLTypeDeb _apt_DebType; | |
607 | APT_HIDDEN debSLTypeDebSrc _apt_DebSrcType; | |
608 | APT_HIDDEN debSLTypeDebFile _apt_DebFileType; |