]>
Commit | Line | Data |
---|---|---|
e878aedb DK |
1 | // -*- mode: cpp; mode: fold -*- |
2 | // Description /*{{{*/ | |
3 | /* ###################################################################### | |
4 | ||
5 | Provide access methods to various configuration settings, | |
6 | setup defaults and returns validate settings. | |
7 | ||
8 | ##################################################################### */ | |
9 | /*}}}*/ | |
10 | // Include Files /*{{{*/ | |
11 | #include <apt-pkg/fileutl.h> | |
12 | #include <apt-pkg/aptconfiguration.h> | |
13 | #include <apt-pkg/configuration.h> | |
14 | ||
15 | #include <vector> | |
16 | #include <string> | |
8bd02d8b | 17 | #include <algorithm> |
e878aedb DK |
18 | /*}}}*/ |
19 | namespace APT { | |
20 | // getCompressionTypes - Return Vector of usbale compressiontypes /*{{{*/ | |
21 | // --------------------------------------------------------------------- | |
22 | /* return a vector of compression types in the prefered order. */ | |
23 | std::vector<std::string> | |
24 | const Configuration::getCompressionTypes(bool const &Cached) { | |
25 | static std::vector<std::string> types; | |
26 | if (types.empty() == false) { | |
27 | if (Cached == true) | |
28 | return types; | |
29 | else | |
30 | types.clear(); | |
31 | } | |
32 | ||
8bd02d8b DK |
33 | // setup the defaults for the compressiontypes => method mapping |
34 | _config->CndSet("Acquire::CompressionTypes::bz2","bzip2"); | |
35 | _config->CndSet("Acquire::CompressionTypes::lzma","lzma"); | |
36 | _config->CndSet("Acquire::CompressionTypes::gz","gzip"); | |
37 | ||
e878aedb DK |
38 | // Set default application paths to check for optional compression types |
39 | _config->CndSet("Dir::Bin::lzma", "/usr/bin/lzma"); | |
40 | _config->CndSet("Dir::Bin::bzip2", "/bin/bzip2"); | |
41 | ||
8bd02d8b DK |
42 | // accept non-list order as override setting for config settings on commandline |
43 | std::string const overrideOrder = _config->Find("Acquire::CompressionTypes::Order",""); | |
44 | if (overrideOrder.empty() == false) | |
45 | types.push_back(overrideOrder); | |
e878aedb | 46 | |
8bd02d8b DK |
47 | // load the order setting into our vector |
48 | std::vector<std::string> const order = _config->FindVector("Acquire::CompressionTypes::Order"); | |
49 | for (std::vector<std::string>::const_iterator o = order.begin(); | |
50 | o != order.end(); o++) { | |
51 | if ((*o).empty() == true) | |
52 | continue; | |
53 | // ignore types we have no method ready to use | |
54 | if (_config->Exists(string("Acquire::CompressionTypes::").append(*o)) == false) | |
55 | continue; | |
56 | // ignore types we have no app ready to use | |
57 | string const appsetting = string("Dir::Bin::").append(*o); | |
58 | if (_config->Exists(appsetting) == true) { | |
59 | std::string const app = _config->FindFile(appsetting.c_str(), ""); | |
60 | if (app.empty() == false && FileExists(app) == false) | |
61 | continue; | |
62 | } | |
63 | types.push_back(*o); | |
e878aedb DK |
64 | } |
65 | ||
8bd02d8b | 66 | // move again over the option tree to add all missing compression types |
e878aedb DK |
67 | ::Configuration::Item const *Types = _config->Tree("Acquire::CompressionTypes"); |
68 | if (Types != 0) | |
69 | Types = Types->Child; | |
70 | ||
71 | for (; Types != 0; Types = Types->Next) { | |
8bd02d8b DK |
72 | if (Types->Tag == "Order" || Types->Tag.empty() == true) |
73 | continue; | |
74 | // ignore types we already have in the vector | |
75 | if (std::find(types.begin(),types.end(),Types->Tag) != types.end()) | |
76 | continue; | |
77 | // ignore types we have no app ready to use | |
e878aedb | 78 | string const appsetting = string("Dir::Bin::").append(Types->Value); |
e878aedb DK |
79 | if (appsetting.empty() == false && _config->Exists(appsetting) == true) { |
80 | std::string const app = _config->FindFile(appsetting.c_str(), ""); | |
81 | if (app.empty() == false && FileExists(app) == false) | |
82 | continue; | |
83 | } | |
84 | types.push_back(Types->Tag); | |
85 | } | |
86 | ||
87 | return types; | |
88 | } | |
89 | /*}}}*/ | |
90 | } |