]> git.saurik.com Git - apt.git/blob - apt-pkg/deb/debmetaindex.cc
drop obsolete explicit :none handling in pkgCacheGen
[apt.git] / apt-pkg / deb / debmetaindex.cc
1 #include <config.h>
2
3 #include <apt-pkg/error.h>
4 #include <apt-pkg/debmetaindex.h>
5 #include <apt-pkg/debindexfile.h>
6 #include <apt-pkg/strutl.h>
7 #include <apt-pkg/fileutl.h>
8 #include <apt-pkg/acquire-item.h>
9 #include <apt-pkg/configuration.h>
10 #include <apt-pkg/aptconfiguration.h>
11 #include <apt-pkg/sourcelist.h>
12 #include <apt-pkg/hashes.h>
13 #include <apt-pkg/metaindex.h>
14 #include <apt-pkg/pkgcachegen.h>
15 #include <apt-pkg/tagfile.h>
16 #include <apt-pkg/gpgv.h>
17 #include <apt-pkg/macros.h>
18
19 #include <map>
20 #include <string>
21 #include <utility>
22 #include <vector>
23 #include <set>
24 #include <algorithm>
25
26 #include <sys/types.h>
27 #include <sys/stat.h>
28 #include <unistd.h>
29 #include <string.h>
30
31 #include <apti18n.h>
32
33 class APT_HIDDEN debReleaseIndexPrivate /*{{{*/
34 {
35 public:
36 struct APT_HIDDEN debSectionEntry
37 {
38 std::string Name;
39 std::vector<std::string> Targets;
40 std::vector<std::string> Architectures;
41 std::vector<std::string> Languages;
42 };
43
44 std::vector<debSectionEntry> DebEntries;
45 std::vector<debSectionEntry> DebSrcEntries;
46
47 metaIndex::TriState CheckValidUntil;
48 time_t ValidUntilMin;
49 time_t ValidUntilMax;
50
51 debReleaseIndexPrivate() : CheckValidUntil(metaIndex::TRI_UNSET), ValidUntilMin(0), ValidUntilMax(0) {}
52 };
53 /*}}}*/
54 // ReleaseIndex::MetaIndex* - display helpers /*{{{*/
55 std::string debReleaseIndex::MetaIndexInfo(const char *Type) const
56 {
57 std::string Info = ::URI::ArchiveOnly(URI) + ' ';
58 if (Dist[Dist.size() - 1] == '/')
59 {
60 if (Dist != "/")
61 Info += Dist;
62 }
63 else
64 Info += Dist;
65 Info += " ";
66 Info += Type;
67 return Info;
68 }
69 std::string debReleaseIndex::Describe() const
70 {
71 return MetaIndexInfo("Release");
72 }
73
74 std::string debReleaseIndex::MetaIndexFile(const char *Type) const
75 {
76 return _config->FindDir("Dir::State::lists") +
77 URItoFileName(MetaIndexURI(Type));
78 }
79
80 std::string debReleaseIndex::MetaIndexURI(const char *Type) const
81 {
82 std::string Res;
83
84 if (Dist == "/")
85 Res = URI;
86 else if (Dist[Dist.size()-1] == '/')
87 Res = URI + Dist;
88 else
89 Res = URI + "dists/" + Dist + "/";
90
91 Res += Type;
92 return Res;
93 }
94 /*}}}*/
95 // ReleaseIndex Con- and Destructors /*{{{*/
96 debReleaseIndex::debReleaseIndex(std::string const &URI, std::string const &Dist) :
97 metaIndex(URI, Dist, "deb"), d(new debReleaseIndexPrivate())
98 {}
99 debReleaseIndex::debReleaseIndex(std::string const &URI, std::string const &Dist, bool const pTrusted) :
100 metaIndex(URI, Dist, "deb"), d(new debReleaseIndexPrivate())
101 {
102 Trusted = pTrusted ? TRI_YES : TRI_NO;
103 }
104 debReleaseIndex::~debReleaseIndex() {
105 if (d != NULL)
106 delete d;
107 }
108 /*}}}*/
109 // ReleaseIndex::GetIndexTargets /*{{{*/
110 static void GetIndexTargetsFor(char const * const Type, std::string const &URI, std::string const &Dist,
111 std::vector<debReleaseIndexPrivate::debSectionEntry> const &entries,
112 std::vector<IndexTarget> &IndexTargets)
113 {
114 bool const flatArchive = (Dist[Dist.length() - 1] == '/');
115 std::string baseURI = URI;
116 if (flatArchive)
117 {
118 if (Dist != "/")
119 baseURI += Dist;
120 }
121 else
122 baseURI += "dists/" + Dist + "/";
123 std::string const Release = (Dist == "/") ? "" : Dist;
124 std::string const Site = ::URI::ArchiveOnly(URI);
125
126 bool const GzipIndex = _config->FindB("Acquire::GzipIndexes", false);
127 for (std::vector<debReleaseIndexPrivate::debSectionEntry>::const_iterator E = entries.begin(); E != entries.end(); ++E)
128 {
129 for (std::vector<std::string>::const_iterator T = E->Targets.begin(); T != E->Targets.end(); ++T)
130 {
131 #define APT_T_CONFIG(X) _config->Find(std::string("Acquire::IndexTargets::") + Type + "::" + *T + "::" + (X))
132 std::string const tplMetaKey = APT_T_CONFIG(flatArchive ? "flatMetaKey" : "MetaKey");
133 std::string const tplShortDesc = APT_T_CONFIG("ShortDescription");
134 std::string const tplLongDesc = "$(SITE) " + APT_T_CONFIG(flatArchive ? "flatDescription" : "Description");
135 bool const IsOptional = _config->FindB(std::string("Acquire::IndexTargets::") + Type + "::" + *T + "::Optional", true);
136 bool const KeepCompressed = _config->FindB(std::string("Acquire::IndexTargets::") + Type + "::" + *T + "::KeepCompressed", GzipIndex);
137 #undef APT_T_CONFIG
138 if (tplMetaKey.empty())
139 continue;
140
141 for (std::vector<std::string>::const_iterator L = E->Languages.begin(); L != E->Languages.end(); ++L)
142 {
143 if (*L == "none" && tplMetaKey.find("$(LANGUAGE)") != std::string::npos)
144 continue;
145
146 for (std::vector<std::string>::const_iterator A = E->Architectures.begin(); A != E->Architectures.end(); ++A)
147 {
148
149 std::map<std::string, std::string> Options;
150 Options.insert(std::make_pair("SITE", Site));
151 Options.insert(std::make_pair("RELEASE", Release));
152 if (tplMetaKey.find("$(COMPONENT)") != std::string::npos)
153 Options.insert(std::make_pair("COMPONENT", E->Name));
154 if (tplMetaKey.find("$(LANGUAGE)") != std::string::npos)
155 Options.insert(std::make_pair("LANGUAGE", *L));
156 if (tplMetaKey.find("$(ARCHITECTURE)") != std::string::npos)
157 Options.insert(std::make_pair("ARCHITECTURE", *A));
158 Options.insert(std::make_pair("BASE_URI", baseURI));
159 Options.insert(std::make_pair("REPO_URI", URI));
160 Options.insert(std::make_pair("TARGET_OF", "deb-src"));
161 Options.insert(std::make_pair("CREATED_BY", *T));
162
163 std::string MetaKey = tplMetaKey;
164 std::string ShortDesc = tplShortDesc;
165 std::string LongDesc = tplLongDesc;
166 for (std::map<std::string, std::string>::const_iterator O = Options.begin(); O != Options.end(); ++O)
167 {
168 MetaKey = SubstVar(MetaKey, std::string("$(") + O->first + ")", O->second);
169 ShortDesc = SubstVar(ShortDesc, std::string("$(") + O->first + ")", O->second);
170 LongDesc = SubstVar(LongDesc, std::string("$(") + O->first + ")", O->second);
171 }
172 IndexTarget Target(
173 MetaKey,
174 ShortDesc,
175 LongDesc,
176 Options.find("BASE_URI")->second + MetaKey,
177 IsOptional,
178 KeepCompressed,
179 Options
180 );
181 IndexTargets.push_back(Target);
182
183 if (tplMetaKey.find("$(ARCHITECTURE)") == std::string::npos)
184 break;
185
186 }
187
188 if (tplMetaKey.find("$(LANGUAGE)") == std::string::npos)
189 break;
190
191 }
192
193 }
194 }
195 }
196 std::vector<IndexTarget> debReleaseIndex::GetIndexTargets() const
197 {
198 std::vector<IndexTarget> IndexTargets;
199 GetIndexTargetsFor("deb-src", URI, Dist, d->DebSrcEntries, IndexTargets);
200 GetIndexTargetsFor("deb", URI, Dist, d->DebEntries, IndexTargets);
201 return IndexTargets;
202 }
203 /*}}}*/
204 void debReleaseIndex::AddComponent(bool const isSrc, std::string const &Name,/*{{{*/
205 std::vector<std::string> const &Targets,
206 std::vector<std::string> const &Architectures,
207 std::vector<std::string> Languages)
208 {
209 if (Languages.empty() == true)
210 Languages.push_back("none");
211 debReleaseIndexPrivate::debSectionEntry const entry = {
212 Name, Targets, Architectures, Languages
213 };
214 if (isSrc)
215 d->DebSrcEntries.push_back(entry);
216 else
217 d->DebEntries.push_back(entry);
218 }
219 /*}}}*/
220
221 bool debReleaseIndex::Load(std::string const &Filename, std::string * const ErrorText)/*{{{*/
222 {
223 LoadedSuccessfully = TRI_NO;
224 FileFd Fd;
225 if (OpenMaybeClearSignedFile(Filename, Fd) == false)
226 return false;
227
228 pkgTagFile TagFile(&Fd, Fd.Size());
229 if (_error->PendingError() == true)
230 {
231 if (ErrorText != NULL)
232 strprintf(*ErrorText, _("Unable to parse Release file %s"),Filename.c_str());
233 return false;
234 }
235
236 pkgTagSection Section;
237 const char *Start, *End;
238 if (TagFile.Step(Section) == false)
239 {
240 if (ErrorText != NULL)
241 strprintf(*ErrorText, _("No sections in Release file %s"), Filename.c_str());
242 return false;
243 }
244 // FIXME: find better tag name
245 SupportsAcquireByHash = Section.FindB("Acquire-By-Hash", false);
246
247 Suite = Section.FindS("Suite");
248 Codename = Section.FindS("Codename");
249
250 bool FoundHashSum = false;
251 for (int i=0;HashString::SupportedHashes()[i] != NULL; i++)
252 {
253 if (!Section.Find(HashString::SupportedHashes()[i], Start, End))
254 continue;
255
256 std::string Name;
257 std::string Hash;
258 unsigned long long Size;
259 while (Start < End)
260 {
261 if (!parseSumData(Start, End, Name, Hash, Size))
262 return false;
263
264 if (Entries.find(Name) == Entries.end())
265 {
266 metaIndex::checkSum *Sum = new metaIndex::checkSum;
267 Sum->MetaKeyFilename = Name;
268 Sum->Size = Size;
269 Sum->Hashes.FileSize(Size);
270 APT_IGNORE_DEPRECATED(Sum->Hash = HashString(HashString::SupportedHashes()[i],Hash);)
271 Entries[Name] = Sum;
272 }
273 Entries[Name]->Hashes.push_back(HashString(HashString::SupportedHashes()[i],Hash));
274 FoundHashSum = true;
275 }
276 }
277
278 if(FoundHashSum == false)
279 {
280 if (ErrorText != NULL)
281 strprintf(*ErrorText, _("No Hash entry in Release file %s"), Filename.c_str());
282 return false;
283 }
284
285 std::string const StrDate = Section.FindS("Date");
286 if (RFC1123StrToTime(StrDate.c_str(), Date) == false)
287 {
288 if (ErrorText != NULL)
289 strprintf(*ErrorText, _("Invalid 'Date' entry in Release file %s"), Filename.c_str());
290 return false;
291 }
292
293 bool CheckValidUntil = _config->FindB("Acquire::Check-Valid-Until", true);
294 if (d->CheckValidUntil == metaIndex::TRI_NO)
295 CheckValidUntil = false;
296 else if (d->CheckValidUntil == metaIndex::TRI_YES)
297 CheckValidUntil = true;
298
299 if (CheckValidUntil == true)
300 {
301 std::string const Label = Section.FindS("Label");
302 std::string const StrValidUntil = Section.FindS("Valid-Until");
303
304 // if we have a Valid-Until header in the Release file, use it as default
305 if (StrValidUntil.empty() == false)
306 {
307 if(RFC1123StrToTime(StrValidUntil.c_str(), ValidUntil) == false)
308 {
309 if (ErrorText != NULL)
310 strprintf(*ErrorText, _("Invalid 'Valid-Until' entry in Release file %s"), Filename.c_str());
311 return false;
312 }
313 }
314 // get the user settings for this archive and use what expires earlier
315 time_t MaxAge = d->ValidUntilMax;
316 if (MaxAge == 0)
317 {
318 MaxAge = _config->FindI("Acquire::Max-ValidTime", 0);
319 if (Label.empty() == false)
320 MaxAge = _config->FindI(("Acquire::Max-ValidTime::" + Label).c_str(), MaxAge);
321 }
322 time_t MinAge = d->ValidUntilMin;
323 if (MinAge == 0)
324 {
325 MinAge = _config->FindI("Acquire::Min-ValidTime", 0);
326 if (Label.empty() == false)
327 MinAge = _config->FindI(("Acquire::Min-ValidTime::" + Label).c_str(), MinAge);
328 }
329
330 if (MinAge != 0 && ValidUntil != 0) {
331 time_t const min_date = Date + MinAge;
332 if (ValidUntil < min_date)
333 ValidUntil = min_date;
334 }
335 if (MaxAge != 0) {
336 time_t const max_date = Date + MaxAge;
337 if (ValidUntil == 0 || ValidUntil > max_date)
338 ValidUntil = max_date;
339 }
340 }
341
342 LoadedSuccessfully = TRI_YES;
343 return true;
344 }
345 /*}}}*/
346 metaIndex * debReleaseIndex::UnloadedClone() const /*{{{*/
347 {
348 if (Trusted == TRI_NO)
349 return new debReleaseIndex(URI, Dist, false);
350 else if (Trusted == TRI_YES)
351 return new debReleaseIndex(URI, Dist, true);
352 else
353 return new debReleaseIndex(URI, Dist);
354 }
355 /*}}}*/
356 bool debReleaseIndex::parseSumData(const char *&Start, const char *End, /*{{{*/
357 std::string &Name, std::string &Hash, unsigned long long &Size)
358 {
359 Name = "";
360 Hash = "";
361 Size = 0;
362 /* Skip over the first blank */
363 while ((*Start == '\t' || *Start == ' ' || *Start == '\n' || *Start == '\r')
364 && Start < End)
365 Start++;
366 if (Start >= End)
367 return false;
368
369 /* Move EntryEnd to the end of the first entry (the hash) */
370 const char *EntryEnd = Start;
371 while ((*EntryEnd != '\t' && *EntryEnd != ' ')
372 && EntryEnd < End)
373 EntryEnd++;
374 if (EntryEnd == End)
375 return false;
376
377 Hash.append(Start, EntryEnd-Start);
378
379 /* Skip over intermediate blanks */
380 Start = EntryEnd;
381 while (*Start == '\t' || *Start == ' ')
382 Start++;
383 if (Start >= End)
384 return false;
385
386 EntryEnd = Start;
387 /* Find the end of the second entry (the size) */
388 while ((*EntryEnd != '\t' && *EntryEnd != ' ' )
389 && EntryEnd < End)
390 EntryEnd++;
391 if (EntryEnd == End)
392 return false;
393
394 Size = strtoull (Start, NULL, 10);
395
396 /* Skip over intermediate blanks */
397 Start = EntryEnd;
398 while (*Start == '\t' || *Start == ' ')
399 Start++;
400 if (Start >= End)
401 return false;
402
403 EntryEnd = Start;
404 /* Find the end of the third entry (the filename) */
405 while ((*EntryEnd != '\t' && *EntryEnd != ' ' &&
406 *EntryEnd != '\n' && *EntryEnd != '\r')
407 && EntryEnd < End)
408 EntryEnd++;
409
410 Name.append(Start, EntryEnd-Start);
411 Start = EntryEnd; //prepare for the next round
412 return true;
413 }
414 /*}}}*/
415
416 bool debReleaseIndex::GetIndexes(pkgAcquire *Owner, bool const &GetAll)/*{{{*/
417 {
418 std::vector<IndexTarget> const targets = GetIndexTargets();
419 #define APT_TARGET(X) IndexTarget("", X, MetaIndexInfo(X), MetaIndexURI(X), false, false, std::map<std::string,std::string>())
420 pkgAcqMetaClearSig * const TransactionManager = new pkgAcqMetaClearSig(Owner,
421 APT_TARGET("InRelease"), APT_TARGET("Release"), APT_TARGET("Release.gpg"),
422 targets, this);
423 #undef APT_TARGET
424 // special case for --print-uris
425 if (GetAll)
426 {
427 for (std::vector<IndexTarget>::const_iterator Target = targets.begin(); Target != targets.end(); ++Target)
428 new pkgAcqIndex(Owner, TransactionManager, *Target);
429 }
430
431 return true;
432 }
433 /*}}}*/
434 // ReleaseIndex::Set* TriState options /*{{{*/
435 bool debReleaseIndex::SetTrusted(TriState const pTrusted)
436 {
437 if (Trusted == TRI_UNSET)
438 Trusted = pTrusted;
439 else if (Trusted != pTrusted)
440 // TRANSLATOR: The first is an option name from sources.list manpage, the other two URI and Suite
441 return _error->Error(_("Conflicting values set for option %s concerning source %s %s"), "Trusted", URI.c_str(), Dist.c_str());
442 return true;
443 }
444 bool debReleaseIndex::SetCheckValidUntil(TriState const pCheckValidUntil)
445 {
446 if (d->CheckValidUntil == TRI_UNSET)
447 d->CheckValidUntil = pCheckValidUntil;
448 else if (d->CheckValidUntil != pCheckValidUntil)
449 return _error->Error(_("Conflicting values set for option %s concerning source %s %s"), "Check-Valid-Until", URI.c_str(), Dist.c_str());
450 return true;
451 }
452 bool debReleaseIndex::SetValidUntilMin(time_t const Valid)
453 {
454 if (d->ValidUntilMin == 0)
455 d->ValidUntilMin = Valid;
456 else if (d->ValidUntilMin != Valid)
457 return _error->Error(_("Conflicting values set for option %s concerning source %s %s"), "Min-ValidTime", URI.c_str(), Dist.c_str());
458 return true;
459 }
460 bool debReleaseIndex::SetValidUntilMax(time_t const Valid)
461 {
462 if (d->ValidUntilMax == 0)
463 d->ValidUntilMax = Valid;
464 else if (d->ValidUntilMax != Valid)
465 return _error->Error(_("Conflicting values set for option %s concerning source %s %s"), "Max-ValidTime", URI.c_str(), Dist.c_str());
466 return true;
467 }
468 bool debReleaseIndex::SetSignedBy(std::string const &pSignedBy)
469 {
470 if (SignedBy.empty() == true && pSignedBy.empty() == false)
471 {
472 if (pSignedBy[0] == '/') // no check for existence as we could be chrooting later or such things
473 ; // absolute path to a keyring file
474 else
475 {
476 // we could go all fancy and allow short/long/string matches as gpgv/apt-key does,
477 // but fingerprints are harder to fake than the others and this option is set once,
478 // not interactively all the time so easy to type is not really a concern.
479 std::string finger = pSignedBy;
480 finger.erase(std::remove(finger.begin(), finger.end(), ' '), finger.end());
481 std::transform(finger.begin(), finger.end(), finger.begin(), ::toupper);
482 if (finger.length() != 40 || finger.find_first_not_of("0123456789ABCDEF") != std::string::npos)
483 return _error->Error(_("Invalid value set for option %s concerning source %s %s (%s)"), "Signed-By", URI.c_str(), Dist.c_str(), "not a fingerprint");
484 }
485 SignedBy = pSignedBy;
486 }
487 else if (SignedBy != pSignedBy)
488 return _error->Error(_("Conflicting values set for option %s concerning source %s %s"), "Signed-By", URI.c_str(), Dist.c_str());
489 return true;
490 }
491 /*}}}*/
492 // ReleaseIndex::IsTrusted /*{{{*/
493 bool debReleaseIndex::IsTrusted() const
494 {
495 if (Trusted == TRI_YES)
496 return true;
497 else if (Trusted == TRI_NO)
498 return false;
499
500
501 if(_config->FindB("APT::Authentication::TrustCDROM", false))
502 if(URI.substr(0,strlen("cdrom:")) == "cdrom:")
503 return true;
504
505 if (FileExists(MetaIndexFile("Release.gpg")))
506 return true;
507
508 return FileExists(MetaIndexFile("InRelease"));
509 }
510 /*}}}*/
511 std::vector <pkgIndexFile *> *debReleaseIndex::GetIndexFiles() /*{{{*/
512 {
513 if (Indexes != NULL)
514 return Indexes;
515
516 Indexes = new std::vector<pkgIndexFile*>();
517 std::vector<IndexTarget> const Targets = GetIndexTargets();
518 bool const istrusted = IsTrusted();
519 for (std::vector<IndexTarget>::const_iterator T = Targets.begin(); T != Targets.end(); ++T)
520 {
521 std::string const TargetName = T->Option(IndexTarget::CREATED_BY);
522 if (TargetName == "Packages")
523 Indexes->push_back(new debPackagesIndex(*T, istrusted));
524 else if (TargetName == "Sources")
525 Indexes->push_back(new debSourcesIndex(*T, istrusted));
526 else if (TargetName == "Translations")
527 Indexes->push_back(new debTranslationsIndex(*T));
528 }
529 return Indexes;
530 }
531 /*}}}*/
532
533 static bool ReleaseFileName(debReleaseIndex const * const That, std::string &ReleaseFile)/*{{{*/
534 {
535 ReleaseFile = That->MetaIndexFile("InRelease");
536 bool releaseExists = false;
537 if (FileExists(ReleaseFile) == true)
538 releaseExists = true;
539 else
540 {
541 ReleaseFile = That->MetaIndexFile("Release");
542 if (FileExists(ReleaseFile))
543 releaseExists = true;
544 }
545 return releaseExists;
546 }
547 /*}}}*/
548 bool debReleaseIndex::Merge(pkgCacheGenerator &Gen,OpProgress * /*Prog*/) const/*{{{*/
549 {
550 std::string ReleaseFile;
551 bool const releaseExists = ReleaseFileName(this, ReleaseFile);
552
553 ::URI Tmp(URI);
554 if (Gen.SelectReleaseFile(ReleaseFile, Tmp.Host) == false)
555 return _error->Error("Problem with SelectReleaseFile %s", ReleaseFile.c_str());
556
557 if (releaseExists == false)
558 return true;
559
560 FileFd Rel;
561 // Beware: The 'Release' file might be clearsigned in case the
562 // signature for an 'InRelease' file couldn't be checked
563 if (OpenMaybeClearSignedFile(ReleaseFile, Rel) == false)
564 return false;
565 if (_error->PendingError() == true)
566 return false;
567
568 // Store the IMS information
569 pkgCache::RlsFileIterator File = Gen.GetCurRlsFile();
570 pkgCacheGenerator::Dynamic<pkgCache::RlsFileIterator> DynFile(File);
571 // Rel can't be used as this is potentially a temporary file
572 struct stat Buf;
573 if (stat(ReleaseFile.c_str(), &Buf) != 0)
574 return _error->Errno("fstat", "Unable to stat file %s", ReleaseFile.c_str());
575 File->Size = Buf.st_size;
576 File->mtime = Buf.st_mtime;
577
578 pkgTagFile TagFile(&Rel, Rel.Size());
579 pkgTagSection Section;
580 if (_error->PendingError() == true || TagFile.Step(Section) == false)
581 return false;
582
583 std::string data;
584 #define APT_INRELEASE(TYPE, TAG, STORE) \
585 data = Section.FindS(TAG); \
586 if (data.empty() == false) \
587 { \
588 map_stringitem_t const storage = Gen.StoreString(pkgCacheGenerator::TYPE, data); \
589 STORE = storage; \
590 }
591 APT_INRELEASE(MIXED, "Suite", File->Archive)
592 APT_INRELEASE(VERSIONNUMBER, "Version", File->Version)
593 APT_INRELEASE(MIXED, "Origin", File->Origin)
594 APT_INRELEASE(MIXED, "Codename", File->Codename)
595 APT_INRELEASE(MIXED, "Label", File->Label)
596 #undef APT_INRELEASE
597 Section.FindFlag("NotAutomatic", File->Flags, pkgCache::Flag::NotAutomatic);
598 Section.FindFlag("ButAutomaticUpgrades", File->Flags, pkgCache::Flag::ButAutomaticUpgrades);
599
600 return !_error->PendingError();
601 }
602 /*}}}*/
603 // ReleaseIndex::FindInCache - Find this index /*{{{*/
604 pkgCache::RlsFileIterator debReleaseIndex::FindInCache(pkgCache &Cache, bool const ModifyCheck) const
605 {
606 std::string ReleaseFile;
607 bool const releaseExists = ReleaseFileName(this, ReleaseFile);
608
609 pkgCache::RlsFileIterator File = Cache.RlsFileBegin();
610 for (; File.end() == false; ++File)
611 {
612 if (File->FileName == 0 || ReleaseFile != File.FileName())
613 continue;
614
615 // empty means the file does not exist by "design"
616 if (ModifyCheck == false || (releaseExists == false && File->Size == 0))
617 return File;
618
619 struct stat St;
620 if (stat(File.FileName(),&St) != 0)
621 {
622 if (_config->FindB("Debug::pkgCacheGen", false))
623 std::clog << "ReleaseIndex::FindInCache - stat failed on " << File.FileName() << std::endl;
624 return pkgCache::RlsFileIterator(Cache);
625 }
626 if ((unsigned)St.st_size != File->Size || St.st_mtime != File->mtime)
627 {
628 if (_config->FindB("Debug::pkgCacheGen", false))
629 std::clog << "ReleaseIndex::FindInCache - size (" << St.st_size << " <> " << File->Size
630 << ") or mtime (" << St.st_mtime << " <> " << File->mtime
631 << ") doesn't match for " << File.FileName() << std::endl;
632 return pkgCache::RlsFileIterator(Cache);
633 }
634 return File;
635 }
636
637 return File;
638 }
639 /*}}}*/
640
641 static std::vector<std::string> parsePlusMinusOptions(std::string const &Name, /*{{{*/
642 std::map<std::string, std::string> const &Options, std::vector<std::string> const &defaultValues)
643 {
644 std::map<std::string, std::string>::const_iterator val = Options.find(Name);
645 std::vector<std::string> Values;
646 if (val != Options.end())
647 Values = VectorizeString(val->second, ',');
648 else
649 Values = defaultValues;
650
651 if ((val = Options.find(Name + "+")) != Options.end())
652 {
653 std::vector<std::string> const plusArch = VectorizeString(val->second, ',');
654 for (std::vector<std::string>::const_iterator plus = plusArch.begin(); plus != plusArch.end(); ++plus)
655 if (std::find(Values.begin(), Values.end(), *plus) == Values.end())
656 Values.push_back(*plus);
657 }
658 if ((val = Options.find(Name + "-")) != Options.end())
659 {
660 std::vector<std::string> const minusArch = VectorizeString(val->second, ',');
661 for (std::vector<std::string>::const_iterator minus = minusArch.begin(); minus != minusArch.end(); ++minus)
662 {
663 std::vector<std::string>::iterator kill = std::find(Values.begin(), Values.end(), *minus);
664 if (kill != Values.end())
665 Values.erase(kill);
666 }
667 }
668 return Values;
669 }
670 /*}}}*/
671 class APT_HIDDEN debSLTypeDebian : public pkgSourceList::Type /*{{{*/
672 {
673 metaIndex::TriState GetTriStateOption(std::map<std::string, std::string>const &Options, char const * const name) const
674 {
675 std::map<std::string, std::string>::const_iterator const opt = Options.find(name);
676 if (opt != Options.end())
677 return StringToBool(opt->second, false) ? metaIndex::TRI_YES : metaIndex::TRI_NO;
678 return metaIndex::TRI_DONTCARE;
679 }
680
681 time_t GetTimeOption(std::map<std::string, std::string>const &Options, char const * const name) const
682 {
683 std::map<std::string, std::string>::const_iterator const opt = Options.find(name);
684 if (opt == Options.end())
685 return 0;
686 return strtoull(opt->second.c_str(), NULL, 10);
687 }
688
689 protected:
690
691 bool CreateItemInternal(std::vector<metaIndex *> &List, std::string const &URI,
692 std::string const &Dist, std::string const &Section,
693 bool const &IsSrc, std::map<std::string, std::string> const &Options) const
694 {
695 debReleaseIndex *Deb = NULL;
696 for (std::vector<metaIndex *>::const_iterator I = List.begin();
697 I != List.end(); ++I)
698 {
699 // We only worry about debian entries here
700 if (strcmp((*I)->GetType(), "deb") != 0)
701 continue;
702
703 /* This check insures that there will be only one Release file
704 queued for all the Packages files and Sources files it
705 corresponds to. */
706 if ((*I)->GetURI() == URI && (*I)->GetDist() == Dist)
707 {
708 Deb = dynamic_cast<debReleaseIndex*>(*I);
709 if (Deb != NULL)
710 break;
711 }
712 }
713
714 // No currently created Release file indexes this entry, so we create a new one.
715 if (Deb == NULL)
716 {
717 Deb = new debReleaseIndex(URI, Dist);
718 List.push_back(Deb);
719 }
720
721 Deb->AddComponent(
722 IsSrc,
723 Section,
724 parsePlusMinusOptions("target", Options, _config->FindVector(std::string("Acquire::IndexTargets::") + Name, "", true)),
725 parsePlusMinusOptions("arch", Options, APT::Configuration::getArchitectures()),
726 parsePlusMinusOptions("lang", Options, APT::Configuration::getLanguages(true))
727 );
728
729 if (Deb->SetTrusted(GetTriStateOption(Options, "trusted")) == false ||
730 Deb->SetCheckValidUntil(GetTriStateOption(Options, "check-valid-until")) == false ||
731 Deb->SetValidUntilMax(GetTimeOption(Options, "valid-until-max")) == false ||
732 Deb->SetValidUntilMin(GetTimeOption(Options, "valid-until-min")) == false)
733 return false;
734
735 std::map<std::string, std::string>::const_iterator const signedby = Options.find("signed-by");
736 if (signedby == Options.end())
737 {
738 if (Deb->SetSignedBy("") == false)
739 return false;
740 }
741 else
742 {
743 if (Deb->SetSignedBy(signedby->second) == false)
744 return false;
745 }
746
747 return true;
748 }
749
750 debSLTypeDebian(char const * const Name, char const * const Label) : Type(Name, Label)
751 {
752 }
753 };
754 /*}}}*/
755 class APT_HIDDEN debSLTypeDeb : public debSLTypeDebian /*{{{*/
756 {
757 public:
758
759 bool CreateItem(std::vector<metaIndex *> &List, std::string const &URI,
760 std::string const &Dist, std::string const &Section,
761 std::map<std::string, std::string> const &Options) const APT_OVERRIDE
762 {
763 return CreateItemInternal(List, URI, Dist, Section, false, Options);
764 }
765
766 debSLTypeDeb() : debSLTypeDebian("deb", "Debian binary tree")
767 {
768 }
769 };
770 /*}}}*/
771 class APT_HIDDEN debSLTypeDebSrc : public debSLTypeDebian /*{{{*/
772 {
773 public:
774
775 bool CreateItem(std::vector<metaIndex *> &List, std::string const &URI,
776 std::string const &Dist, std::string const &Section,
777 std::map<std::string, std::string> const &Options) const APT_OVERRIDE
778 {
779 return CreateItemInternal(List, URI, Dist, Section, true, Options);
780 }
781
782 debSLTypeDebSrc() : debSLTypeDebian("deb-src", "Debian source tree")
783 {
784 }
785 };
786 /*}}}*/
787
788 APT_HIDDEN debSLTypeDeb _apt_DebType;
789 APT_HIDDEN debSLTypeDebSrc _apt_DebSrcType;