summaryrefslogtreecommitdiff
path: root/apt-pkg/aptconfiguration.cc
blob: 1a8e8262f70f866d0e397b8c4b5c194d0cb70da3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// -*- mode: cpp; mode: fold -*-
// Description								/*{{{*/
/* ######################################################################

   Provide access methods to various configuration settings,
   setup defaults and returns validate settings.

   ##################################################################### */
									/*}}}*/
// Include Files							/*{{{*/
#include <apt-pkg/fileutl.h>
#include <apt-pkg/aptconfiguration.h>
#include <apt-pkg/configuration.h>

#include <vector>
#include <string>
									/*}}}*/
namespace APT {
// getCompressionTypes - Return Vector of usbale compressiontypes	/*{{{*/
// ---------------------------------------------------------------------
/* return a vector of compression types in the prefered order. */
std::vector<std::string>
const Configuration::getCompressionTypes(bool const &Cached) {
	static std::vector<std::string> types;
	if (types.empty() == false) {
		if (Cached == true)
			return types;
		else
			types.clear();
	}

	// 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;

	// 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;
	}

	// 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
	::Configuration::Item const *Types = _config->Tree("Acquire::CompressionTypes");
	if (Types != 0)
		Types = Types->Child;

	for (; Types != 0; Types = Types->Next) {
		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)
				continue;
		}
		types.push_back(Types->Tag);
	}

	return types;
}
									/*}}}*/
}