]>
git.saurik.com Git - apt.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
);
90 // GetLanguages - Return Vector of Language Codes /*{{{*/
91 // ---------------------------------------------------------------------
92 /* return a vector of language codes in the prefered order.
93 the special word "environment" will be replaced with the long and the short
94 code of the local settings and it will be insured that this will not add
95 duplicates. So in an german local the setting "environment, de_DE, en, de"
96 will result in "de_DE, de, en".
97 The special word "none" is the stopcode for the not-All code vector */
98 std::vector
<std::string
> const Configuration::getLanguages(bool const &All
,
99 bool const &Cached
, char const * const Locale
) {
102 // The detection is boring and has a lot of cornercases,
103 // so we cache the results to calculated it only once.
104 std::vector
<string
> static allCodes
;
105 std::vector
<string
> static codes
;
107 // we have something in the cache
108 if (codes
.empty() == false || allCodes
.empty() == false) {
109 if (Cached
== true) {
110 if(All
== true && allCodes
.empty() == false)
120 // get the environment language code
121 // we extract both, a long and a short code and then we will
122 // check if we actually need both (rare) or if the short is enough
123 string
const envMsg
= string(Locale
== 0 ? std::setlocale(LC_MESSAGES
, NULL
) : Locale
);
124 size_t const lenShort
= (envMsg
.find('_') != string::npos
) ? envMsg
.find('_') : 2;
125 size_t const lenLong
= (envMsg
.find('.') != string::npos
) ? envMsg
.find('.') : (lenShort
+ 3);
127 string envLong
= envMsg
.substr(0,lenLong
);
128 string
const envShort
= envLong
.substr(0,lenShort
);
129 bool envLongIncluded
= true, envShortIncluded
= false;
131 // first cornercase: LANG=C, so we use only "en" Translation
132 if (envLong
== "C") {
133 codes
.push_back("en");
137 if (envLong
!= envShort
) {
138 // to save the servers from unneeded queries, we only try also long codes
139 // for languages it is realistic to have a long code translation file...
140 char const *needLong
[] = { "cs", "en", "pt", "sv", "zh", NULL
};
141 for (char const **l
= needLong
; *l
!= NULL
; l
++)
142 if (envShort
.compare(*l
) == 0) {
143 envLongIncluded
= false;
148 // we don't add the long code, but we allow the user to do so
149 if (envLongIncluded
== true)
152 // FIXME: Remove support for the old APT::Acquire::Translation
153 // it was undocumented and so it should be not very widthly used
154 string
const oldAcquire
= _config
->Find("APT::Acquire::Translation","");
155 if (oldAcquire
.empty() == false && oldAcquire
!= "environment") {
156 if (oldAcquire
!= "none")
157 codes
.push_back(oldAcquire
);
161 // Support settings like Acquire::Translation=none on the command line to
162 // override the configuration settings vector of languages.
163 string
const forceLang
= _config
->Find("Acquire::Languages","");
164 if (forceLang
.empty() == false) {
165 if (forceLang
== "environment") {
166 if (envLongIncluded
== false)
167 codes
.push_back(envLong
);
168 if (envShortIncluded
== false)
169 codes
.push_back(envShort
);
171 } else if (forceLang
!= "none")
172 codes
.push_back(forceLang
);
176 std::vector
<string
> const lang
= _config
->FindVector("Acquire::Languages");
177 // the default setting -> "environment, en"
178 if (lang
.empty() == true) {
179 if (envLongIncluded
== false)
180 codes
.push_back(envLong
);
181 if (envShortIncluded
== false)
182 codes
.push_back(envShort
);
183 if (envShort
!= "en")
184 codes
.push_back("en");
188 // the configs define the order, so add the environment
189 // then needed and ensure the codes are not listed twice.
190 bool noneSeen
= false;
191 for (std::vector
<string
>::const_iterator l
= lang
.begin();
192 l
!= lang
.end(); l
++) {
193 if (*l
== "environment") {
194 if (envLongIncluded
== true && envShortIncluded
== true)
196 if (envLongIncluded
== false) {
197 envLongIncluded
= true;
198 if (noneSeen
== false)
199 codes
.push_back(envLong
);
200 allCodes
.push_back(envLong
);
202 if (envShortIncluded
== false) {
203 envShortIncluded
= true;
204 if (noneSeen
== false)
205 codes
.push_back(envShort
);
206 allCodes
.push_back(envShort
);
209 } else if (*l
== "none") {
212 } else if ((envLongIncluded
== true && *l
== envLong
) ||
213 (envShortIncluded
== true && *l
== envShort
))
216 if (noneSeen
== false)
218 allCodes
.push_back(*l
);