]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/deb/debmetaindex.cc
rename Calculate- to GetIndexTargets and use it as official API
[apt.git] / apt-pkg / deb / debmetaindex.cc
index c35f3b0a4a13c91f40db6b61f43e8a6207c5dab9..e1f86d20f01fa76fd078914bf169c10ef01e9aa1 100644 (file)
@@ -93,7 +93,7 @@ debReleaseIndex::~debReleaseIndex() {
 template<typename CallC>
 void foreachTarget(std::string const URI, std::string const Dist,
       std::map<std::string, std::vector<debReleaseIndex::debSectionEntry const *> > const &ArchEntries,
-      CallC Call)
+      CallC &Call)
 {
    bool const flatArchive = (Dist[Dist.length() - 1] == '/');
    std::string baseURI = URI;
@@ -116,12 +116,12 @@ void foreachTarget(std::string const URI, std::string const Dist,
       for (std::vector<std::string>::const_iterator T = targets.begin(); T != targets.end(); ++T)
       {
 #define APT_T_CONFIG(X) _config->Find(std::string("APT::Acquire::Targets::deb-src::") + *T + "::" + (X))
-        std::string const URI = APT_T_CONFIG(flatArchive ? "flatURI" : "URI");
+        std::string const MetaKey = APT_T_CONFIG(flatArchive ? "flatMetaKey" : "MetaKey");
         std::string const ShortDesc = APT_T_CONFIG("ShortDescription");
         std::string const LongDesc = APT_T_CONFIG(flatArchive ? "flatDescription" : "Description");
         bool const IsOptional = _config->FindB(std::string("APT::Acquire::Targets::deb-src::") + *T + "::Optional", true);
 #undef APT_T_CONFIG
-        if (URI.empty())
+        if (MetaKey.empty())
            continue;
 
         vector<debReleaseIndex::debSectionEntry const*> const SectionEntries = src->second;
@@ -130,23 +130,24 @@ void foreachTarget(std::string const URI, std::string const Dist,
         {
            for (vector<std::string>::const_iterator l = lang.begin(); l != lang.end(); ++l)
            {
-              if (*l == "none" && URI.find("$(LANGUAGE)") != std::string::npos)
+              if (*l == "none" && MetaKey.find("$(LANGUAGE)") != std::string::npos)
                  continue;
 
-              struct SubstVar subst[] = {
-                 { "$(SITE)", &Site },
-                 { "$(RELEASE)", &Release },
-                 { "$(COMPONENT)", &((*I)->Section) },
-                 { "$(LANGUAGE)", &(*l) },
-                 { NULL, NULL }
-              };
-              Call(baseURI, *T, URI, ShortDesc, LongDesc, IsOptional, subst);
-
-              if (URI.find("$(LANGUAGE)") == std::string::npos)
+              std::map<std::string, std::string> Options;
+              Options.insert(std::make_pair("SITE", Site));
+              Options.insert(std::make_pair("RELEASE", Release));
+              Options.insert(std::make_pair("COMPONENT", (*I)->Section));
+              Options.insert(std::make_pair("LANGUAGE", *l));
+              Options.insert(std::make_pair("ARCHITECTURE", "source"));
+              Options.insert(std::make_pair("BASE_URI", baseURI));
+              Options.insert(std::make_pair("CREATED_BY", *T));
+              Call(MetaKey, ShortDesc, LongDesc, IsOptional, Options);
+
+              if (MetaKey.find("$(LANGUAGE)") == std::string::npos)
                  break;
            }
 
-           if (URI.find("$(COMPONENT)") == std::string::npos)
+           if (MetaKey.find("$(COMPONENT)") == std::string::npos)
               break;
         }
       }
@@ -156,12 +157,12 @@ void foreachTarget(std::string const URI, std::string const Dist,
    for (std::vector<std::string>::const_iterator T = targets.begin(); T != targets.end(); ++T)
    {
 #define APT_T_CONFIG(X) _config->Find(std::string("APT::Acquire::Targets::deb::") + *T + "::" + (X))
-      std::string const URI = APT_T_CONFIG(flatArchive ? "flatURI" : "URI");
+      std::string const MetaKey = APT_T_CONFIG(flatArchive ? "flatMetaKey" : "MetaKey");
       std::string const ShortDesc = APT_T_CONFIG("ShortDescription");
       std::string const LongDesc = APT_T_CONFIG(flatArchive ? "flatDescription" : "Description");
       bool const IsOptional = _config->FindB(std::string("APT::Acquire::Targets::deb::") + *T + "::Optional", true);
 #undef APT_T_CONFIG
-      if (URI.empty())
+      if (MetaKey.empty())
         continue;
 
       for (map<string, vector<debReleaseIndex::debSectionEntry const*> >::const_iterator a = ArchEntries.begin();
@@ -175,28 +176,28 @@ void foreachTarget(std::string const URI, std::string const Dist,
 
            for (vector<std::string>::const_iterator l = lang.begin(); l != lang.end(); ++l)
            {
-              if (*l == "none" && URI.find("$(LANGUAGE)") != std::string::npos)
+              if (*l == "none" && MetaKey.find("$(LANGUAGE)") != std::string::npos)
                  continue;
 
-              struct SubstVar subst[] = {
-                 { "$(SITE)", &Site },
-                 { "$(RELEASE)", &Release },
-                 { "$(COMPONENT)", &((*I)->Section) },
-                 { "$(LANGUAGE)", &(*l) },
-                 { "$(ARCHITECTURE)", &(a->first) },
-                 { NULL, NULL }
-              };
-              Call(baseURI, *T, URI, ShortDesc, LongDesc, IsOptional, subst);
-
-              if (URI.find("$(LANGUAGE)") == std::string::npos)
+              std::map<std::string, std::string> Options;
+              Options.insert(std::make_pair("SITE", Site));
+              Options.insert(std::make_pair("RELEASE", Release));
+              Options.insert(std::make_pair("COMPONENT", (*I)->Section));
+              Options.insert(std::make_pair("LANGUAGE", *l));
+              Options.insert(std::make_pair("ARCHITECTURE", a->first));
+              Options.insert(std::make_pair("BASE_URI", baseURI));
+              Options.insert(std::make_pair("CREATED_BY", *T));
+              Call(MetaKey, ShortDesc, LongDesc, IsOptional, Options);
+
+              if (MetaKey.find("$(LANGUAGE)") == std::string::npos)
                  break;
            }
 
-           if (URI.find("$(COMPONENT)") == std::string::npos)
+           if (MetaKey.find("$(COMPONENT)") == std::string::npos)
               break;
         }
 
-        if (URI.find("$(ARCHITECTURE)") == std::string::npos)
+        if (MetaKey.find("$(ARCHITECTURE)") == std::string::npos)
            break;
       }
    }
@@ -205,39 +206,30 @@ void foreachTarget(std::string const URI, std::string const Dist,
 
 struct ComputeIndexTargetsClass
 {
-   vector <IndexTarget *> * const IndexTargets;
+   vector <IndexTarget> IndexTargets;
 
-   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)
+   void operator()(std::string MetaKey, std::string ShortDesc, std::string LongDesc,
+        bool const IsOptional, std::map<std::string, std::string> Options)
    {
-      std::string const name = SubstVar(URI, subst);
-      IndexTarget * Target;
-      if (IsOptional == true)
-      {
-        Target = new OptionalIndexTarget(
-              name,
-              SubstVar(ShortDesc, subst),
-              SubstVar(LongDesc, subst),
-              baseURI + name
-              );
-      }
-      else
+      for (std::map<std::string, std::string>::const_iterator O = Options.begin(); O != Options.end(); ++O)
       {
-        Target = new IndexTarget(
-              name,
-              SubstVar(ShortDesc, subst),
-              SubstVar(LongDesc, subst),
-              baseURI + name
-              );
+        MetaKey = SubstVar(MetaKey, std::string("$(") + O->first + ")", O->second);
+        ShortDesc = SubstVar(ShortDesc, std::string("$(") + O->first + ")", O->second);
+        LongDesc = SubstVar(LongDesc, std::string("$(") + O->first + ")", O->second);
       }
-      IndexTargets->push_back(Target);
+      IndexTarget Target(
+           MetaKey,
+           ShortDesc,
+           LongDesc,
+           Options.find("BASE_URI")->second + MetaKey,
+           IsOptional,
+           Options
+           );
+      IndexTargets.push_back(Target);
    }
-
-   ComputeIndexTargetsClass() : IndexTargets(new vector <IndexTarget *>) {}
 };
 
-vector <IndexTarget *>* debReleaseIndex::ComputeIndexTargets() const
+std::vector<IndexTarget> debReleaseIndex::GetIndexTargets() const
 {
    ComputeIndexTargetsClass comp;
    foreachTarget(URI, Dist, ArchEntries, comp);
@@ -255,15 +247,15 @@ bool debReleaseIndex::GetIndexes(pkgAcquire *Owner, bool const &GetAll) const
       iR->SetTrusted(false);
 
    // special case for --print-uris
-   vector <IndexTarget *> const * const targets = ComputeIndexTargets();
-#define APT_TARGET(X) IndexTarget("", X, MetaIndexInfo(X), MetaIndexURI(X))
+   std::vector<IndexTarget> const targets = GetIndexTargets();
+#define APT_TARGET(X) IndexTarget("", X, MetaIndexInfo(X), MetaIndexURI(X), false, std::map<std::string,std::string>())
    pkgAcqMetaBase * const TransactionManager = new pkgAcqMetaClearSig(Owner,
         APT_TARGET("InRelease"), APT_TARGET("Release"), APT_TARGET("Release.gpg"),
         targets, iR);
 #undef APT_TARGET
    if (GetAll)
    {
-      for (vector <IndexTarget*>::const_iterator Target = targets->begin(); Target != targets->end(); ++Target)
+      for (std::vector<IndexTarget>::const_iterator Target = targets.begin(); Target != targets.end(); ++Target)
         new pkgAcqIndex(Owner, TransactionManager, *Target);
    }
 
@@ -309,33 +301,33 @@ struct GetIndexFilesClass
    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)
+   void operator()(std::string const &/*URI*/, std::string const &/*ShortDesc*/, std::string const &/*LongDesc*/,
+        bool const /*IsOptional*/, std::map<std::string, std::string> Options)
    {
+      std::string const TargetName = Options.find("CREATED_BY")->second;
       if (TargetName == "Packages")
       {
         Indexes->push_back(new debPackagesIndex(
                  URI,
                  Release,
-                 SubstVar("$(COMPONENT)", subst),
+                 Options.find("COMPONENT")->second,
                  IsTrusted,
-                 SubstVar("$(ARCHITECTURE)", subst)
+                 Options.find("ARCHITECTURE")->second
                  ));
       }
       else if (TargetName == "Sources")
         Indexes->push_back(new debSourcesIndex(
                  URI,
                  Release,
-                 SubstVar("$(COMPONENT)", subst),
+                 Options.find("COMPONENT")->second,
                  IsTrusted
                  ));
       else if (TargetName == "Translations")
         Indexes->push_back(new debTranslationsIndex(
                  URI,
                  Release,
-                 SubstVar("$(COMPONENT)", subst),
-                 SubstVar("$(LANGUAGE)", subst)
+                 Options.find("COMPONENT")->second,
+                 Options.find("LANGUAGE")->second
                  ));
    }
 
@@ -404,6 +396,7 @@ class APT_HIDDEN debSLTypeDebian : public pkgSourceList::Type
 
       map<string, string>::const_iterator const trusted = Options.find("trusted");
 
+      debReleaseIndex *Deb = NULL;
       for (vector<metaIndex *>::const_iterator I = List.begin();
           I != List.end(); ++I)
       {
@@ -411,34 +404,23 @@ class APT_HIDDEN debSLTypeDebian : public pkgSourceList::Type
         if (strcmp((*I)->GetType(), "deb") != 0)
            continue;
 
-        debReleaseIndex *Deb = (debReleaseIndex *) (*I);
-        if (trusted != Options.end())
-           Deb->SetTrusted(StringToBool(trusted->second, false));
-
         /* This check insures that there will be only one Release file
            queued for all the Packages files and Sources files it
            corresponds to. */
-        if (Deb->GetURI() == URI && Deb->GetDist() == Dist)
+        if ((*I)->GetURI() == URI && (*I)->GetDist() == Dist)
         {
-           if (IsSrc == true)
-              Deb->PushSectionEntry("source", new debReleaseIndex::debSectionEntry(Section, IsSrc));
-           else
-           {
-              if (Dist[Dist.size() - 1] == '/')
-                 Deb->PushSectionEntry("any", new debReleaseIndex::debSectionEntry(Section, IsSrc));
-              else
-                 Deb->PushSectionEntry(Archs, new debReleaseIndex::debSectionEntry(Section, IsSrc));
-           }
-           return true;
+           Deb = dynamic_cast<debReleaseIndex*>(*I);
+           if (Deb != NULL)
+              break;
         }
       }
 
       // No currently created Release file indexes this entry, so we create a new one.
-      debReleaseIndex *Deb;
-      if (trusted != Options.end())
-        Deb = new debReleaseIndex(URI, Dist, StringToBool(trusted->second, false));
-      else
+      if (Deb == NULL)
+      {
         Deb = new debReleaseIndex(URI, Dist);
+        List.push_back(Deb);
+      }
 
       if (IsSrc == true)
         Deb->PushSectionEntry ("source", new debReleaseIndex::debSectionEntry(Section, IsSrc));
@@ -449,7 +431,10 @@ class APT_HIDDEN debSLTypeDebian : public pkgSourceList::Type
         else
            Deb->PushSectionEntry (Archs, new debReleaseIndex::debSectionEntry(Section, IsSrc));
       }
-      List.push_back(Deb);
+
+      if (trusted != Options.end())
+        Deb->SetTrusted(StringToBool(trusted->second, false));
+
       return true;
    }
 };