]> git.saurik.com Git - apt.git/commitdiff
"backport" the APT::Configuration class to apt-sid
authorDavid Kalnischkies <kalnischkies@gmail.com>
Tue, 25 Aug 2009 13:32:40 +0000 (15:32 +0200)
committerDavid Kalnischkies <kalnischkies@gmail.com>
Tue, 25 Aug 2009 13:32:40 +0000 (15:32 +0200)
We can use it to simplify the internal code to operate with
Acquire::CompressionTypes group. This also made it possible
to set this setting with the -o flag.

apt-pkg/acquire-item.cc
apt-pkg/aptconfiguration.cc [new file with mode: 0644]
apt-pkg/aptconfiguration.h [new file with mode: 0644]
apt-pkg/init.cc
apt-pkg/makefile
doc/apt.conf.5.xml
po/apt-all.pot

index ffbe66d7d151118f47621b06b32bbe5d356c9c32..94341c81a93f47ac6e227d4eabbad7b74dadf57d 100644 (file)
@@ -15,6 +15,7 @@
 // Include Files                                                       /*{{{*/
 #include <apt-pkg/acquire-item.h>
 #include <apt-pkg/configuration.h>
 // Include Files                                                       /*{{{*/
 #include <apt-pkg/acquire-item.h>
 #include <apt-pkg/configuration.h>
+#include <apt-pkg/aptconfiguration.h>
 #include <apt-pkg/sourcelist.h>
 #include <apt-pkg/vendorlist.h>
 #include <apt-pkg/error.h>
 #include <apt-pkg/sourcelist.h>
 #include <apt-pkg/vendorlist.h>
 #include <apt-pkg/error.h>
