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