]> git.saurik.com Git - apt.git/commitdiff
store all targets data in IndexTarget struct
authorDavid Kalnischkies <david@kalnischkies.de>
Wed, 10 Jun 2015 19:24:47 +0000 (21:24 +0200)
committerDavid Kalnischkies <david@kalnischkies.de>
Wed, 10 Jun 2015 19:24:47 +0000 (21:24 +0200)
We still need an API for the targets, so slowly prepare the IndexTargets
to let them take this job.

Git-Dch: Ignore

apt-pkg/acquire-item.cc
apt-pkg/acquire-item.h
apt-pkg/deb/debmetaindex.cc
apt-pkg/init.cc
doc/acquire-additional-files.txt
test/integration/test-apt-acquire-additional-files

index a1357fb15adff323a3b6e40287514e8c750cc952..e92ccc08b68efef8df5c7c8247f61067556aa230 100644 (file)
@@ -382,6 +382,15 @@ bool pkgAcqDiffIndex::TransactionState(TransactionStates const state)
 }
                                                                        /*}}}*/
 
+// IndexTarget - Constructor                                           /*{{{*/
+IndexTarget::IndexTarget(std::string const &MetaKey, std::string const &ShortDesc,
+      std::string const &LongDesc, std::string const &URI, bool const IsOptional,
+      std::map<std::string, std::string> const &Options) :
+   URI(URI), Description(LongDesc), ShortDesc(ShortDesc), MetaKey(MetaKey), IsOptional(IsOptional), Options(Options)
+{
+}
+                                                                       /*}}}*/
+
 class APT_HIDDEN NoActionItem : public pkgAcquire::Item                        /*{{{*/
 /* The sole purpose of this class is having an item which does nothing to
    reach its done state to prevent cleanup deleting the mentioned file.
@@ -955,7 +964,7 @@ void pkgAcqMetaBase::QueueIndexes(bool const verify)                        /*{{{*/
         if (TransactionManager->MetaIndexParser->Exists((*Target)->MetaKey) == false)
         {
            // optional targets that we do not have in the Release file are skipped
-           if ((*Target)->IsOptional())
+           if ((*Target)->IsOptional)
               continue;
 
            Status = StatAuthError;
@@ -2388,7 +2397,7 @@ string pkgAcqIndex::Custom600Headers() const
    if (stat(Final.c_str(),&Buf) == 0)
       msg += "\nLast-Modified: " + TimeRFC1123(Buf.st_mtime);
 
-   if(Target->IsOptional())
+   if(Target->IsOptional)
       msg += "\nFail-Ignore: true";
 
    return msg;
@@ -2410,7 +2419,7 @@ void pkgAcqIndex::Failed(string const &Message,pkgAcquire::MethodConfig const *
       }
    }
 
-   if(Target->IsOptional() && GetExpectedHashes().empty() && Stage == STAGE_DOWNLOAD)
+   if(Target->IsOptional && GetExpectedHashes().empty() && Stage == STAGE_DOWNLOAD)
       Status = StatDone;
    else
       TransactionManager->AbortTransaction();
index 38a7a86621aaed78cdd8b612c935a5f224d19b72..a2571e1cd513c36863e5b34a059c4ed9db530b33 100644 (file)
@@ -28,6 +28,7 @@
 
 #include <string>
 #include <vector>
+#include <map>
 
 #ifndef APT_8_CLEANER_HEADERS
 #include <apt-pkg/indexfile.h>
@@ -49,7 +50,7 @@ class pkgSourceList;
 class IndexTarget;
 class pkgAcqMetaBase;
 
