-vector <pkgIndexFile *> *debReleaseIndex::GetIndexFiles() {
- if (Indexes != NULL)
- return Indexes;
-
- Indexes = new vector <pkgIndexFile*>;
- map<string, vector<debSectionEntry const*> >::const_iterator const src = ArchEntries.find("source");
- if (src != ArchEntries.end()) {
- vector<debSectionEntry const*> const SectionEntries = src->second;
- for (vector<debSectionEntry const*>::const_iterator I = SectionEntries.begin();
- I != SectionEntries.end(); ++I)
- Indexes->push_back(new debSourcesIndex (URI, Dist, (*I)->Section, IsTrusted()));
- }
-
- // Only source release
- if (Indexes->empty() == false && ArchEntries.size() == 1)
- return Indexes;
-
- std::vector<std::string> const lang = APT::Configuration::getLanguages(true);
- map<string, set<string> > sections;
- for (map<string, vector<debSectionEntry const*> >::const_iterator a = ArchEntries.begin();
- a != ArchEntries.end(); ++a) {
- if (a->first == "source")
- continue;
- for (vector<debSectionEntry const*>::const_iterator I = a->second.begin();
- I != a->second.end(); ++I) {
- Indexes->push_back(new debPackagesIndex (URI, Dist, (*I)->Section, IsTrusted(), a->first));
- sections[(*I)->Section].insert(lang.begin(), lang.end());
- }
- }
-
- for (map<string, set<string> >::const_iterator s = sections.begin();
- s != sections.end(); ++s)
- for (set<string>::const_iterator l = s->second.begin();
- l != s->second.end(); ++l) {
- if (*l == "none") continue;
- Indexes->push_back(new debTranslationsIndex(URI,Dist,s->first,(*l).c_str()));
- }
-
- return Indexes;
+struct GetIndexFilesClass
+{
+ vector <pkgIndexFile *> * const Indexes;
+ std::string const URI;
+ std::string const Release;
+ bool const IsTrusted;
+
+ void operator()(std::string const &/*baseURI*/, std::string const &TargetName,
+ std::string const &/*URI*/, std::string const &/*ShortDesc*/, std::string const &/*LongDesc*/,
+ bool const /*IsOptional*/, struct SubstVar const * const subst)
+ {
+ if (TargetName == "Packages")
+ {
+ Indexes->push_back(new debPackagesIndex(
+ URI,
+ Release,
+ SubstVar("$(COMPONENT)", subst),
+ IsTrusted,
+ SubstVar("$(ARCHITECTURE)", subst)
+ ));
+ }
+ else if (TargetName == "Sources")
+ Indexes->push_back(new debSourcesIndex(
+ URI,
+ Release,
+ SubstVar("$(COMPONENT)", subst),
+ IsTrusted
+ ));
+ else if (TargetName == "Translations")
+ Indexes->push_back(new debTranslationsIndex(
+ URI,
+ Release,
+ SubstVar("$(COMPONENT)", subst),
+ SubstVar("$(LANGUAGE)", subst)
+ ));
+ }
+
+ GetIndexFilesClass(std::string const &URI, std::string const &Release, bool const IsTrusted) :
+ Indexes(new vector <pkgIndexFile*>), URI(URI), Release(Release), IsTrusted(IsTrusted) {}
+};
+
+std::vector <pkgIndexFile *> *debReleaseIndex::GetIndexFiles()
+{
+ if (Indexes != NULL)
+ return Indexes;
+
+ GetIndexFilesClass comp(URI, Dist, IsTrusted());
+ foreachTarget(URI, Dist, ArchEntries, comp);
+ return Indexes = comp.Indexes;