@@ -551,21 +552,11 @@ pkgAcqIndex::pkgAcqIndex(pkgAcquire *Owner,
    if(comprExt.empty()) 
    {
       // autoselect the compression method
    if(comprExt.empty()) 
    {
       // autoselect the compression method
-      Configuration::Item const *Opts = _config->Tree("Acquire::CompressionTypes");
-      if (Opts != 0)
-        Opts = Opts->Child;
-
-      const char dirBin[] = "Dir::Bin::";
-      for (; Opts != 0; Opts = Opts->Next)
-      {
-        if (Opts->Tag.empty() == true || Opts->Value.empty() == true)
-           continue;
-        const string bin = _config->FindFile(string(dirBin).append(Opts->Value).c_str(),"");
-        if (bin != "" && !FileExists(bin))
-           continue;
-        comprExt = '.' + Opts->Tag;
-        break;
-      }
+      std::vector<std::string> types = APT::Configuration::getCompressionTypes();
+      if (types.empty() == true)
+        comprExt = "plain";
+      else
+        comprExt = "." + types[0];
    }
    CompressionExtension = ((comprExt == "plain" || comprExt == ".") ? "" : comprExt);
 
    }
    CompressionExtension = ((comprExt == "plain" || comprExt == ".") ? "" : comprExt);
 
@@ -595,36 +586,31 @@ string pkgAcqIndex::Custom600Headers()
                                                                        /*}}}*/
 void pkgAcqIndex::Failed(string Message,pkgAcquire::MethodConfig *Cnf) /*{{{*/
 {
                                                                        /*}}}*/
 void pkgAcqIndex::Failed(string Message,pkgAcquire::MethodConfig *Cnf) /*{{{*/
 {
-   Configuration::Item const *Opts = _config->Tree("Acquire::CompressionTypes");
-   if (Opts != 0)
-      Opts = Opts->Child;
+   std::vector<std::string> types = APT::Configuration::getCompressionTypes();
 
 
-   const char dirBin[] = "Dir::Bin::";
-   for (; Opts != 0; Opts = Opts->Next)
+   for (std::vector<std::string>::const_iterator t = types.begin();
+       t != types.end(); t++)
    {
    {
-      if (Opts->Tag.empty() == true || Opts->Value.empty() == true)
+      // jump over all already tried compression types
+      const unsigned int nameLen = Desc.URI.size() - (*t).size();
+      if(Desc.URI.substr(nameLen) != *t)
         continue;
 
         continue;
 
-      // jump over all already checked compression types
-      const unsigned int nameLen = Desc.URI.size() - Opts->Tag.size();
-      if(Desc.URI.substr(nameLen) != Opts->Tag || Opts->Next == 0)
-        continue;
-
-      // check if we need an external binary for this compression type
-      const string bin = _config->FindFile(string(dirBin).append(Opts->Next->Value).c_str(),"");
-      if (bin != "" && !FileExists(bin))
-        continue;
+      // we want to try it with the next extension
+      t++;
 
 
-      // retry with the next extension
-      Desc.URI = Desc.URI.substr(0, nameLen) + Opts->Next->Tag;
+      if (t != types.end())
+      {
+        Desc.URI = Desc.URI.substr(0, nameLen) + *t;
 
 
-      new pkgAcqIndex(Owner, RealURI, Desc.Description, Desc.ShortDesc,
-                       ExpectedHash, string(".").append(Opts->Next->Tag));
+        new pkgAcqIndex(Owner, RealURI, Desc.Description, Desc.ShortDesc,
+                        ExpectedHash, string(".").append(*t));
 
 
-      Status = StatDone;
-      Complete = false;
-      Dequeue();
-      return;
+        Status = StatDone;
+        Complete = false;
+        Dequeue();
+        return;
+      }
    }
 
    // on decompression failure, remove bad versions in partial/
    }
 
    // on decompression failure, remove bad versions in partial/
diff --git a/apt-pkg/aptconfiguration.cc b/apt-pkg/aptconfiguration.cc
new file mode 100644 (file)
index 0000000..1a8e826
--- /dev/null
@@ -0,0 +1,78 @@
+// -*- mode: cpp; mode: fold -*-
+// Description                                                         /*{{{*/
+/* ######################################################################
+
+   Provide access methods to various configuration settings,
+   setup defaults and returns validate settings.
+
+   ##################################################################### */
+                                                                       /*}}}*/
+// Include Files                                                       /*{{{*/
+#include <apt-pkg/fileutl.h>
+#include <apt-pkg/aptconfiguration.h>
+#include <apt-pkg/configuration.h>
+
+#include <vector>
+#include <string>
+                                                                       /*}}}*/
+namespace APT {
+// getCompressionTypes - Return Vector of usbale compressiontypes      /*{{{*/
+// ---------------------------------------------------------------------
+/* return a vector of compression types in the prefered order. */
+std::vector<std::string>
+const Configuration::getCompressionTypes(bool const &Cached) {
+       static std::vector<std::string> types;
+       if (types.empty() == false) {
+               if (Cached == true)
+                       return types;
+               else
+                       types.clear();
+       }
+
+       // Set default application paths to check for optional compression types
+       _config->CndSet("Dir::Bin::lzma", "/usr/bin/lzma");
+       _config->CndSet("Dir::Bin::bzip2", "/bin/bzip2");
+
+       ::Configuration::Item const *Opts = _config->Tree("Acquire::CompressionTypes");
+       if (Opts != 0)
+               Opts = Opts->Child;
+
+       // at first, move over the options to setup at least the default options
+       bool foundLzma=false, foundBzip2=false, foundGzip=false;
+       for (; Opts != 0; Opts = Opts->Next) {
+               if (Opts->Value == "lzma")
+                       foundLzma = true;
+               else if (Opts->Value == "bz2")
+                       foundBzip2 = true;
+               else if (Opts->Value == "gz")
+                       foundGzip = true;
+       }
+
+       // setup the defaults now
+       if (!foundBzip2)
+               _config->Set("Acquire::CompressionTypes::bz2","bzip2");
+       if (!foundLzma)
+               _config->Set("Acquire::CompressionTypes::lzma","lzma");
+       if (!foundGzip)
+               _config->Set("Acquire::CompressionTypes::gz","gzip");
+
+       // move again over the option tree to finially calculate our result
+       ::Configuration::Item const *Types = _config->Tree("Acquire::CompressionTypes");
+       if (Types != 0)
+               Types = Types->Child;
+
+       for (; Types != 0; Types = Types->Next) {
+               string const appsetting = string("Dir::Bin::").append(Types->Value);
+               // ignore compression types we have no app ready to use
+               if (appsetting.empty() == false && _config->Exists(appsetting) == true) {
+                       std::string const app = _config->FindFile(appsetting.c_str(), "");
+                       if (app.empty() == false && FileExists(app) == false)
+                               continue;
+               }
+               types.push_back(Types->Tag);
+       }
+
+       return types;
+}
+                                                                       /*}}}*/
+}
diff --git a/apt-pkg/aptconfiguration.h b/apt-pkg/aptconfiguration.h
new file mode 100644 (file)
index 0000000..6a123ad
--- /dev/null
@@ -0,0 +1,46 @@
+// -*- mode: cpp; mode: fold -*-
+// Description                                                         /*{{{*/
+/** \class APT::Configuration
+ *  \brief Provide access methods to various configuration settings
+ *
+ *  This class and their methods providing a layer around the usual access
+ *  methods with _config to ensure that settings are correct and to be able
+ *  to set defaults without the need to recheck it in every method again.
+ */
+                                                                       /*}}}*/
+#ifndef APT_CONFIGURATION_H
+#define APT_CONFIGURATION_H
+// Include Files                                                       /*{{{*/
+#include <string>
+#include <vector>
+                                                                       /*}}}*/
+namespace APT {
+class Configuration {                                                  /*{{{*/
+public:                                                                        /*{{{*/
+       /** \brief Returns a vector of usable Compression Types
+        *
+        *  Files can be compressed in various ways to decrease the size of the
+        *  download. Therefore the Acquiremethods support a few compression types
+        *  and some archives provide also a few different types. This option
+        *  group exists to give the user the choice to prefer one type over the
+        *  other (some compression types are very resource intensive - great if you
+        *  have a limited download, bad if you have a really lowpowered hardware.)
+        *
+        *  This method ensures that the defaults are set and checks at runtime
+        *  if the type can be used. E.g. the current default is to prefer bzip2
+        *  over lzma and gz - if the bzip2 binary is not available it has not much
+        *  sense in downloading the bz2 file, therefore we will not return bz2 as
+        *  a usable compression type. The availability is checked with the settings
+        *  in the Dir::Bin group.
+        *
+        *  \param Cached saves the result so we need to calculated it only once
+        *                this parameter should ony be used for testing purposes.
+        *
+        *  \return a vector of (all) Language Codes in the prefered usage order
+        */
+       std::vector<std::string> static const getCompressionTypes(bool const &Cached = true);
+                                                                       /*}}}*/
+};
+                                                                       /*}}}*/
+}
+#endif
index 46017bf0ce3775c7be3c1525e15041a531cbcea0..15efb1a3d58b708518a6cd78daa5cdeaa43b48a9 100644 (file)
@@ -104,28 +104,6 @@ bool pkgInitConfig(Configuration &Cnf)
    if (Res == false)
       return false;
 
    if (Res == false)
       return false;
 
-   // we load all config files, now check the configs and setup post-defaults:
-   // * check for CompressionTypes setup
-   {
-      Configuration::Item const *Opts = _config->Tree("Acquire::CompressionTypes");
-      if (Opts != 0)
-        Opts = Opts->Child;
-      bool foundLzma=false, foundBzip2=false, foundGzip=false;
-      for (; Opts != 0; Opts = Opts->Next)
-      {
-        if (Opts->Value == "lzma") foundLzma = true;
-        else if (Opts->Value == "bz2") foundBzip2 = true;
-        else if (Opts->Value == "gz") foundGzip = true;
-      }
-      if (!foundBzip2) Cnf.Set("Acquire::CompressionTypes::bz2","bzip2");
-      if (!foundLzma) Cnf.Set("Acquire::CompressionTypes::lzma","lzma");
-      if (!foundGzip) Cnf.Set("Acquire::CompressionTypes::gz","gzip");
-      Cnf.CndSet("Dir::Bin::lzma", "/usr/bin/lzma");
-      Cnf.CndSet("Dir::Bin::bzip2", "/bin/bzip2");
-   }
-
-
-
    if (Cnf.FindB("Debug::pkgInitConfig",false) == true)
       Cnf.Dump();
    
    if (Cnf.FindB("Debug::pkgInitConfig",false) == true)
       Cnf.Dump();
    
index 92ef58967a98f1183384b5b02746710530ee220f..679d97e70e31b2db47853cf630c4970deee0f5cc 100644 (file)
@@ -34,14 +34,15 @@ SOURCE+= pkgcache.cc version.cc depcache.cc \
         acquire-worker.cc acquire-method.cc init.cc clean.cc \
         srcrecords.cc cachefile.cc versionmatch.cc policy.cc \
         pkgsystem.cc indexfile.cc pkgcachegen.cc acquire-item.cc \
         acquire-worker.cc acquire-method.cc init.cc clean.cc \
         srcrecords.cc cachefile.cc versionmatch.cc policy.cc \
         pkgsystem.cc indexfile.cc pkgcachegen.cc acquire-item.cc \
-        indexrecords.cc vendor.cc vendorlist.cc cdrom.cc indexcopy.cc
+        indexrecords.cc vendor.cc vendorlist.cc cdrom.cc indexcopy.cc \
+        aptconfiguration.cc
 HEADERS+= algorithms.h depcache.h pkgcachegen.h cacheiterators.h \
          orderlist.h sourcelist.h packagemanager.h tagfile.h \
          init.h pkgcache.h version.h progress.h pkgrecords.h \
          acquire.h acquire-worker.h acquire-item.h acquire-method.h \
          clean.h srcrecords.h cachefile.h versionmatch.h policy.h \
          pkgsystem.h indexfile.h metaindex.h indexrecords.h vendor.h \
 HEADERS+= algorithms.h depcache.h pkgcachegen.h cacheiterators.h \
          orderlist.h sourcelist.h packagemanager.h tagfile.h \
          init.h pkgcache.h version.h progress.h pkgrecords.h \
          acquire.h acquire-worker.h acquire-item.h acquire-method.h \
          clean.h srcrecords.h cachefile.h versionmatch.h policy.h \
          pkgsystem.h indexfile.h metaindex.h indexrecords.h vendor.h \
-          vendorlist.h cdrom.h indexcopy.h
+          vendorlist.h cdrom.h indexcopy.h aptconfiguration.h
 
 # Source code for the debian specific components
 # In theory the deb headers do not need to be exported..
 
 # Source code for the debian specific components
 # In theory the deb headers do not need to be exported..
index d347bda67260ba663eee13b8ef5c83f4328e0ab8..59235f115550207691a619bbb57314823896d65c 100644 (file)
@@ -309,7 +309,7 @@ DPkg::Pre-Install-Pkgs {"/usr/sbin/dpkg-preconfigure --apt";};
      This list defines in which order the acquire methods will try to download these files.
      Per default <command>bzip2</command> compressed files will be prefered over
      <command>lzma</command>, <command>gzip</command> and uncompressed files. The syntax for
      This list defines in which order the acquire methods will try to download these files.
      Per default <command>bzip2</command> compressed files will be prefered over
      <command>lzma</command>, <command>gzip</command> and uncompressed files. The syntax for
-     the configuration fileentry (this option can't be set at runtime with the -o option) is
+     the configuration fileentry is
      <synopsis>Acquire::CompressionTypes::<replaceable>FileExtension</replaceable> "<replaceable>Methodname</replaceable>";</synopsis>
      e.g. <synopsis>Acquire::CompressionTypes::bz2 "bzip2";</synopsis>
      Note that at runtime the <literal>Dir::Bin::<replaceable>Methodname</replaceable></literal> will
      <synopsis>Acquire::CompressionTypes::<replaceable>FileExtension</replaceable> "<replaceable>Methodname</replaceable>";</synopsis>
      e.g. <synopsis>Acquire::CompressionTypes::bz2 "bzip2";</synopsis>
      Note that at runtime the <literal>Dir::Bin::<replaceable>Methodname</replaceable></literal> will
index b20a3fd927ddec1b8eb5c106a537ac5349a765a6..518a3a1c1e7ac820e0b6131cc7286ae5c7d899ef 100644 (file)
@@ -7,7 +7,7 @@ msgid ""
 msgstr ""
 "Project-Id-Version: PACKAGE VERSION\n"
 "Report-Msgid-Bugs-To: \n"
 msgstr ""
 "Project-Id-Version: PACKAGE VERSION\n"
 "Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2009-08-12 14:46+0200\n"
+"POT-Creation-Date: 2009-08-21 11:35+0200\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
@@ -2364,12 +2364,12 @@ msgstr ""
 msgid "Please insert the disc labeled: '%s' in the drive '%s' and press enter."
 msgstr ""
 
 msgid "Please insert the disc labeled: '%s' in the drive '%s' and press enter."
 msgstr ""
 
-#: apt-pkg/init.cc:154
+#: apt-pkg/init.cc:132
 #, c-format
 msgid "Packaging system '%s' is not supported"
 msgstr ""
 
 #, c-format
 msgid "Packaging system '%s' is not supported"
 msgstr ""
 
-#: apt-pkg/init.cc:170
+#: apt-pkg/init.cc:148
 msgid "Unable to determine a suitable packaging system type"
 msgstr ""
 
 msgid "Unable to determine a suitable packaging system type"
 msgstr ""
 
@@ -2497,44 +2497,44 @@ msgstr ""
 msgid "IO Error saving source cache"
 msgstr ""
 
 msgid "IO Error saving source cache"
 msgstr ""
 
-#: apt-pkg/acquire-item.cc:127
+#: apt-pkg/acquire-item.cc:128
 #, c-format
 msgid "rename failed, %s (%s -> %s)."
 msgstr ""
 
 #, c-format
 msgid "rename failed, %s (%s -> %s)."
 msgstr ""
 
-#: apt-pkg/acquire-item.cc:394
+#: apt-pkg/acquire-item.cc:395
 msgid "MD5Sum mismatch"
 msgstr ""
 
 msgid "MD5Sum mismatch"
 msgstr ""
 
-#: apt-pkg/acquire-item.cc:663 apt-pkg/acquire-item.cc:1425
+#: apt-pkg/acquire-item.cc:649 apt-pkg/acquire-item.cc:1411
 msgid "Hash Sum mismatch"
 msgstr ""
 
 msgid "Hash Sum mismatch"
 msgstr ""
 
-#: apt-pkg/acquire-item.cc:1120
+#: apt-pkg/acquire-item.cc:1106
 msgid "There is no public key available for the following key IDs:\n"
 msgstr ""
 
 msgid "There is no public key available for the following key IDs:\n"
 msgstr ""
 
-#: apt-pkg/acquire-item.cc:1230
+#: apt-pkg/acquire-item.cc:1216
 #, c-format
 msgid ""
 "I wasn't able to locate a file for the %s package. This might mean you need "
 "to manually fix this package. (due to missing arch)"
 msgstr ""
 
 #, c-format
 msgid ""
 "I wasn't able to locate a file for the %s package. This might mean you need "
 "to manually fix this package. (due to missing arch)"
 msgstr ""
 
-#: apt-pkg/acquire-item.cc:1289
+#: apt-pkg/acquire-item.cc:1275
 #, c-format
 msgid ""
 "I wasn't able to locate file for the %s package. This might mean you need to "
 "manually fix this package."
 msgstr ""
 
 #, c-format
 msgid ""
 "I wasn't able to locate file for the %s package. This might mean you need to "
 "manually fix this package."
 msgstr ""
 
-#: apt-pkg/acquire-item.cc:1330
+#: apt-pkg/acquire-item.cc:1316
 #, c-format
 msgid ""
 "The package index files are corrupted. No Filename: field for package %s."
 msgstr ""
 
 #, c-format
 msgid ""
 "The package index files are corrupted. No Filename: field for package %s."
 msgstr ""
 
-#: apt-pkg/acquire-item.cc:1417
+#: apt-pkg/acquire-item.cc:1403
 msgid "Size mismatch"
 msgstr ""
 
 msgid "Size mismatch"
 msgstr ""