-class APT_HIDDEN IndexTarget                                           /*{{{*/
+class IndexTarget                                                      /*{{{*/
 /** \brief Information about an index file. */
 {
    public:
@@ -63,30 +64,18 @@ class APT_HIDDEN IndexTarget                                                /*{{{*/
    std::string const ShortDesc;
 
    /** \brief The key by which this index file should be
-    *  looked up within the meta signature file.
-    */
+       looked up within the meta index file. */
    std::string const MetaKey;
 
-   virtual bool IsOptional() const {
-      return false;
-   }
+   /** \brief Is it okay if the file isn't found in the meta index */
+   bool const IsOptional;
 
-   IndexTarget(std::string const &MetaKey, std::string const &ShortDesc,
-        std::string const &LongDesc, std::string const &URI) :
-      URI(URI), Description(LongDesc), ShortDesc(ShortDesc), MetaKey(MetaKey) {}
-};
-                                                                       /*}}}*/
-class APT_HIDDEN OptionalIndexTarget : public IndexTarget              /*{{{*/
-/** \brief Information about an optional index file. */
-{
-   public:
-   virtual bool IsOptional() const {
-      return true;
-   }
+   /** \brief Target specific options defined by the implementation */
+   std::map<std::string, std::string> const Options;
 
-   OptionalIndexTarget(std::string const &MetaKey, std::string const &ShortDesc,
-        std::string const &LongDesc, std::string const &URI) :
-      IndexTarget(MetaKey, ShortDesc, LongDesc, URI) {}
+   IndexTarget(std::string const &MetaKey, std::string const &ShortDesc,
+        std::string const &LongDesc, std::string const &URI, bool const IsOptional,
+        std::map<std::string, std::string> const &Options);
 };
                                                                        /*}}}*/
 class pkgAcquire::Item : public WeakPointable                          /*{{{*/
index c35f3b0a4a13c91f40db6b61f43e8a6207c5dab9..f038f12f59bcaefcaaae446f429b9a12535a9547 100644 (file)
@@ -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;
       }
    }
@@ -207,30 +208,23 @@ struct ComputeIndexTargetsClass
 {
    vector <IndexTarget *> * const 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);
       }
+      IndexTarget * Target = new IndexTarget(
+           MetaKey,
+           ShortDesc,
+           LongDesc,
+           Options.find("BASE_URI")->second + MetaKey,
+           IsOptional,
+           Options
+           );
       IndexTargets->push_back(Target);
    }
 
@@ -256,7 +250,7 @@ bool debReleaseIndex::GetIndexes(pkgAcquire *Owner, bool const &GetAll) const
 
    // special case for --print-uris
    vector <IndexTarget *> const * const targets = ComputeIndexTargets();
-#define APT_TARGET(X) IndexTarget("", X, MetaIndexInfo(X), MetaIndexURI(X))
+#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);
@@ -309,33 +303,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
                  ));
    }
 
index 50ea2b49eca444cd6d4c2adebf3c71def0244050..e2239a906c14775d1e3a7fa6fd87d40fc5869917 100644 (file)
@@ -101,19 +101,19 @@ bool pkgInitConfig(Configuration &Cnf)
    // The default user we drop to in the methods
    Cnf.CndSet("APT::Sandbox::User", "_apt");
 
-   Cnf.CndSet("APT::Acquire::Targets::deb::Packages::URI", "$(COMPONENT)/binary-$(ARCHITECTURE)/Packages");
-   Cnf.CndSet("APT::Acquire::Targets::deb::Packages::flatURI", "Packages");
+   Cnf.CndSet("APT::Acquire::Targets::deb::Packages::MetaKey", "$(COMPONENT)/binary-$(ARCHITECTURE)/Packages");
+   Cnf.CndSet("APT::Acquire::Targets::deb::Packages::flatMetaKey", "Packages");
    Cnf.CndSet("APT::Acquire::Targets::deb::Packages::ShortDescription", "Packages");
    Cnf.CndSet("APT::Acquire::Targets::deb::Packages::Description", "$(SITE) $(RELEASE)/$(COMPONENT) $(ARCHITECTURE) Packages");
    Cnf.CndSet("APT::Acquire::Targets::deb::Packages::flatDescription", "$(SITE) $(RELEASE) Packages");
    Cnf.CndSet("APT::Acquire::Targets::deb::Packages::Optional", false);
