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>
26 #include <sys/types.h>
33 class APT_HIDDEN debReleaseIndexPrivate
/*{{{*/
36 struct APT_HIDDEN debSectionEntry
39 std::vector
<std::string
> Targets
;
40 std::vector
<std::string
> Architectures
;
41 std::vector
<std::string
> Languages
;
44 std::vector
<debSectionEntry
> DebEntries
;
45 std::vector
<debSectionEntry
> DebSrcEntries
;
47 metaIndex::TriState CheckValidUntil
;
51 debReleaseIndexPrivate() : CheckValidUntil(metaIndex::TRI_UNSET
), ValidUntilMin(0), ValidUntilMax(0) {}
54 // ReleaseIndex::MetaIndex* - display helpers /*{{{*/
55 std::string
debReleaseIndex::MetaIndexInfo(const char *Type
) const
57 std::string Info
= ::URI::ArchiveOnly(URI
) + ' ';
58 if (Dist
[Dist
.size() - 1] == '/')
69 std::string
debReleaseIndex::Describe() const
71 return MetaIndexInfo("Release");
74 std::string
debReleaseIndex::MetaIndexFile(const char *Type
) const
76 return _config
->FindDir("Dir::State::lists") +
77 URItoFileName(MetaIndexURI(Type
));
80 std::string
debReleaseIndex::MetaIndexURI(const char *Type
) const
86 else if (Dist
[Dist
.size()-1] == '/')
89 Res
= URI
+ "dists/" + Dist
+ "/";
95 // ReleaseIndex Con- and Destructors /*{{{*/
96 debReleaseIndex::debReleaseIndex(std::string
const &URI
, std::string
const &Dist
) :
97 metaIndex(URI
, Dist
, "deb"), d(new debReleaseIndexPrivate())
99 debReleaseIndex::debReleaseIndex(std::string
const &URI
, std::string
const &Dist
, bool const pTrusted
) :
100 metaIndex(URI
, Dist
, "deb"), d(new debReleaseIndexPrivate())
102 Trusted
= pTrusted
? TRI_YES
: TRI_NO
;
104 debReleaseIndex::~debReleaseIndex() {
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
)
114 bool const flatArchive
= (Dist
[Dist
.length() - 1] == '/');
115 std::string baseURI
= URI
;
122 baseURI
+= "dists/" + Dist
+ "/";
123 std::string
const Release
= (Dist
== "/") ? "" : Dist
;
124 std::string
const Site
= ::URI::ArchiveOnly(URI
);
126 bool const GzipIndex
= _config
->FindB("Acquire::GzipIndexes", false);
127 for (std::vector
<debReleaseIndexPrivate::debSectionEntry
>::const_iterator E
= entries
.begin(); E
!= entries
.end(); ++E
)
129 for (std::vector
<std::string
>::const_iterator T
= E
->Targets
.begin(); T
!= E
->Targets
.end(); ++T
)
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
);
138 if (tplMetaKey
.empty())
141 for (std::vector
<std::string
>::const_iterator L
= E
->Languages
.begin(); L
!= E
->Languages
.end(); ++L
)
143 if (*L
== "none" && tplMetaKey
.find("$(LANGUAGE)") != std::string::npos
)
146 for (std::vector
<std::string
>::const_iterator A
= E
->Architectures
.begin(); A
!= E
->Architectures
.end(); ++A
)
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
));
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
)
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
);
176 Options
.find("BASE_URI")->second
+ MetaKey
,
181 IndexTargets
.push_back(Target
);
183 if (tplMetaKey
.find("$(ARCHITECTURE)") == std::string::npos
)
188 if (tplMetaKey
.find("$(LANGUAGE)") == std::string::npos
)
196 std::vector
<IndexTarget
> debReleaseIndex::GetIndexTargets() const
198 std::vector
<IndexTarget
> IndexTargets
;
199 GetIndexTargetsFor("deb-src", URI
, Dist
, d
->DebSrcEntries
, IndexTargets
);
200 GetIndexTargetsFor("deb", URI
, Dist
, d
->DebEntries
, IndexTargets
);
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
)
209 if (Languages
.empty() == true)
210 Languages
.push_back("none");
211 debReleaseIndexPrivate::debSectionEntry
const entry
= {
212 Name
, Targets
, Architectures
, Languages
215 d
->DebSrcEntries
.push_back(entry
);
217 d
->DebEntries
.push_back(entry
);
221 bool debReleaseIndex::Load(std::string
const &Filename
, std::string
* const ErrorText
)/*{{{*/
223 LoadedSuccessfully
= TRI_NO
;
225 if (OpenMaybeClearSignedFile(Filename
, Fd
) == false)
228 pkgTagFile
TagFile(&Fd
, Fd
.Size());
229 if (_error
->PendingError() == true)
231 if (ErrorText
!= NULL
)
232 strprintf(*ErrorText
, _("Unable to parse Release file %s"),Filename
.c_str());
236 pkgTagSection Section
;
237 const char *Start
, *End
;
238 if (TagFile
.Step(Section
) == false)
240 if (ErrorText
!= NULL
)
241 strprintf(*ErrorText
, _("No sections in Release file %s"), Filename
.c_str());
244 // FIXME: find better tag name
245 SupportsAcquireByHash
= Section
.FindB("Acquire-By-Hash", false);
247 Suite
= Section
.FindS("Suite");
248 Codename
= Section
.FindS("Codename");
250 bool FoundHashSum
= false;
251 for (int i
=0;HashString::SupportedHashes()[i
] != NULL
; i
++)
253 if (!Section
.Find(HashString::SupportedHashes()[i
], Start
, End
))
258 unsigned long long Size
;
261 if (!parseSumData(Start
, End
, Name
, Hash
, Size
))
264 if (Entries
.find(Name
) == Entries
.end())
266 metaIndex::checkSum
*Sum
= new metaIndex::checkSum
;
267 Sum
->MetaKeyFilename
= Name
;
269 Sum
->Hashes
.FileSize(Size
);
270 APT_IGNORE_DEPRECATED(Sum
->Hash
= HashString(HashString::SupportedHashes()[i
],Hash
);)
273 Entries
[Name
]->Hashes
.push_back(HashString(HashString::SupportedHashes()[i
],Hash
));
278 if(FoundHashSum
== false)
280 if (ErrorText
!= NULL
)
281 strprintf(*ErrorText
, _("No Hash entry in Release file %s"), Filename
.c_str());
285 std::string
const StrDate
= Section
.FindS("Date");
286 if (RFC1123StrToTime(StrDate
.c_str(), Date
) == false)
288 if (ErrorText
!= NULL
)
289 strprintf(*ErrorText
, _("Invalid 'Date' entry in Release file %s"), Filename
.c_str());
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;
299 if (CheckValidUntil
== true)
301 std::string
const Label
= Section
.FindS("Label");
302 std::string
const StrValidUntil
= Section
.FindS("Valid-Until");
304 // if we have a Valid-Until header in the Release file, use it as default
305 if (StrValidUntil
.empty() == false)
307 if(RFC1123StrToTime(StrValidUntil
.c_str(), ValidUntil
) == false)
309 if (ErrorText
!= NULL
)
310 strprintf(*ErrorText
, _("Invalid 'Valid-Until' entry in Release file %s"), Filename
.c_str());
314 // get the user settings for this archive and use what expires earlier
315 time_t MaxAge
= d
->ValidUntilMax
;
318 MaxAge
= _config
->FindI("Acquire::Max-ValidTime", 0);
319 if (Label
.empty() == false)
320 MaxAge
= _config
->FindI(("Acquire::Max-ValidTime::" + Label
).c_str(), MaxAge
);
322 time_t MinAge
= d
->ValidUntilMin
;
325 MinAge
= _config
->FindI("Acquire::Min-ValidTime", 0);
326 if (Label
.empty() == false)
327 MinAge
= _config
->FindI(("Acquire::Min-ValidTime::" + Label
).c_str(), MinAge
);
330 if (MinAge
!= 0 && ValidUntil
!= 0) {
331 time_t const min_date
= Date
+ MinAge
;
332 if (ValidUntil
< min_date
)
333 ValidUntil
= min_date
;
336 time_t const max_date
= Date
+ MaxAge
;
337 if (ValidUntil
== 0 || ValidUntil
> max_date
)
338 ValidUntil
= max_date
;
342 LoadedSuccessfully
= TRI_YES
;
346 metaIndex
* debReleaseIndex::UnloadedClone() const /*{{{*/
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);
353 return new debReleaseIndex(URI
, Dist
);
356 bool debReleaseIndex::parseSumData(const char *&Start
, const char *End
, /*{{{*/
357 std::string
&Name
, std::string
&Hash
, unsigned long long &Size
)
362 /* Skip over the first blank */
363 while ((*Start
== '\t' || *Start
== ' ' || *Start
== '\n' || *Start
== '\r')
369 /* Move EntryEnd to the end of the first entry (the hash) */
370 const char *EntryEnd
= Start
;
371 while ((*EntryEnd
!= '\t' && *EntryEnd
!= ' ')
377 Hash
.append(Start
, EntryEnd
-Start
);
379 /* Skip over intermediate blanks */
381 while (*Start
== '\t' || *Start
== ' ')
387 /* Find the end of the second entry (the size) */
388 while ((*EntryEnd
!= '\t' && *EntryEnd
!= ' ' )
394 Size
= strtoull (Start
, NULL
, 10);
396 /* Skip over intermediate blanks */
398 while (*Start
== '\t' || *Start
== ' ')
404 /* Find the end of the third entry (the filename) */
405 while ((*EntryEnd
!= '\t' && *EntryEnd
!= ' ' &&
406 *EntryEnd
!= '\n' && *EntryEnd
!= '\r')
410 Name
.append(Start
, EntryEnd
-Start
);
411 Start
= EntryEnd
; //prepare for the next round
416 bool debReleaseIndex::GetIndexes(pkgAcquire
*Owner
, bool const &GetAll
)/*{{{*/
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"),
424 // special case for --print-uris
427 for (std::vector
<IndexTarget
>::const_iterator Target
= targets
.begin(); Target
!= targets
.end(); ++Target
)
428 new pkgAcqIndex(Owner
, TransactionManager
, *Target
);
434 // ReleaseIndex::Set* TriState options /*{{{*/
435 bool debReleaseIndex::SetTrusted(TriState
const pTrusted
)
437 if (Trusted
== TRI_UNSET
)
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());
444 bool debReleaseIndex::SetCheckValidUntil(TriState
const pCheckValidUntil
)
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());
452 bool debReleaseIndex::SetValidUntilMin(time_t const Valid
)
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());
460 bool debReleaseIndex::SetValidUntilMax(time_t const Valid
)
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());
468 bool debReleaseIndex::SetSignedBy(std::string
const &pSignedBy
)
470 if (SignedBy
.empty() == true && pSignedBy
.empty() == false)
472 if (pSignedBy
[0] == '/') // no check for existence as we could be chrooting later or such things
473 ; // absolute path to a keyring file
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");
485 SignedBy
= pSignedBy
;
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());
492 // ReleaseIndex::IsTrusted /*{{{*/
493 bool debReleaseIndex::IsTrusted() const
495 if (Trusted
== TRI_YES
)
497 else if (Trusted
== TRI_NO
)
501 if(_config
->FindB("APT::Authentication::TrustCDROM", false))
502 if(URI
.substr(0,strlen("cdrom:")) == "cdrom:")
505 if (FileExists(MetaIndexFile("Release.gpg")))
508 return FileExists(MetaIndexFile("InRelease"));
511 std::vector
<pkgIndexFile
*> *debReleaseIndex::GetIndexFiles() /*{{{*/
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
)
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
));
533 static bool ReleaseFileName(debReleaseIndex
const * const That
, std::string
&ReleaseFile
)/*{{{*/
535 ReleaseFile
= That
->MetaIndexFile("InRelease");
536 bool releaseExists
= false;
537 if (FileExists(ReleaseFile
) == true)
538 releaseExists
= true;
541 ReleaseFile
= That
->MetaIndexFile("Release");
542 if (FileExists(ReleaseFile
))
543 releaseExists
= true;
545 return releaseExists
;
548 bool debReleaseIndex::Merge(pkgCacheGenerator
&Gen
,OpProgress
* /*Prog*/) const/*{{{*/
550 std::string ReleaseFile
;
551 bool const releaseExists
= ReleaseFileName(this, ReleaseFile
);
554 if (Gen
.SelectReleaseFile(ReleaseFile
, Tmp
.Host
) == false)
555 return _error
->Error("Problem with SelectReleaseFile %s", ReleaseFile
.c_str());
557 if (releaseExists
== false)
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)
565 if (_error
->PendingError() == true)
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
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
;
578 pkgTagFile
TagFile(&Rel
, Rel
.Size());
579 pkgTagSection Section
;
580 if (_error
->PendingError() == true || TagFile
.Step(Section
) == false)
584 #define APT_INRELEASE(TYPE, TAG, STORE) \
585 data = Section.FindS(TAG); \
586 if (data.empty() == false) \
588 map_stringitem_t const storage = Gen.StoreString(pkgCacheGenerator::TYPE, data); \
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
)
597 Section
.FindFlag("NotAutomatic", File
->Flags
, pkgCache::Flag::NotAutomatic
);
598 Section
.FindFlag("ButAutomaticUpgrades", File
->Flags
, pkgCache::Flag::ButAutomaticUpgrades
);
600 return !_error
->PendingError();
603 // ReleaseIndex::FindInCache - Find this index /*{{{*/
604 pkgCache::RlsFileIterator
debReleaseIndex::FindInCache(pkgCache
&Cache
, bool const ModifyCheck
) const
606 std::string ReleaseFile
;
607 bool const releaseExists
= ReleaseFileName(this, ReleaseFile
);
609 pkgCache::RlsFileIterator File
= Cache
.RlsFileBegin();
610 for (; File
.end() == false; ++File
)
612 if (File
->FileName
== 0 || ReleaseFile
!= File
.FileName())
615 // empty means the file does not exist by "design"
616 if (ModifyCheck
== false || (releaseExists
== false && File
->Size
== 0))
620 if (stat(File
.FileName(),&St
) != 0)
622 if (_config
->FindB("Debug::pkgCacheGen", false))
623 std::clog
<< "ReleaseIndex::FindInCache - stat failed on " << File
.FileName() << std::endl
;
624 return pkgCache::RlsFileIterator(Cache
);
626 if ((unsigned)St
.st_size
!= File
->Size
|| St
.st_mtime
!= File
->mtime
)
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
);
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
)
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
, ',');
649 Values
= defaultValues
;
651 if ((val
= Options
.find(Name
+ "+")) != Options
.end())
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
);
658 if ((val
= Options
.find(Name
+ "-")) != Options
.end())
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
)
663 std::vector
<std::string
>::iterator kill
= std::find(Values
.begin(), Values
.end(), *minus
);
664 if (kill
!= Values
.end())
671 class APT_HIDDEN debSLTypeDebian
: public pkgSourceList::Type
/*{{{*/
673 metaIndex::TriState
GetTriStateOption(std::map
<std::string
, std::string
>const &Options
, char const * const name
) const
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
;
681 time_t GetTimeOption(std::map
<std::string
, std::string
>const &Options
, char const * const name
) const
683 std::map
<std::string
, std::string
>::const_iterator
const opt
= Options
.find(name
);
684 if (opt
== Options
.end())
686 return strtoull(opt
->second
.c_str(), NULL
, 10);
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
695 debReleaseIndex
*Deb
= NULL
;
696 for (std::vector
<metaIndex
*>::const_iterator I
= List
.begin();
697 I
!= List
.end(); ++I
)
699 // We only worry about debian entries here
700 if (strcmp((*I
)->GetType(), "deb") != 0)
703 /* This check insures that there will be only one Release file
704 queued for all the Packages files and Sources files it
706 if ((*I
)->GetURI() == URI
&& (*I
)->GetDist() == Dist
)
708 Deb
= dynamic_cast<debReleaseIndex
*>(*I
);
714 // No currently created Release file indexes this entry, so we create a new one.
717 Deb
= new debReleaseIndex(URI
, Dist
);
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))
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)
735 std::map
<std::string
, std::string
>::const_iterator
const signedby
= Options
.find("signed-by");
736 if (signedby
== Options
.end())
738 if (Deb
->SetSignedBy("") == false)
743 if (Deb
->SetSignedBy(signedby
->second
) == false)
750 debSLTypeDebian(char const * const Name
, char const * const Label
) : Type(Name
, Label
)
755 class APT_HIDDEN debSLTypeDeb
: public debSLTypeDebian
/*{{{*/
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
763 return CreateItemInternal(List
, URI
, Dist
, Section
, false, Options
);
766 debSLTypeDeb() : debSLTypeDebian("deb", "Debian binary tree")
771 class APT_HIDDEN debSLTypeDebSrc
: public debSLTypeDebian
/*{{{*/
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
779 return CreateItemInternal(List
, URI
, Dist
, Section
, true, Options
);
782 debSLTypeDebSrc() : debSLTypeDebian("deb-src", "Debian source tree")
788 debDebFileMetaIndex::debDebFileMetaIndex(std::string
const &DebFile
) /*{{{*/
789 : metaIndex(DebFile
, "local-uri", "deb-dist"), d(NULL
), DebFile(DebFile
)
791 DebIndex
= new debDebPkgFileIndex(DebFile
);
792 Indexes
= new std::vector
<pkgIndexFile
*>();
793 Indexes
->push_back(DebIndex
);
795 debDebFileMetaIndex::~debDebFileMetaIndex() {}
797 class APT_HIDDEN debSLTypeDebFile
: public pkgSourceList::Type
/*{{{*/
801 bool CreateItem(std::vector
<metaIndex
*> &List
, std::string
const &URI
,
802 std::string
const &/*Dist*/, std::string
const &/*Section*/,
803 std::map
<std::string
, std::string
> const &/*Options*/) const APT_OVERRIDE
805 metaIndex
*mi
= new debDebFileMetaIndex(URI
);
810 debSLTypeDebFile() : Type("deb-file", "Debian local deb file")
816 APT_HIDDEN debSLTypeDeb _apt_DebType
;
817 APT_HIDDEN debSLTypeDebSrc _apt_DebSrcType
;
818 APT_HIDDEN debSLTypeDebFile _apt_DebFileType
;