diff options
author | David Kalnischkies <kalnischkies@gmail.com> | 2009-08-25 15:32:40 +0200 |
---|---|---|
committer | David Kalnischkies <kalnischkies@gmail.com> | 2009-08-25 15:32:40 +0200 |
commit | e878aedb8b53b311295a2df55ce5e865b1ad92b9 (patch) | |
tree | 9d80d839b59da7fbeaea2a2be53138698f73b5cb /apt-pkg/aptconfiguration.cc | |
parent | dda7233c5d3879f2580543ead0ad7cd76196a160 (diff) |
"backport" the APT::Configuration class to apt-sid
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.
Diffstat (limited to 'apt-pkg/aptconfiguration.cc')
-rw-r--r-- | apt-pkg/aptconfiguration.cc | 78 |
1 files changed, 78 insertions, 0 deletions
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; +} + /*}}}*/ +} |