-   Cnf.CndSet("APT::Acquire::Targets::deb::Translations::URI", "$(COMPONENT)/i18n/Translation-$(LANGUAGE)");
-   Cnf.CndSet("APT::Acquire::Targets::deb::Translations::flatURI", "$(LANGUAGE)");
+   Cnf.CndSet("APT::Acquire::Targets::deb::Translations::MetaKey", "$(COMPONENT)/i18n/Translation-$(LANGUAGE)");
+   Cnf.CndSet("APT::Acquire::Targets::deb::Translations::flatMetaKey", "$(LANGUAGE)");
    Cnf.CndSet("APT::Acquire::Targets::deb::Translations::ShortDescription", "Translation-$(LANGUAGE)");
    Cnf.CndSet("APT::Acquire::Targets::deb::Translations::Description", "$(SITE) $(RELEASE)/$(COMPONENT) Translation-$(LANGUAGE)");
    Cnf.CndSet("APT::Acquire::Targets::deb::Translations::flatDescription", "$(SITE) $(RELEASE) Translation-$(LANGUAGE)");
-   Cnf.CndSet("APT::Acquire::Targets::deb-src::Sources::URI", "$(COMPONENT)/source/Sources");
-   Cnf.CndSet("APT::Acquire::Targets::deb-src::Sources::flatURI", "Sources");
+   Cnf.CndSet("APT::Acquire::Targets::deb-src::Sources::MetaKey", "$(COMPONENT)/source/Sources");
+   Cnf.CndSet("APT::Acquire::Targets::deb-src::Sources::flatMetaKey", "Sources");
    Cnf.CndSet("APT::Acquire::Targets::deb-src::Sources::ShortDescription", "Sources");
    Cnf.CndSet("APT::Acquire::Targets::deb-src::Sources::Description", "$(SITE) $(RELEASE)/$(COMPONENT) Sources");
    Cnf.CndSet("APT::Acquire::Targets::deb-src::Sources::flatDescription", "$(SITE) $(RELEASE) Sources");
