diff options
Diffstat (limited to 'apt-pkg')
-rw-r--r-- | apt-pkg/acquire-item.cc | 62 | ||||
-rw-r--r-- | apt-pkg/aptconfiguration.cc | 78 | ||||
-rw-r--r-- | apt-pkg/aptconfiguration.h | 46 | ||||
-rw-r--r-- | apt-pkg/init.cc | 22 | ||||
-rw-r--r-- | apt-pkg/makefile | 5 |
5 files changed, 151 insertions, 62 deletions
diff --git a/apt-pkg/acquire-item.cc b/apt-pkg/acquire-item.cc index ffbe66d7d..94341c81a 100644 --- a/apt-pkg/acquire-item.cc +++ b/apt-pkg/acquire-item.cc @@ -15,6 +15,7 @@ // 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> @@ -551,21 +552,11 @@ pkgAcqIndex::pkgAcqIndex(pkgAcquire *Owner, 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); @@ -595,36 +586,31 @@ string pkgAcqIndex::Custom600Headers() /*}}}*/ 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; - // 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/ diff --git a/apt-pkg/aptconfiguration.cc b/apt-pkg/aptconfiguration.cc new file mode 100644 index 000000000..1a8e8262f --- /dev/null +++ b/apt-pkg/aptconfiguration.cc @@ -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 index 000000000..6a123adce --- /dev/null +++ b/apt-pkg/aptconfiguration.h @@ -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 diff --git a/apt-pkg/init.cc b/apt-pkg/init.cc index 46017bf0c..15efb1a3d 100644 --- a/apt-pkg/init.cc +++ b/apt-pkg/init.cc @@ -104,28 +104,6 @@ bool pkgInitConfig(Configuration &Cnf) 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(); diff --git a/apt-pkg/makefile b/apt-pkg/makefile index 92ef58967..679d97e70 100644 --- a/apt-pkg/makefile +++ b/apt-pkg/makefile @@ -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 \ - 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 \ - 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.. |