]>
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 /*{{{*/ | |
ea542140 DK |
11 | #include <config.h> |
12 | ||
e878aedb DK |
13 | #include <apt-pkg/aptconfiguration.h> |
14 | #include <apt-pkg/configuration.h> | |
9f9717fa | 15 | #include <apt-pkg/error.h> |
d7cf5923 DK |
16 | #include <apt-pkg/fileutl.h> |
17 | #include <apt-pkg/macros.h> | |
18 | #include <apt-pkg/strutl.h> | |
e878aedb | 19 | |
3f2d77b5 DK |
20 | #include <sys/types.h> |
21 | #include <dirent.h> | |
8aec002f | 22 | #include <stdio.h> |
b9ed63d3 | 23 | #include <fcntl.h> |
3f2d77b5 | 24 | |
8bd02d8b | 25 | #include <algorithm> |
3f2d77b5 DK |
26 | #include <string> |
27 | #include <vector> | |
e878aedb DK |
28 | /*}}}*/ |
29 | namespace APT { | |
1e3f4083 | 30 | // getCompressionTypes - Return Vector of usable compressiontypes /*{{{*/ |
e878aedb | 31 | // --------------------------------------------------------------------- |
1e3f4083 | 32 | /* return a vector of compression types in the preferred order. */ |
e878aedb DK |
33 | std::vector<std::string> |
34 | const Configuration::getCompressionTypes(bool const &Cached) { | |
35 | static std::vector<std::string> types; | |
36 | if (types.empty() == false) { | |
37 | if (Cached == true) | |
38 | return types; | |
39 | else | |
40 | types.clear(); | |
41 | } | |
42 | ||
8bd02d8b DK |
43 | // setup the defaults for the compressiontypes => method mapping |
44 | _config->CndSet("Acquire::CompressionTypes::bz2","bzip2"); | |
b2430e6d | 45 | _config->CndSet("Acquire::CompressionTypes::xz","xz"); |
8bd02d8b DK |
46 | _config->CndSet("Acquire::CompressionTypes::lzma","lzma"); |
47 | _config->CndSet("Acquire::CompressionTypes::gz","gzip"); | |
48 | ||
03bef784 | 49 | setDefaultConfigurationForCompressors(); |
858fd39f | 50 | std::vector<APT::Configuration::Compressor> const compressors = getCompressors(); |
e878aedb | 51 | |
8bd02d8b DK |
52 | // accept non-list order as override setting for config settings on commandline |
53 | std::string const overrideOrder = _config->Find("Acquire::CompressionTypes::Order",""); | |
54 | if (overrideOrder.empty() == false) | |
55 | types.push_back(overrideOrder); | |
e878aedb | 56 | |
8bd02d8b DK |
57 | // load the order setting into our vector |
58 | std::vector<std::string> const order = _config->FindVector("Acquire::CompressionTypes::Order"); | |
59 | for (std::vector<std::string>::const_iterator o = order.begin(); | |
f7f0d6c7 | 60 | o != order.end(); ++o) { |
8bd02d8b DK |
61 | if ((*o).empty() == true) |
62 | continue; | |
63 | // ignore types we have no method ready to use | |
79b207bc DK |
64 | std::string const method = std::string("Acquire::CompressionTypes::").append(*o); |
65 | if (_config->Exists(method) == false) | |
8bd02d8b DK |
66 | continue; |
67 | // ignore types we have no app ready to use | |
79b207bc | 68 | std::string const app = _config->Find(method); |
858fd39f DK |
69 | std::vector<APT::Configuration::Compressor>::const_iterator c = compressors.begin(); |
70 | for (; c != compressors.end(); ++c) | |
79b207bc | 71 | if (c->Name == app) |
858fd39f DK |
72 | break; |
73 | if (c == compressors.end()) | |
74 | continue; | |
8bd02d8b | 75 | types.push_back(*o); |
e878aedb DK |
76 | } |
77 | ||
8bd02d8b | 78 | // move again over the option tree to add all missing compression types |
e878aedb DK |
79 | ::Configuration::Item const *Types = _config->Tree("Acquire::CompressionTypes"); |
80 | if (Types != 0) | |
81 | Types = Types->Child; | |
82 | ||
83 | for (; Types != 0; Types = Types->Next) { | |
8bd02d8b DK |
84 | if (Types->Tag == "Order" || Types->Tag.empty() == true) |
85 | continue; | |
86 | // ignore types we already have in the vector | |
87 | if (std::find(types.begin(),types.end(),Types->Tag) != types.end()) | |
88 | continue; | |
89 | // ignore types we have no app ready to use | |
858fd39f DK |
90 | std::vector<APT::Configuration::Compressor>::const_iterator c = compressors.begin(); |
91 | for (; c != compressors.end(); ++c) | |
92 | if (c->Name == Types->Value) | |
93 | break; | |
94 | if (c == compressors.end()) | |
95 | continue; | |
e878aedb DK |
96 | types.push_back(Types->Tag); |
97 | } | |
98 | ||
5d885723 DK |
99 | // add the special "uncompressed" type |
100 | if (std::find(types.begin(), types.end(), "uncompressed") == types.end()) | |
101 | { | |
8f3ba4e8 | 102 | std::string const uncompr = _config->FindFile("Dir::Bin::uncompressed", ""); |
5d885723 DK |
103 | if (uncompr.empty() == true || FileExists(uncompr) == true) |
104 | types.push_back("uncompressed"); | |
105 | } | |
106 | ||
e878aedb DK |
107 | return types; |
108 | } | |
109 | /*}}}*/ | |
45df0ad2 DK |
110 | // GetLanguages - Return Vector of Language Codes /*{{{*/ |
111 | // --------------------------------------------------------------------- | |
1e3f4083 | 112 | /* return a vector of language codes in the preferred order. |
45df0ad2 DK |
113 | the special word "environment" will be replaced with the long and the short |
114 | code of the local settings and it will be insured that this will not add | |
115 | duplicates. So in an german local the setting "environment, de_DE, en, de" | |
116 | will result in "de_DE, de, en". | |
117 | The special word "none" is the stopcode for the not-All code vector */ | |
118 | std::vector<std::string> const Configuration::getLanguages(bool const &All, | |
d7cf5923 | 119 | bool const &Cached, char const ** const Locale) { |
45df0ad2 DK |
120 | using std::string; |
121 | ||
122 | // The detection is boring and has a lot of cornercases, | |
123 | // so we cache the results to calculated it only once. | |
124 | std::vector<string> static allCodes; | |
125 | std::vector<string> static codes; | |
126 | ||
127 | // we have something in the cache | |
128 | if (codes.empty() == false || allCodes.empty() == false) { | |
129 | if (Cached == true) { | |
130 | if(All == true && allCodes.empty() == false) | |
131 | return allCodes; | |
132 | else | |
133 | return codes; | |
134 | } else { | |
135 | allCodes.clear(); | |
136 | codes.clear(); | |
137 | } | |
138 | } | |
139 | ||
3f2d77b5 DK |
140 | // Include all Language codes we have a Translation file for in /var/lib/apt/lists |
141 | // so they will be all included in the Cache. | |
142 | std::vector<string> builtin; | |
143 | DIR *D = opendir(_config->FindDir("Dir::State::lists").c_str()); | |
62d8a765 | 144 | if (D != NULL) { |
3f2d77b5 DK |
145 | builtin.push_back("none"); |
146 | for (struct dirent *Ent = readdir(D); Ent != 0; Ent = readdir(D)) { | |
527df5a2 | 147 | string const name = SubstVar(Ent->d_name, "%5f", "_"); |
3f2d77b5 | 148 | size_t const foundDash = name.rfind("-"); |
7cb28948 | 149 | size_t const foundUnderscore = name.rfind("_", foundDash); |
3f2d77b5 DK |
150 | if (foundDash == string::npos || foundUnderscore == string::npos || |
151 | foundDash <= foundUnderscore || | |
152 | name.substr(foundUnderscore+1, foundDash-(foundUnderscore+1)) != "Translation") | |
153 | continue; | |
154 | string const c = name.substr(foundDash+1); | |
155 | if (unlikely(c.empty() == true) || c == "en") | |
156 | continue; | |
157 | // Skip unusual files, like backups or that alike | |
158 | string::const_iterator s = c.begin(); | |
159 | for (;s != c.end(); ++s) { | |
7cb28948 | 160 | if (isalpha(*s) == 0 && *s != '_') |
3f2d77b5 DK |
161 | break; |
162 | } | |
163 | if (s != c.end()) | |
164 | continue; | |
165 | if (std::find(builtin.begin(), builtin.end(), c) != builtin.end()) | |
166 | continue; | |
167 | builtin.push_back(c); | |
168 | } | |
62d8a765 | 169 | closedir(D); |
3f2d77b5 DK |
170 | } |
171 | ||
45df0ad2 DK |
172 | // FIXME: Remove support for the old APT::Acquire::Translation |
173 | // it was undocumented and so it should be not very widthly used | |
174 | string const oldAcquire = _config->Find("APT::Acquire::Translation",""); | |
175 | if (oldAcquire.empty() == false && oldAcquire != "environment") { | |
9f9717fa DK |
176 | // TRANSLATORS: the two %s are APT configuration options |
177 | _error->Notice("Option '%s' is deprecated. Please use '%s' instead, see 'man 5 apt.conf' for details.", | |
178 | "APT::Acquire::Translation", "Acquire::Languages"); | |
45df0ad2 DK |
179 | if (oldAcquire != "none") |
180 | codes.push_back(oldAcquire); | |
3f2d77b5 | 181 | codes.push_back("en"); |
d7cf5923 | 182 | allCodes = codes; |
3f2d77b5 DK |
183 | for (std::vector<string>::const_iterator b = builtin.begin(); |
184 | b != builtin.end(); ++b) | |
185 | if (std::find(allCodes.begin(), allCodes.end(), *b) == allCodes.end()) | |
186 | allCodes.push_back(*b); | |
187 | if (All == true) | |
188 | return allCodes; | |
189 | else | |
190 | return codes; | |
45df0ad2 DK |
191 | } |
192 | ||
ab53c018 DK |
193 | // get the environment language codes: LC_MESSAGES (and later LANGUAGE) |
194 | // we extract both, a long and a short code and then we will | |
195 | // check if we actually need both (rare) or if the short is enough | |
196 | string const envMsg = string(Locale == 0 ? std::setlocale(LC_MESSAGES, NULL) : *Locale); | |
197 | size_t const lenShort = (envMsg.find('_') != string::npos) ? envMsg.find('_') : 2; | |
198 | size_t const lenLong = (envMsg.find_first_of(".@") != string::npos) ? envMsg.find_first_of(".@") : (lenShort + 3); | |
199 | ||
200 | string const envLong = envMsg.substr(0,lenLong); | |
201 | string const envShort = envLong.substr(0,lenShort); | |
202 | ||
203 | // It is very likely we will need the environment codes later, | |
d7cf5923 DK |
204 | // so let us generate them now from LC_MESSAGES and LANGUAGE |
205 | std::vector<string> environment; | |
eb3947c6 DK |
206 | if (envShort != "C") { |
207 | // take care of LC_MESSAGES | |
ab53c018 | 208 | if (envLong != envShort) |
eb3947c6 DK |
209 | environment.push_back(envLong); |
210 | environment.push_back(envShort); | |
211 | // take care of LANGUAGE | |
212 | const char *language_env = getenv("LANGUAGE") == 0 ? "" : getenv("LANGUAGE"); | |
213 | string envLang = Locale == 0 ? language_env : *(Locale+1); | |
214 | if (envLang.empty() == false) { | |
215 | std::vector<string> env = VectorizeString(envLang,':'); | |
216 | short addedLangs = 0; // add a maximum of 3 fallbacks from the environment | |
217 | for (std::vector<string>::const_iterator e = env.begin(); | |
218 | e != env.end() && addedLangs < 3; ++e) { | |
219 | if (unlikely(e->empty() == true) || *e == "en") | |
220 | continue; | |
221 | if (*e == envLong || *e == envShort) | |
222 | continue; | |
223 | if (std::find(environment.begin(), environment.end(), *e) != environment.end()) | |
d7cf5923 | 224 | continue; |
eb3947c6 DK |
225 | ++addedLangs; |
226 | environment.push_back(*e); | |
d7cf5923 | 227 | } |
d7cf5923 | 228 | } |
eb3947c6 DK |
229 | } else { |
230 | environment.push_back("en"); | |
d7cf5923 DK |
231 | } |
232 | ||
da833832 | 233 | // Support settings like Acquire::Languages=none on the command line to |
45df0ad2 DK |
234 | // override the configuration settings vector of languages. |
235 | string const forceLang = _config->Find("Acquire::Languages",""); | |
236 | if (forceLang.empty() == false) { | |
f87fab03 DK |
237 | if (forceLang == "none") { |
238 | codes.clear(); | |
239 | allCodes.clear(); | |
240 | allCodes.push_back("none"); | |
241 | } else { | |
242 | if (forceLang == "environment") | |
243 | codes = environment; | |
244 | else | |
245 | codes.push_back(forceLang); | |
246 | allCodes = codes; | |
247 | for (std::vector<string>::const_iterator b = builtin.begin(); | |
248 | b != builtin.end(); ++b) | |
249 | if (std::find(allCodes.begin(), allCodes.end(), *b) == allCodes.end()) | |
250 | allCodes.push_back(*b); | |
251 | } | |
3f2d77b5 DK |
252 | if (All == true) |
253 | return allCodes; | |
254 | else | |
255 | return codes; | |
45df0ad2 DK |
256 | } |
257 | ||
eb3947c6 DK |
258 | // cornercase: LANG=C, so we use only "en" Translation |
259 | if (envShort == "C") { | |
260 | allCodes = codes = environment; | |
261 | allCodes.insert(allCodes.end(), builtin.begin(), builtin.end()); | |
262 | if (All == true) | |
263 | return allCodes; | |
264 | else | |
265 | return codes; | |
266 | } | |
267 | ||
45df0ad2 DK |
268 | std::vector<string> const lang = _config->FindVector("Acquire::Languages"); |
269 | // the default setting -> "environment, en" | |
270 | if (lang.empty() == true) { | |
d7cf5923 | 271 | codes = environment; |
45df0ad2 DK |
272 | if (envShort != "en") |
273 | codes.push_back("en"); | |
d7cf5923 | 274 | allCodes = codes; |
3f2d77b5 DK |
275 | for (std::vector<string>::const_iterator b = builtin.begin(); |
276 | b != builtin.end(); ++b) | |
277 | if (std::find(allCodes.begin(), allCodes.end(), *b) == allCodes.end()) | |
278 | allCodes.push_back(*b); | |
279 | if (All == true) | |
280 | return allCodes; | |
281 | else | |
282 | return codes; | |
45df0ad2 DK |
283 | } |
284 | ||
285 | // the configs define the order, so add the environment | |
286 | // then needed and ensure the codes are not listed twice. | |
287 | bool noneSeen = false; | |
288 | for (std::vector<string>::const_iterator l = lang.begin(); | |
f7f0d6c7 | 289 | l != lang.end(); ++l) { |
45df0ad2 | 290 | if (*l == "environment") { |
d7cf5923 DK |
291 | for (std::vector<string>::const_iterator e = environment.begin(); |
292 | e != environment.end(); ++e) { | |
293 | if (std::find(allCodes.begin(), allCodes.end(), *e) != allCodes.end()) | |
294 | continue; | |
45df0ad2 | 295 | if (noneSeen == false) |
d7cf5923 DK |
296 | codes.push_back(*e); |
297 | allCodes.push_back(*e); | |
45df0ad2 DK |
298 | } |
299 | continue; | |
300 | } else if (*l == "none") { | |
301 | noneSeen = true; | |
302 | continue; | |
d7cf5923 | 303 | } else if (std::find(allCodes.begin(), allCodes.end(), *l) != allCodes.end()) |
45df0ad2 DK |
304 | continue; |
305 | ||
306 | if (noneSeen == false) | |
307 | codes.push_back(*l); | |
308 | allCodes.push_back(*l); | |
309 | } | |
3f2d77b5 DK |
310 | |
311 | for (std::vector<string>::const_iterator b = builtin.begin(); | |
312 | b != builtin.end(); ++b) | |
313 | if (std::find(allCodes.begin(), allCodes.end(), *b) == allCodes.end()) | |
314 | allCodes.push_back(*b); | |
315 | ||
45df0ad2 DK |
316 | if (All == true) |
317 | return allCodes; | |
318 | else | |
319 | return codes; | |
320 | } | |
321 | /*}}}*/ | |
c45233ea DK |
322 | // checkLanguage - are we interested in the given Language? /*{{{*/ |
323 | bool const Configuration::checkLanguage(std::string Lang, bool const All) { | |
324 | // the empty Language is always interesting as it is the original | |
325 | if (Lang.empty() == true) | |
326 | return true; | |
327 | // filenames are encoded, so undo this | |
328 | Lang = SubstVar(Lang, "%5f", "_"); | |
329 | std::vector<std::string> const langs = getLanguages(All, true); | |
330 | return (std::find(langs.begin(), langs.end(), Lang) != langs.end()); | |
331 | } | |
332 | /*}}}*/ | |
1e3f4083 | 333 | // getArchitectures - Return Vector of preferred Architectures /*{{{*/ |
5dd4c8b8 DK |
334 | std::vector<std::string> const Configuration::getArchitectures(bool const &Cached) { |
335 | using std::string; | |
336 | ||
337 | std::vector<string> static archs; | |
338 | if (likely(Cached == true) && archs.empty() == false) | |
339 | return archs; | |
340 | ||
3152f4aa | 341 | string const arch = _config->Find("APT::Architecture"); |
8aec002f DK |
342 | archs = _config->FindVector("APT::Architectures"); |
343 | ||
3152f4aa DK |
344 | if (unlikely(arch.empty() == true)) |
345 | return archs; | |
346 | ||
8aec002f DK |
347 | // FIXME: It is a bit unclean to have debian specific code hereā¦ |
348 | if (archs.empty() == true) { | |
349 | archs.push_back(arch); | |
b9ed63d3 DK |
350 | |
351 | // Generate the base argument list for dpkg | |
352 | std::vector<const char *> Args; | |
353 | string Tmp = _config->Find("Dir::Bin::dpkg","dpkg"); | |
354 | { | |
355 | string const dpkgChrootDir = _config->FindDir("DPkg::Chroot-Directory", "/"); | |
356 | size_t dpkgChrootLen = dpkgChrootDir.length(); | |
357 | if (dpkgChrootDir != "/" && Tmp.find(dpkgChrootDir) == 0) { | |
358 | if (dpkgChrootDir[dpkgChrootLen - 1] == '/') | |
359 | --dpkgChrootLen; | |
360 | Tmp = Tmp.substr(dpkgChrootLen); | |
361 | } | |
362 | } | |
363 | Args.push_back(Tmp.c_str()); | |
364 | ||
365 | // Stick in any custom dpkg options | |
366 | ::Configuration::Item const *Opts = _config->Tree("DPkg::Options"); | |
367 | if (Opts != 0) { | |
368 | Opts = Opts->Child; | |
369 | for (; Opts != 0; Opts = Opts->Next) | |
370 | { | |
371 | if (Opts->Value.empty() == true) | |
372 | continue; | |
373 | Args.push_back(Opts->Value.c_str()); | |
374 | } | |
375 | } | |
376 | ||
377 | Args.push_back("--print-foreign-architectures"); | |
378 | Args.push_back(NULL); | |
379 | ||
380 | int external[2] = {-1, -1}; | |
381 | if (pipe(external) != 0) | |
382 | { | |
383 | _error->WarningE("getArchitecture", "Can't create IPC pipe for dpkg --print-foreign-architectures"); | |
384 | return archs; | |
385 | } | |
386 | ||
387 | pid_t dpkgMultiArch = ExecFork(); | |
388 | if (dpkgMultiArch == 0) { | |
389 | close(external[0]); | |
390 | std::string const chrootDir = _config->FindDir("DPkg::Chroot-Directory"); | |
b9ed63d3 DK |
391 | int const nullfd = open("/dev/null", O_RDONLY); |
392 | dup2(nullfd, STDIN_FILENO); | |
393 | dup2(external[1], STDOUT_FILENO); | |
394 | dup2(nullfd, STDERR_FILENO); | |
2510eea4 | 395 | if (chrootDir != "/" && chroot(chrootDir.c_str()) != 0 && chdir("/") != 0) |
36a0c0f7 | 396 | _error->WarningE("getArchitecture", "Couldn't chroot into %s for dpkg --print-foreign-architectures", chrootDir.c_str()); |
17019a09 | 397 | execvp(Args[0], (char**) &Args[0]); |
b9ed63d3 DK |
398 | _error->WarningE("getArchitecture", "Can't detect foreign architectures supported by dpkg!"); |
399 | _exit(100); | |
400 | } | |
401 | close(external[1]); | |
402 | ||
403 | FILE *dpkg = fdopen(external[0], "r"); | |
8aec002f | 404 | if(dpkg != NULL) { |
69c2ecbd | 405 | char buf[1024]; |
4df62de6 | 406 | while (fgets(buf, sizeof(buf), dpkg) != NULL) { |
8aec002f DK |
407 | char* arch = strtok(buf, " "); |
408 | while (arch != NULL) { | |
409 | for (; isspace(*arch) != 0; ++arch); | |
bdb3d92c | 410 | if (arch[0] != '\0') { |
8aec002f DK |
411 | char const* archend = arch; |
412 | for (; isspace(*archend) == 0 && *archend != '\0'; ++archend); | |
dd7233af DK |
413 | string a(arch, (archend - arch)); |
414 | if (std::find(archs.begin(), archs.end(), a) == archs.end()) | |
415 | archs.push_back(a); | |
8aec002f DK |
416 | } |
417 | arch = strtok(NULL, " "); | |
418 | } | |
419 | } | |
b9ed63d3 | 420 | fclose(dpkg); |
8aec002f | 421 | } |
b9ed63d3 | 422 | ExecWait(dpkgMultiArch, "dpkg --print-foreign-architectures", true); |
8aec002f DK |
423 | return archs; |
424 | } | |
425 | ||
5dd4c8b8 DK |
426 | if (archs.empty() == true || |
427 | std::find(archs.begin(), archs.end(), arch) == archs.end()) | |
bd9d81e3 | 428 | archs.insert(archs.begin(), arch); |
3152f4aa DK |
429 | |
430 | // erase duplicates and empty strings | |
431 | for (std::vector<string>::reverse_iterator a = archs.rbegin(); | |
432 | a != archs.rend(); ++a) { | |
433 | if (a->empty() == true || std::find(a + 1, archs.rend(), *a) != archs.rend()) | |
434 | archs.erase(a.base()-1); | |
435 | if (a == archs.rend()) | |
436 | break; | |
437 | } | |
438 | ||
5dd4c8b8 DK |
439 | return archs; |
440 | } | |
441 | /*}}}*/ | |
442 | // checkArchitecture - are we interested in the given Architecture? /*{{{*/ | |
443 | bool const Configuration::checkArchitecture(std::string const &Arch) { | |
444 | if (Arch == "all") | |
445 | return true; | |
446 | std::vector<std::string> const archs = getArchitectures(true); | |
447 | return (std::find(archs.begin(), archs.end(), Arch) != archs.end()); | |
448 | } | |
449 | /*}}}*/ | |
03bef784 DK |
450 | // setDefaultConfigurationForCompressors /*{{{*/ |
451 | void Configuration::setDefaultConfigurationForCompressors() { | |
452 | // Set default application paths to check for optional compression types | |
03bef784 | 453 | _config->CndSet("Dir::Bin::bzip2", "/bin/bzip2"); |
2024154c DK |
454 | _config->CndSet("Dir::Bin::xz", "/usr/bin/xz"); |
455 | if (FileExists(_config->FindFile("Dir::Bin::xz")) == true) { | |
342df712 | 456 | _config->Set("Dir::Bin::lzma", _config->FindFile("Dir::Bin::xz")); |
2024154c DK |
457 | _config->Set("APT::Compressor::lzma::Binary", "xz"); |
458 | if (_config->Exists("APT::Compressor::lzma::CompressArg") == false) { | |
459 | _config->Set("APT::Compressor::lzma::CompressArg::", "--format=lzma"); | |
460 | _config->Set("APT::Compressor::lzma::CompressArg::", "-9"); | |
461 | } | |
462 | if (_config->Exists("APT::Compressor::lzma::UncompressArg") == false) { | |
463 | _config->Set("APT::Compressor::lzma::UncompressArg::", "--format=lzma"); | |
464 | _config->Set("APT::Compressor::lzma::UncompressArg::", "-d"); | |
465 | } | |
466 | } else { | |
467 | _config->CndSet("Dir::Bin::lzma", "/usr/bin/lzma"); | |
468 | if (_config->Exists("APT::Compressor::lzma::CompressArg") == false) { | |
469 | _config->Set("APT::Compressor::lzma::CompressArg::", "--suffix="); | |
470 | _config->Set("APT::Compressor::lzma::CompressArg::", "-9"); | |
471 | } | |
472 | if (_config->Exists("APT::Compressor::lzma::UncompressArg") == false) { | |
473 | _config->Set("APT::Compressor::lzma::UncompressArg::", "--suffix="); | |
474 | _config->Set("APT::Compressor::lzma::UncompressArg::", "-d"); | |
475 | } | |
476 | } | |
03bef784 DK |
477 | } |
478 | /*}}}*/ | |
479 | // getCompressors - Return Vector of usbale compressors /*{{{*/ | |
480 | // --------------------------------------------------------------------- | |
481 | /* return a vector of compressors used by apt-ftparchive in the | |
482 | multicompress functionality or to detect data.tar files */ | |
483 | std::vector<APT::Configuration::Compressor> | |
484 | const Configuration::getCompressors(bool const Cached) { | |
485 | static std::vector<APT::Configuration::Compressor> compressors; | |
486 | if (compressors.empty() == false) { | |
487 | if (Cached == true) | |
488 | return compressors; | |
489 | else | |
490 | compressors.clear(); | |
491 | } | |
492 | ||
493 | setDefaultConfigurationForCompressors(); | |
494 | ||
e29d7e3e | 495 | compressors.push_back(Compressor(".", "", "", NULL, NULL, 1)); |
03bef784 DK |
496 | if (_config->Exists("Dir::Bin::gzip") == false || FileExists(_config->FindFile("Dir::Bin::gzip")) == true) |
497 | compressors.push_back(Compressor("gzip",".gz","gzip","-9n","-d",2)); | |
8dd623db DK |
498 | #ifdef HAVE_ZLIB |
499 | else | |
e29d7e3e | 500 | compressors.push_back(Compressor("gzip",".gz","false", NULL, NULL, 2)); |
8dd623db | 501 | #endif |
03bef784 DK |
502 | if (_config->Exists("Dir::Bin::bzip2") == false || FileExists(_config->FindFile("Dir::Bin::bzip2")) == true) |
503 | compressors.push_back(Compressor("bzip2",".bz2","bzip2","-9","-d",3)); | |
c4997486 DK |
504 | #ifdef HAVE_BZ2 |
505 | else | |
e29d7e3e | 506 | compressors.push_back(Compressor("bzip2",".bz2","false", NULL, NULL, 3)); |
c4997486 | 507 | #endif |
03bef784 | 508 | if (_config->Exists("Dir::Bin::xz") == false || FileExists(_config->FindFile("Dir::Bin::xz")) == true) |
2024154c DK |
509 | compressors.push_back(Compressor("xz",".xz","xz","-6","-d",4)); |
510 | if (_config->Exists("Dir::Bin::lzma") == false || FileExists(_config->FindFile("Dir::Bin::lzma")) == true) | |
511 | compressors.push_back(Compressor("lzma",".lzma","lzma","-9","-d",5)); | |
03bef784 DK |
512 | |
513 | std::vector<std::string> const comp = _config->FindVector("APT::Compressor"); | |
514 | for (std::vector<std::string>::const_iterator c = comp.begin(); | |
515 | c != comp.end(); ++c) { | |
516 | if (*c == "." || *c == "gzip" || *c == "bzip2" || *c == "lzma" || *c == "xz") | |
517 | continue; | |
518 | compressors.push_back(Compressor(c->c_str(), std::string(".").append(*c).c_str(), c->c_str(), "-9", "-d", 100)); | |
519 | } | |
520 | ||
521 | return compressors; | |
522 | } | |
523 | /*}}}*/ | |
b0e1a43f DK |
524 | // getCompressorExtensions - supported data.tar extensions /*{{{*/ |
525 | // --------------------------------------------------------------------- | |
526 | /* */ | |
527 | std::vector<std::string> const Configuration::getCompressorExtensions() { | |
528 | std::vector<APT::Configuration::Compressor> const compressors = getCompressors(); | |
529 | std::vector<std::string> ext; | |
530 | for (std::vector<APT::Configuration::Compressor>::const_iterator c = compressors.begin(); | |
531 | c != compressors.end(); ++c) | |
532 | if (c->Extension.empty() == false && c->Extension != ".") | |
533 | ext.push_back(c->Extension); | |
534 | return ext; | |
535 | } | |
536 | /*}}}*/ | |
03bef784 DK |
537 | // Compressor constructor /*{{{*/ |
538 | // --------------------------------------------------------------------- | |
539 | /* */ | |
540 | Configuration::Compressor::Compressor(char const *name, char const *extension, | |
541 | char const *binary, | |
542 | char const *compressArg, char const *uncompressArg, | |
543 | unsigned short const cost) { | |
2024154c | 544 | std::string const config = std::string("APT::Compressor::").append(name).append("::"); |
03bef784 DK |
545 | Name = _config->Find(std::string(config).append("Name"), name); |
546 | Extension = _config->Find(std::string(config).append("Extension"), extension); | |
547 | Binary = _config->Find(std::string(config).append("Binary"), binary); | |
548 | Cost = _config->FindI(std::string(config).append("Cost"), cost); | |
549 | std::string const compConf = std::string(config).append("CompressArg"); | |
550 | if (_config->Exists(compConf) == true) | |
551 | CompressArgs = _config->FindVector(compConf); | |
552 | else if (compressArg != NULL) | |
553 | CompressArgs.push_back(compressArg); | |
554 | std::string const uncompConf = std::string(config).append("UncompressArg"); | |
555 | if (_config->Exists(uncompConf) == true) | |
556 | UncompressArgs = _config->FindVector(uncompConf); | |
557 | else if (uncompressArg != NULL) | |
558 | UncompressArgs.push_back(uncompressArg); | |
559 | } | |
560 | /*}}}*/ | |
e878aedb | 561 | } |