index 5a07c2becc06bd5b50fdb4cca3b397a85888cdb7..ab833440b100f0e1ad0076f5d343725483d7635e 100644 (file)
@@ -33,11 +33,11 @@ instructing the Acquire system to download the Packages files would look
 like this (see also apt.conf(5) manpage for configuration file syntax):
 
        APT::Acquire::Targets::deb::Packages {
-               URI "$(COMPONENT)/binary-$(ARCHITECTURE)/Packages";
+               MetaKey "$(COMPONENT)/binary-$(ARCHITECTURE)/Packages";
                ShortDescription "Packages";
                Description "$(SITE) $(RELEASE)/$(COMPONENT) $(ARCHITECTURE) Packages";
 
-               flatURI "Packages";
+               flatMetaKey "Packages";
                flatDescription "$(SITE) $(RELEASE) Packages";
 
                Optional "false";
@@ -47,18 +47,18 @@ All files which should be downloaded (nicknamed 'Targets') are mentioned
 below the APT::Acquire::Targets scope. 'deb' is here the type of the
 sources.list entry the file should be acquired for. The only other
 supported value is hence 'deb-src'. Beware: You can't specify multiple
-types here and you can't download the same URI for multiple types!
+types here and you can't download the same MetaKey form multiple types!
 
 After the type you can pick any valid and unique string which preferable
 refers to the file it downloads (In the example we picked 'Packages').
 This string is never shown or used.
 
 All targets have three main properties you can define:
-* URI: The identifier of the file to be downloaded as used in the
+* MetaKey: The identifier of the file to be downloaded as used in the
   Release file.  It is also the relative location of the file from the
   Release file.  You can neither download from a different server
-  entirely (absolute URI) nor should you try to access directories above
-  the Release file (e.g. "../../").
+  entirely (absolute URI) nor access directories above the Release file
+  (e.g. "../../").
 * ShortDescription: Very short string intended to be displayed to the
   user e.g.  while reporting progress. apt will e.g. use this string in
   the last line to indicate progress of e.g. the download of a specific
@@ -69,7 +69,7 @@ All targets have three main properties you can define:
   progress lines.
 
 Additional optional properties:
-* flat{URI,Description}: APT supports two types of repositories:
+* flat{MetaKey,Description}: APT supports two types of repositories:
   dists-style repositories which are the default and by far the most
   common which are named after the fact that the files are in an
   elaborated directory structure.  In contrast a flat-style repositories
@@ -96,20 +96,20 @@ look like this:
 
 APT::Acquire::Targets {
        deb::Translations {
-               URI "$(COMPONENT)/i18n/Translation-$(LANGUAGE)";
+               MetaKey "$(COMPONENT)/i18n/Translation-$(LANGUAGE)";
                ShortDescription "Translation-$(LANGUAGE)";
                Description "$(SITE) $(RELEASE)/$(COMPONENT) Translation-$(LANGUAGE)";
 
-               flatURI "$(LANGUAGE)";
+               flatMetaKey "$(LANGUAGE)";
                flatDescription "$(SITE) $(RELEASE) Translation-$(LANGUAGE)";
        };
 
        deb-src::Sources {
-               URI "$(COMPONENT)/source/Sources";
+               MetaKey "$(COMPONENT)/source/Sources";
                ShortDescription "Sources";
                Description "$(SITE) $(RELEASE)/$(COMPONENT) Sources";
 
-               flatURI "Sources";
+               flatMetaKey "Sources";
                flatDescription "$(SITE) $(RELEASE) Sources";
 
                Optional "false";
@@ -133,10 +133,7 @@ printed literally.
   have a meaningful value here.
 * $(LANGUAGE): Values are all entries (expect "none") of configuration
   option Acquire::Languages, e.g. "en", "de" or "de_AT".
-
-These values are defined both for 'deb' as well as 'deb-src' targets.
-'deb' targets additional have the variable:
-
 * $(ARCHITECTURE): Values are all entries of configuration option
   APT::Architectures (potentially modified by sources.list options),
-  e.g. "amd64", "i386" or "armel".
+  e.g. "amd64", "i386" or "armel" for the 'deb' type. In type 'deb-src'
+  this variable has the value "source".
index 0e59233e926905f15b55f148e16f1f9756871b9b..4a6845f40e75c9c91d88cb721a2a62feefe0b438 100755 (executable)
@@ -31,7 +31,7 @@ testempty find rootdir/var/lib/apt/lists -name '*Contents*'
 
 cat > rootdir/etc/apt/apt.conf.d/content-target.conf <<EOF
 APT::Acquire::Targets::deb::Contents {
-       URI "\$(COMPONENT)/Contents-\$(ARCHITECTURE)";
+       MetaKey "\$(COMPONENT)/Contents-\$(ARCHITECTURE)";
        ShortDescription "Contents";
        Description "\$(SITE) \$(RELEASE)/\$(COMPONENT) \$(ARCHITECTURE) Contents";
 };
@@ -54,7 +54,7 @@ testsuccess cmp 'rootdir/var/lib/apt/lists/localhost:8080_dists_unstable_main_Co
 # only if we downloaded a compressed file, but target was uncompressed
 cat > rootdir/etc/apt/apt.conf.d/content-target.conf <<EOF
 APT::Acquire::Targets::deb::Contents {
-       URI "\$(COMPONENT)/Contents-\$(ARCHITECTURE).gz";
+       MetaKey "\$(COMPONENT)/Contents-\$(ARCHITECTURE).gz";
        ShortDescription "Contents.gz";
        Description "\$(SITE) \$(RELEASE)/\$(COMPONENT) \$(ARCHITECTURE) Contents.gz";
 };