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>
31 class APT_HIDDEN debReleaseIndexPrivate
/*{{{*/
34 struct APT_HIDDEN debSectionEntry
37 std::vector
<std::string
> Targets
;
38 std::vector
<std::string
> Architectures
;
39 std::vector
<std::string
> Languages
;
43 std::vector
<debSectionEntry
> DebEntries
;
44 std::vector
<debSectionEntry
> DebSrcEntries
;
46 metaIndex::TriState CheckValidUntil
;
50 debReleaseIndexPrivate() : CheckValidUntil(metaIndex::TRI_UNSET
), ValidUntilMin(0), ValidUntilMax(0) {}
53 // ReleaseIndex::MetaIndex* - display helpers /*{{{*/
54 std::string
debReleaseIndex::MetaIndexInfo(const char *Type
) const
56 std::string Info
= ::URI::ArchiveOnly(URI
) + ' ';
57 if (Dist
[Dist
.size() - 1] == '/')
68 std::string
debReleaseIndex::Describe() const
70 return MetaIndexInfo("Release");
73 std::string
debReleaseIndex::MetaIndexFile(const char *Type
) const
75 return _config
->FindDir("Dir::State::lists") +
76 URItoFileName(MetaIndexURI(Type
));
79 std::string
debReleaseIndex::MetaIndexURI(const char *Type
) const
85 else if (Dist
[Dist
.size()-1] == '/')
88 Res
= URI
+ "dists/" + Dist
+ "/";
94 // ReleaseIndex Con- and Destructors /*{{{*/
95 debReleaseIndex::debReleaseIndex(std::string
const &URI
, std::string
const &Dist
) :
96 metaIndex(URI
, Dist
, "deb"), d(new debReleaseIndexPrivate())
98 debReleaseIndex::debReleaseIndex(std::string
const &URI
, std::string
const &Dist
, bool const pTrusted
) :
99 metaIndex(URI
, Dist
, "deb"), d(new debReleaseIndexPrivate())
101 Trusted
= pTrusted
? TRI_YES
: TRI_NO
;
103 debReleaseIndex::~debReleaseIndex() {
108 // ReleaseIndex::GetIndexTargets /*{{{*/
109 static void GetIndexTargetsFor(char const * const Type
, std::string
const &URI
, std::string
const &Dist
,
110 std::vector
<debReleaseIndexPrivate::debSectionEntry
> const &entries
,
111 std::vector
<IndexTarget
> &IndexTargets
)
113 bool const flatArchive
= (Dist
[Dist
.length() - 1] == '/');
114 std::string baseURI
= URI
;
121 baseURI
+= "dists/" + Dist
+ "/";
122 std::string
const Release
= (Dist
== "/") ? "" : Dist
;
123 std::string
const Site
= ::URI::ArchiveOnly(URI
);
125 std::string DefCompressionTypes
;
127 std::vector
<std::string
> types
= APT::Configuration::getCompressionTypes();
128 if (types
.empty() == false)
130 std::ostringstream os
;
131 std::copy(types
.begin(), types
.end()-1, std::ostream_iterator
<std::string
>(os
, " "));
132 os
<< *types
.rbegin();
133 DefCompressionTypes
= os
.str();
136 bool const GzipIndex
= _config
->FindB("Acquire::GzipIndexes", false);
137 for (std::vector
<debReleaseIndexPrivate::debSectionEntry
>::const_iterator E
= entries
.begin(); E
!= entries
.end(); ++E
)
139 for (std::vector
<std::string
>::const_iterator T
= E
->Targets
.begin(); T
!= E
->Targets
.end(); ++T
)
141 #define APT_T_CONFIG_STR(X, Y) _config->Find(std::string("Acquire::IndexTargets::") + Type + "::" + *T + "::" + (X), (Y))
142 #define APT_T_CONFIG_BOOL(X, Y) _config->FindB(std::string("Acquire::IndexTargets::") + Type + "::" + *T + "::" + (X), (Y))
143 std::string
const tplMetaKey
= APT_T_CONFIG_STR(flatArchive
? "flatMetaKey" : "MetaKey", "");
144 std::string
const tplShortDesc
= APT_T_CONFIG_STR("ShortDescription", "");
145 std::string
const tplLongDesc
= "$(SITE) " + APT_T_CONFIG_STR(flatArchive
? "flatDescription" : "Description", "");
146 bool const IsOptional
= APT_T_CONFIG_BOOL("Optional", true);
147 bool const KeepCompressed
= APT_T_CONFIG_BOOL("KeepCompressed", GzipIndex
);
148 bool const UsePDiffs
= APT_T_CONFIG_BOOL("PDiffs", E
->UsePDiffs
);
149 std::string
const CompressionTypes
= APT_T_CONFIG_STR("CompressionTypes", DefCompressionTypes
);
150 #undef APT_T_CONFIG_BOOL
151 #undef APT_T_CONFIG_STR
152 if (tplMetaKey
.empty())
155 for (std::vector
<std::string
>::const_iterator L
= E
->Languages
.begin(); L
!= E
->Languages
.end(); ++L
)
157 if (*L
== "none" && tplMetaKey
.find("$(LANGUAGE)") != std::string::npos
)
160 for (std::vector
<std::string
>::const_iterator A
= E
->Architectures
.begin(); A
!= E
->Architectures
.end(); ++A
)
162 // available in templates
163 std::map
<std::string
, std::string
> Options
;
164 Options
.insert(std::make_pair("SITE", Site
));
165 Options
.insert(std::make_pair("RELEASE", Release
));
166 if (tplMetaKey
.find("$(COMPONENT)") != std::string::npos
)
167 Options
.insert(std::make_pair("COMPONENT", E
->Name
));
168 if (tplMetaKey
.find("$(LANGUAGE)") != std::string::npos
)
169 Options
.insert(std::make_pair("LANGUAGE", *L
));
170 if (tplMetaKey
.find("$(ARCHITECTURE)") != std::string::npos
)
171 Options
.insert(std::make_pair("ARCHITECTURE", *A
));
173 std::string MetaKey
= tplMetaKey
;
174 std::string ShortDesc
= tplShortDesc
;
175 std::string LongDesc
= tplLongDesc
;
176 for (std::map
<std::string
, std::string
>::const_iterator O
= Options
.begin(); O
!= Options
.end(); ++O
)
178 MetaKey
= SubstVar(MetaKey
, std::string("$(") + O
->first
+ ")", O
->second
);
179 ShortDesc
= SubstVar(ShortDesc
, std::string("$(") + O
->first
+ ")", O
->second
);
180 LongDesc
= SubstVar(LongDesc
, std::string("$(") + O
->first
+ ")", O
->second
);
183 // not available in templates, but in the indextarget
184 Options
.insert(std::make_pair("BASE_URI", baseURI
));
185 Options
.insert(std::make_pair("REPO_URI", URI
));
186 Options
.insert(std::make_pair("TARGET_OF", Type
));
187 Options
.insert(std::make_pair("CREATED_BY", *T
));
189 Options
.insert(std::make_pair("PDIFFS", "yes"));
191 Options
.insert(std::make_pair("PDIFFS", "no"));
192 Options
.insert(std::make_pair("COMPRESSIONTYPES", CompressionTypes
));
198 Options
.find("BASE_URI")->second
+ MetaKey
,
203 IndexTargets
.push_back(Target
);
205 if (tplMetaKey
.find("$(ARCHITECTURE)") == std::string::npos
)
210 if (tplMetaKey
.find("$(LANGUAGE)") == std::string::npos
)
218 std::vector
<IndexTarget
> debReleaseIndex::GetIndexTargets() const
220 std::vector
<IndexTarget
> IndexTargets
;
221 GetIndexTargetsFor("deb-src", URI
, Dist
, d
->DebSrcEntries
, IndexTargets
);
222 GetIndexTargetsFor("deb", URI
, Dist
, d
->DebEntries
, IndexTargets
);
226 void debReleaseIndex::AddComponent(bool const isSrc
, std::string
const &Name
,/*{{{*/
227 std::vector
<std::string
> const &Targets
,
228 std::vector
<std::string
> const &Architectures
,
229 std::vector
<std::string
> Languages
,
230 bool const usePDiffs
)
232 if (Languages
.empty() == true)
233 Languages
.push_back("none");
234 debReleaseIndexPrivate::debSectionEntry
const entry
= {
235 Name
, Targets
, Architectures
, Languages
, usePDiffs
238 d
->DebSrcEntries
.push_back(entry
);
240 d
->DebEntries
.push_back(entry
);
244 bool debReleaseIndex::Load(std::string
const &Filename
, std::string
* const ErrorText
)/*{{{*/
246 LoadedSuccessfully
= TRI_NO
;
248 if (OpenMaybeClearSignedFile(Filename
, Fd
) == false)
251 pkgTagFile
TagFile(&Fd
, Fd
.Size());
252 if (_error
->PendingError() == true)
254 if (ErrorText
!= NULL
)
255 strprintf(*ErrorText
, _("Unable to parse Release file %s"),Filename
.c_str());
259 pkgTagSection Section
;
260 const char *Start
, *End
;
261 if (TagFile
.Step(Section
) == false)
263 if (ErrorText
!= NULL
)
264 strprintf(*ErrorText
, _("No sections in Release file %s"), Filename
.c_str());
267 // FIXME: find better tag name
268 SupportsAcquireByHash
= Section
.FindB("Acquire-By-Hash", false);
270 Suite
= Section
.FindS("Suite");
271 Codename
= Section
.FindS("Codename");
273 bool FoundHashSum
= false;
274 for (int i
=0;HashString::SupportedHashes()[i
] != NULL
; i
++)
276 if (!Section
.Find(HashString::SupportedHashes()[i
], Start
, End
))
281 unsigned long long Size
;
284 if (!parseSumData(Start
, End
, Name
, Hash
, Size
))
287 if (Entries
.find(Name
) == Entries
.end())
289 metaIndex::checkSum
*Sum
= new metaIndex::checkSum
;
290 Sum
->MetaKeyFilename
= Name
;
292 Sum
->Hashes
.FileSize(Size
);
293 APT_IGNORE_DEPRECATED(Sum
->Hash
= HashString(HashString::SupportedHashes()[i
],Hash
);)
296 Entries
[Name
]->Hashes
.push_back(HashString(HashString::SupportedHashes()[i
],Hash
));
301 if(FoundHashSum
== false)
303 if (ErrorText
!= NULL
)
304 strprintf(*ErrorText
, _("No Hash entry in Release file %s"), Filename
.c_str());
308 std::string
const StrDate
= Section
.FindS("Date");
309 if (RFC1123StrToTime(StrDate
.c_str(), Date
) == false)
311 if (ErrorText
!= NULL
)
312 strprintf(*ErrorText
, _("Invalid 'Date' entry in Release file %s"), Filename
.c_str());
316 bool CheckValidUntil
= _config
->FindB("Acquire::Check-Valid-Until", true);
317 if (d
->CheckValidUntil
== metaIndex::TRI_NO
)
318 CheckValidUntil
= false;
319 else if (d
->CheckValidUntil
== metaIndex::TRI_YES
)
320 CheckValidUntil
= true;
322 if (CheckValidUntil
== true)
324 std::string
const Label
= Section
.FindS("Label");
325 std::string
const StrValidUntil
= Section
.FindS("Valid-Until");
327 // if we have a Valid-Until header in the Release file, use it as default
328 if (StrValidUntil
.empty() == false)
330 if(RFC1123StrToTime(StrValidUntil
.c_str(), ValidUntil
) == false)
332 if (ErrorText
!= NULL
)
333 strprintf(*ErrorText
, _("Invalid 'Valid-Until' entry in Release file %s"), Filename
.c_str());
337 // get the user settings for this archive and use what expires earlier
338 time_t MaxAge
= d
->ValidUntilMax
;
341 MaxAge
= _config
->FindI("Acquire::Max-ValidTime", 0);
342 if (Label
.empty() == false)
343 MaxAge
= _config
->FindI(("Acquire::Max-ValidTime::" + Label
).c_str(), MaxAge
);
345 time_t MinAge
= d
->ValidUntilMin
;
348 MinAge
= _config
->FindI("Acquire::Min-ValidTime", 0);
349 if (Label
.empty() == false)
350 MinAge
= _config
->FindI(("Acquire::Min-ValidTime::" + Label
).c_str(), MinAge
);
353 if (MinAge
!= 0 && ValidUntil
!= 0) {
354 time_t const min_date
= Date
+ MinAge
;
355 if (ValidUntil
< min_date
)
356 ValidUntil
= min_date
;
359 time_t const max_date
= Date
+ MaxAge
;
360 if (ValidUntil
== 0 || ValidUntil
> max_date
)
361 ValidUntil
= max_date
;
365 LoadedSuccessfully
= TRI_YES
;
369 metaIndex
* debReleaseIndex::UnloadedClone() const /*{{{*/
371 if (Trusted
== TRI_NO
)
372 return new debReleaseIndex(URI
, Dist
, false);
373 else if (Trusted
== TRI_YES
)
374 return new debReleaseIndex(URI
, Dist
, true);
376 return new debReleaseIndex(URI
, Dist
);
379 bool debReleaseIndex::parseSumData(const char *&Start
, const char *End
, /*{{{*/
380 std::string
&Name
, std::string
&Hash
, unsigned long long &Size
)
385 /* Skip over the first blank */
386 while ((*Start
== '\t' || *Start
== ' ' || *Start
== '\n' || *Start
== '\r')
392 /* Move EntryEnd to the end of the first entry (the hash) */
393 const char *EntryEnd
= Start
;
394 while ((*EntryEnd
!= '\t' && *EntryEnd
!= ' ')
400 Hash
.append(Start
, EntryEnd
-Start
);
402 /* Skip over intermediate blanks */
404 while (*Start
== '\t' || *Start
== ' ')
410 /* Find the end of the second entry (the size) */
411 while ((*EntryEnd
!= '\t' && *EntryEnd
!= ' ' )
417 Size
= strtoull (Start
, NULL
, 10);
419 /* Skip over intermediate blanks */
421 while (*Start
== '\t' || *Start
== ' ')
427 /* Find the end of the third entry (the filename) */
428 while ((*EntryEnd
!= '\t' && *EntryEnd
!= ' ' &&
429 *EntryEnd
!= '\n' && *EntryEnd
!= '\r')
433 Name
.append(Start
, EntryEnd
-Start
);
434 Start
= EntryEnd
; //prepare for the next round
439 bool debReleaseIndex::GetIndexes(pkgAcquire
*Owner
, bool const &GetAll
)/*{{{*/
441 std::vector
<IndexTarget
> const targets
= GetIndexTargets();
442 #define APT_TARGET(X) IndexTarget("", X, MetaIndexInfo(X), MetaIndexURI(X), false, false, std::map<std::string,std::string>())
443 pkgAcqMetaClearSig
* const TransactionManager
= new pkgAcqMetaClearSig(Owner
,
444 APT_TARGET("InRelease"), APT_TARGET("Release"), APT_TARGET("Release.gpg"),
447 // special case for --print-uris
450 for (std::vector
<IndexTarget
>::const_iterator Target
= targets
.begin(); Target
!= targets
.end(); ++Target
)
451 new pkgAcqIndex(Owner
, TransactionManager
, *Target
);
457 // ReleaseIndex::Set* TriState options /*{{{*/
458 bool debReleaseIndex::SetTrusted(TriState
const pTrusted
)
460 if (Trusted
== TRI_UNSET
)
462 else if (Trusted
!= pTrusted
)
463 // TRANSLATOR: The first is an option name from sources.list manpage, the other two URI and Suite
464 return _error
->Error(_("Conflicting values set for option %s concerning source %s %s"), "Trusted", URI
.c_str(), Dist
.c_str());
467 bool debReleaseIndex::SetCheckValidUntil(TriState
const pCheckValidUntil
)
469 if (d
->CheckValidUntil
== TRI_UNSET
)
470 d
->CheckValidUntil
= pCheckValidUntil
;
471 else if (d
->CheckValidUntil
!= pCheckValidUntil
)
472 return _error
->Error(_("Conflicting values set for option %s concerning source %s %s"), "Check-Valid-Until", URI
.c_str(), Dist
.c_str());
475 bool debReleaseIndex::SetValidUntilMin(time_t const Valid
)
477 if (d
->ValidUntilMin
== 0)
478 d
->ValidUntilMin
= Valid
;
479 else if (d
->ValidUntilMin
!= Valid
)
480 return _error
->Error(_("Conflicting values set for option %s concerning source %s %s"), "Min-ValidTime", URI
.c_str(), Dist
.c_str());
483 bool debReleaseIndex::SetValidUntilMax(time_t const Valid
)
485 if (d
->ValidUntilMax
== 0)
486 d
->ValidUntilMax
= Valid
;
487 else if (d
->ValidUntilMax
!= Valid
)
488 return _error
->Error(_("Conflicting values set for option %s concerning source %s %s"), "Max-ValidTime", URI
.c_str(), Dist
.c_str());
491 bool debReleaseIndex::SetSignedBy(std::string
const &pSignedBy
)
493 if (SignedBy
.empty() == true && pSignedBy
.empty() == false)
495 if (pSignedBy
[0] == '/') // no check for existence as we could be chrooting later or such things
496 ; // absolute path to a keyring file
499 // we could go all fancy and allow short/long/string matches as gpgv/apt-key does,
500 // but fingerprints are harder to fake than the others and this option is set once,
501 // not interactively all the time so easy to type is not really a concern.
502 std::string finger
= pSignedBy
;
503 finger
.erase(std::remove(finger
.begin(), finger
.end(), ' '), finger
.end());
504 std::transform(finger
.begin(), finger
.end(), finger
.begin(), ::toupper
);
505 if (finger
.length() != 40 || finger
.find_first_not_of("0123456789ABCDEF") != std::string::npos
)
506 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");
508 SignedBy
= pSignedBy
;
510 else if (SignedBy
!= pSignedBy
)
511 return _error
->Error(_("Conflicting values set for option %s concerning source %s %s"), "Signed-By", URI
.c_str(), Dist
.c_str());
515 // ReleaseIndex::IsTrusted /*{{{*/
516 bool debReleaseIndex::IsTrusted() const
518 if (Trusted
== TRI_YES
)
520 else if (Trusted
== TRI_NO
)
524 if(_config
->FindB("APT::Authentication::TrustCDROM", false))
525 if(URI
.substr(0,strlen("cdrom:")) == "cdrom:")
528 if (FileExists(MetaIndexFile("Release.gpg")))
531 return FileExists(MetaIndexFile("InRelease"));
534 std::vector
<pkgIndexFile
*> *debReleaseIndex::GetIndexFiles() /*{{{*/
539 Indexes
= new std::vector
<pkgIndexFile
*>();
540 std::vector
<IndexTarget
> const Targets
= GetIndexTargets();
541 bool const istrusted
= IsTrusted();
542 for (std::vector
<IndexTarget
>::const_iterator T
= Targets
.begin(); T
!= Targets
.end(); ++T
)
544 std::string
const TargetName
= T
->Option(IndexTarget::CREATED_BY
);
545 if (TargetName
== "Packages")
546 Indexes
->push_back(new debPackagesIndex(*T
, istrusted
));
547 else if (TargetName
== "Sources")
548 Indexes
->push_back(new debSourcesIndex(*T
, istrusted
));
549 else if (TargetName
== "Translations")
550 Indexes
->push_back(new debTranslationsIndex(*T
));
556 static bool ReleaseFileName(debReleaseIndex
const * const That
, std::string
&ReleaseFile
)/*{{{*/
558 ReleaseFile
= That
->MetaIndexFile("InRelease");
559 bool releaseExists
= false;
560 if (FileExists(ReleaseFile
) == true)
561 releaseExists
= true;
564 ReleaseFile
= That
->MetaIndexFile("Release");
565 if (FileExists(ReleaseFile
))
566 releaseExists
= true;
568 return releaseExists
;
571 bool debReleaseIndex::Merge(pkgCacheGenerator
&Gen
,OpProgress
* /*Prog*/) const/*{{{*/
573 std::string ReleaseFile
;
574 bool const releaseExists
= ReleaseFileName(this, ReleaseFile
);
577 if (Gen
.SelectReleaseFile(ReleaseFile
, Tmp
.Host
) == false)
578 return _error
->Error("Problem with SelectReleaseFile %s", ReleaseFile
.c_str());
580 if (releaseExists
== false)
584 // Beware: The 'Release' file might be clearsigned in case the
585 // signature for an 'InRelease' file couldn't be checked
586 if (OpenMaybeClearSignedFile(ReleaseFile
, Rel
) == false)
588 if (_error
->PendingError() == true)
591 // Store the IMS information
592 pkgCache::RlsFileIterator File
= Gen
.GetCurRlsFile();
593 pkgCacheGenerator::Dynamic
<pkgCache::RlsFileIterator
> DynFile(File
);
594 // Rel can't be used as this is potentially a temporary file
596 if (stat(ReleaseFile
.c_str(), &Buf
) != 0)
597 return _error
->Errno("fstat", "Unable to stat file %s", ReleaseFile
.c_str());
598 File
->Size
= Buf
.st_size
;
599 File
->mtime
= Buf
.st_mtime
;
601 pkgTagFile
TagFile(&Rel
, Rel
.Size());
602 pkgTagSection Section
;
603 if (_error
->PendingError() == true || TagFile
.Step(Section
) == false)
607 #define APT_INRELEASE(TYPE, TAG, STORE) \
608 data = Section.FindS(TAG); \
609 if (data.empty() == false) \
611 map_stringitem_t const storage = Gen.StoreString(pkgCacheGenerator::TYPE, data); \
614 APT_INRELEASE(MIXED
, "Suite", File
->Archive
)
615 APT_INRELEASE(VERSIONNUMBER
, "Version", File
->Version
)
616 APT_INRELEASE(MIXED
, "Origin", File
->Origin
)
617 APT_INRELEASE(MIXED
, "Codename", File
->Codename
)
618 APT_INRELEASE(MIXED
, "Label", File
->Label
)
620 Section
.FindFlag("NotAutomatic", File
->Flags
, pkgCache::Flag::NotAutomatic
);
621 Section
.FindFlag("ButAutomaticUpgrades", File
->Flags
, pkgCache::Flag::ButAutomaticUpgrades
);
623 return !_error
->PendingError();
626 // ReleaseIndex::FindInCache - Find this index /*{{{*/
627 pkgCache::RlsFileIterator
debReleaseIndex::FindInCache(pkgCache
&Cache
, bool const ModifyCheck
) const
629 std::string ReleaseFile
;
630 bool const releaseExists
= ReleaseFileName(this, ReleaseFile
);
632 pkgCache::RlsFileIterator File
= Cache
.RlsFileBegin();
633 for (; File
.end() == false; ++File
)
635 if (File
->FileName
== 0 || ReleaseFile
!= File
.FileName())
638 // empty means the file does not exist by "design"
639 if (ModifyCheck
== false || (releaseExists
== false && File
->Size
== 0))
643 if (stat(File
.FileName(),&St
) != 0)
645 if (_config
->FindB("Debug::pkgCacheGen", false))
646 std::clog
<< "ReleaseIndex::FindInCache - stat failed on " << File
.FileName() << std::endl
;
647 return pkgCache::RlsFileIterator(Cache
);
649 if ((unsigned)St
.st_size
!= File
->Size
|| St
.st_mtime
!= File
->mtime
)
651 if (_config
->FindB("Debug::pkgCacheGen", false))
652 std::clog
<< "ReleaseIndex::FindInCache - size (" << St
.st_size
<< " <> " << File
->Size
653 << ") or mtime (" << St
.st_mtime
<< " <> " << File
->mtime
654 << ") doesn't match for " << File
.FileName() << std::endl
;
655 return pkgCache::RlsFileIterator(Cache
);
664 static std::vector
<std::string
> parsePlusMinusOptions(std::string
const &Name
, /*{{{*/
665 std::map
<std::string
, std::string
> const &Options
, std::vector
<std::string
> const &defaultValues
)
667 std::map
<std::string
, std::string
>::const_iterator val
= Options
.find(Name
);
668 std::vector
<std::string
> Values
;
669 if (val
!= Options
.end())
670 Values
= VectorizeString(val
->second
, ',');
672 Values
= defaultValues
;
674 if ((val
= Options
.find(Name
+ "+")) != Options
.end())
676 std::vector
<std::string
> const plusArch
= VectorizeString(val
->second
, ',');
677 for (std::vector
<std::string
>::const_iterator plus
= plusArch
.begin(); plus
!= plusArch
.end(); ++plus
)
678 if (std::find(Values
.begin(), Values
.end(), *plus
) == Values
.end())
679 Values
.push_back(*plus
);
681 if ((val
= Options
.find(Name
+ "-")) != Options
.end())
683 std::vector
<std::string
> const minusArch
= VectorizeString(val
->second
, ',');
684 for (std::vector
<std::string
>::const_iterator minus
= minusArch
.begin(); minus
!= minusArch
.end(); ++minus
)
686 std::vector
<std::string
>::iterator kill
= std::find(Values
.begin(), Values
.end(), *minus
);
687 if (kill
!= Values
.end())
694 class APT_HIDDEN debSLTypeDebian
: public pkgSourceList::Type
/*{{{*/
696 metaIndex::TriState
GetTriStateOption(std::map
<std::string
, std::string
>const &Options
, char const * const name
) const
698 std::map
<std::string
, std::string
>::const_iterator
const opt
= Options
.find(name
);
699 if (opt
!= Options
.end())
700 return StringToBool(opt
->second
, false) ? metaIndex::TRI_YES
: metaIndex::TRI_NO
;
701 return metaIndex::TRI_DONTCARE
;
704 time_t GetTimeOption(std::map
<std::string
, std::string
>const &Options
, char const * const name
) const
706 std::map
<std::string
, std::string
>::const_iterator
const opt
= Options
.find(name
);
707 if (opt
== Options
.end())
709 return strtoull(opt
->second
.c_str(), NULL
, 10);
714 bool CreateItemInternal(std::vector
<metaIndex
*> &List
, std::string
const &URI
,
715 std::string
const &Dist
, std::string
const &Section
,
716 bool const &IsSrc
, std::map
<std::string
, std::string
> const &Options
) const
718 debReleaseIndex
*Deb
= NULL
;
719 for (std::vector
<metaIndex
*>::const_iterator I
= List
.begin();
720 I
!= List
.end(); ++I
)
722 // We only worry about debian entries here
723 if (strcmp((*I
)->GetType(), "deb") != 0)
726 /* This check insures that there will be only one Release file
727 queued for all the Packages files and Sources files it
729 if ((*I
)->GetURI() == URI
&& (*I
)->GetDist() == Dist
)
731 Deb
= dynamic_cast<debReleaseIndex
*>(*I
);
737 // No currently created Release file indexes this entry, so we create a new one.
740 Deb
= new debReleaseIndex(URI
, Dist
);
744 std::vector
<std::string
> const alltargets
= _config
->FindVector(std::string("Acquire::IndexTargets::") + Name
, "", true);
745 std::vector
<std::string
> mytargets
= parsePlusMinusOptions("target", Options
, alltargets
);
746 if (mytargets
.empty() == false)
747 for (auto const &target
: alltargets
)
749 std::map
<std::string
, std::string
>::const_iterator
const opt
= Options
.find(target
);
750 if (opt
== Options
.end())
752 auto const tarItr
= std::find(mytargets
.begin(), mytargets
.end(), target
);
753 bool const optValue
= StringToBool(opt
->second
);
754 if (optValue
== true && tarItr
== mytargets
.end())
755 mytargets
.push_back(target
);
756 else if (optValue
== false && tarItr
!= mytargets
.end())
757 mytargets
.erase(std::remove(mytargets
.begin(), mytargets
.end(), target
), mytargets
.end());
759 bool UsePDiffs
= _config
->FindB("Acquire::PDiffs", true);
761 std::map
<std::string
, std::string
>::const_iterator
const opt
= Options
.find("pdiffs");
762 if (opt
!= Options
.end())
763 UsePDiffs
= StringToBool(opt
->second
);
769 parsePlusMinusOptions("arch", Options
, APT::Configuration::getArchitectures()),
770 parsePlusMinusOptions("lang", Options
, APT::Configuration::getLanguages(true)),
774 if (Deb
->SetTrusted(GetTriStateOption(Options
, "trusted")) == false ||
775 Deb
->SetCheckValidUntil(GetTriStateOption(Options
, "check-valid-until")) == false ||
776 Deb
->SetValidUntilMax(GetTimeOption(Options
, "valid-until-max")) == false ||
777 Deb
->SetValidUntilMin(GetTimeOption(Options
, "valid-until-min")) == false)
780 std::map
<std::string
, std::string
>::const_iterator
const signedby
= Options
.find("signed-by");
781 if (signedby
== Options
.end())
783 if (Deb
->SetSignedBy("") == false)
788 if (Deb
->SetSignedBy(signedby
->second
) == false)
795 debSLTypeDebian(char const * const Name
, char const * const Label
) : Type(Name
, Label
)
800 class APT_HIDDEN debSLTypeDeb
: public debSLTypeDebian
/*{{{*/
804 bool CreateItem(std::vector
<metaIndex
*> &List
, std::string
const &URI
,
805 std::string
const &Dist
, std::string
const &Section
,
806 std::map
<std::string
, std::string
> const &Options
) const APT_OVERRIDE
808 return CreateItemInternal(List
, URI
, Dist
, Section
, false, Options
);
811 debSLTypeDeb() : debSLTypeDebian("deb", "Debian binary tree")
816 class APT_HIDDEN debSLTypeDebSrc
: public debSLTypeDebian
/*{{{*/
820 bool CreateItem(std::vector
<metaIndex
*> &List
, std::string
const &URI
,
821 std::string
const &Dist
, std::string
const &Section
,
822 std::map
<std::string
, std::string
> const &Options
) const APT_OVERRIDE
824 return CreateItemInternal(List
, URI
, Dist
, Section
, true, Options
);
827 debSLTypeDebSrc() : debSLTypeDebian("deb-src", "Debian source tree")
833 APT_HIDDEN debSLTypeDeb _apt_DebType
;
834 APT_HIDDEN debSLTypeDebSrc _apt_DebSrcType
;