summaryrefslogtreecommitdiff
path: root/apt-pkg/aptconfiguration.cc
diff options
context:
space:
mode:
authorDavid Kalnischkies <kalnischkies@gmail.com>2009-09-08 15:02:15 +0200
committerDavid Kalnischkies <kalnischkies@gmail.com>2009-09-08 15:02:15 +0200
commit8bd02d8bd6bc46bc38924635afc09fdde50b6bf5 (patch)
treeb60199c56a24d6e2b1cda3cd837ca92632247c8e /apt-pkg/aptconfiguration.cc
parent6da747804c63f103f431706af80f793b86c41993 (diff)
Rework the CompressionTypes system by adding an Order subgroup to
simplify customisation of the order and improve the documentation about this setting group.
Diffstat (limited to 'apt-pkg/aptconfiguration.cc')
-rw-r--r--apt-pkg/aptconfiguration.cc56
1 files changed, 34 insertions, 22 deletions
diff --git a/apt-pkg/aptconfiguration.cc b/apt-pkg/aptconfiguration.cc
index 1a8e8262f..45ae9bed5 100644
--- a/apt-pkg/aptconfiguration.cc
+++ b/apt-pkg/aptconfiguration.cc
@@ -14,6 +14,7 @@
#include <vector>
#include <string>
+#include <algorithm>
/*}}}*/
namespace APT {
// getCompressionTypes - Return Vector of usbale compressiontypes /*{{{*/
@@ -29,41 +30,52 @@ const Configuration::getCompressionTypes(bool const &Cached) {
types.clear();
}
+ // setup the defaults for the compressiontypes => method mapping
+ _config->CndSet("Acquire::CompressionTypes::bz2","bzip2");
+ _config->CndSet("Acquire::CompressionTypes::lzma","lzma");
+ _config->CndSet("Acquire::CompressionTypes::gz","gzip");
+
// 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;
+ // accept non-list order as override setting for config settings on commandline
+ std::string const overrideOrder = _config->Find("Acquire::CompressionTypes::Order","");
+ if (overrideOrder.empty() == false)
+ types.push_back(overrideOrder);
- // 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;
+ // load the order setting into our vector
+ std::vector<std::string> const order = _config->FindVector("Acquire::CompressionTypes::Order");
+ for (std::vector<std::string>::const_iterator o = order.begin();
+ o != order.end(); o++) {
+ if ((*o).empty() == true)
+ continue;
+ // ignore types we have no method ready to use
+ if (_config->Exists(string("Acquire::CompressionTypes::").append(*o)) == false)
+ continue;
+ // ignore types we have no app ready to use
+ string const appsetting = string("Dir::Bin::").append(*o);
+ if (_config->Exists(appsetting) == true) {
+ std::string const app = _config->FindFile(appsetting.c_str(), "");
+ if (app.empty() == false && FileExists(app) == false)
+ continue;
+ }
+ types.push_back(*o);
}
- // 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
+ // move again over the option tree to add all missing compression types
::Configuration::Item const *Types = _config->Tree("Acquire::CompressionTypes");
if (Types != 0)
Types = Types->Child;
for (; Types != 0; Types = Types->Next) {
+ if (Types->Tag == "Order" || Types->Tag.empty() == true)
+ continue;
+ // ignore types we already have in the vector
+ if (std::find(types.begin(),types.end(),Types->Tag) != types.end())
+ continue;
+ // ignore types we have no app ready to use
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)