]>
git.saurik.com Git - apt-legacy.git/blob - apt-pkg/aptconfiguration.cc
1 // -*- mode: cpp; mode: fold -*-
3 /* ######################################################################
5 Provide access methods to various configuration settings,
6 setup defaults and returns validate settings.
8 ##################################################################### */
10 // Include Files /*{{{*/
11 #include <apt-pkg/fileutl.h>
12 #include <apt-pkg/aptconfiguration.h>
13 #include <apt-pkg/configuration.h>
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) {
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");
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");
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
);
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)
53 // ignore types we have no method ready to use
54 if (_config
->Exists(string("Acquire::CompressionTypes::").append(*o
)) == false)
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)
66 // move again over the option tree to add all missing compression types
67 ::Configuration::Item
const *Types
= _config
->Tree("Acquire::CompressionTypes");
71 for (; Types
!= 0; Types
= Types
->Next
) {
72 if (Types
->Tag
== "Order" || Types
->Tag
.empty() == true)
74 // ignore types we already have in the vector
75 if (std::find(types
.begin(),types
.end(),Types
->Tag
) != types
.end())
77 // ignore types we have no app ready to use
78 string
const appsetting
= string("Dir::Bin::").append(Types
->Value
);
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)
84 types
.push_back(Types
->Tag
);