aptconfiguration.cc 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. /* ######################################################################
  4. Provide access methods to various configuration settings,
  5. setup defaults and returns validate settings.
  6. ##################################################################### */
  7. /*}}}*/
  8. // Include Files /*{{{*/
  9. #include <apt-pkg/fileutl.h>
  10. #include <apt-pkg/aptconfiguration.h>
  11. #include <apt-pkg/configuration.h>
  12. #include <vector>
  13. #include <string>
  14. /*}}}*/
  15. namespace APT {
  16. // getCompressionTypes - Return Vector of usbale compressiontypes /*{{{*/
  17. // ---------------------------------------------------------------------
  18. /* return a vector of compression types in the prefered order. */
  19. std::vector<std::string>
  20. const Configuration::getCompressionTypes(bool const &Cached) {
  21. static std::vector<std::string> types;
  22. if (types.empty() == false) {
  23. if (Cached == true)
  24. return types;
  25. else
  26. types.clear();
  27. }
  28. // Set default application paths to check for optional compression types
  29. _config->CndSet("Dir::Bin::lzma", "/usr/bin/lzma");
  30. _config->CndSet("Dir::Bin::bzip2", "/bin/bzip2");
  31. ::Configuration::Item const *Opts = _config->Tree("Acquire::CompressionTypes");
  32. if (Opts != 0)
  33. Opts = Opts->Child;
  34. // at first, move over the options to setup at least the default options
  35. bool foundLzma=false, foundBzip2=false, foundGzip=false;
  36. for (; Opts != 0; Opts = Opts->Next) {
  37. if (Opts->Value == "lzma")
  38. foundLzma = true;
  39. else if (Opts->Value == "bz2")
  40. foundBzip2 = true;
  41. else if (Opts->Value == "gz")
  42. foundGzip = true;
  43. }
  44. // setup the defaults now
  45. if (!foundBzip2)
  46. _config->Set("Acquire::CompressionTypes::bz2","bzip2");
  47. if (!foundLzma)
  48. _config->Set("Acquire::CompressionTypes::lzma","lzma");
  49. if (!foundGzip)
  50. _config->Set("Acquire::CompressionTypes::gz","gzip");
  51. // move again over the option tree to finially calculate our result
  52. ::Configuration::Item const *Types = _config->Tree("Acquire::CompressionTypes");
  53. if (Types != 0)
  54. Types = Types->Child;
  55. for (; Types != 0; Types = Types->Next) {
  56. string const appsetting = string("Dir::Bin::").append(Types->Value);
  57. // ignore compression types we have no app ready to use
  58. if (appsetting.empty() == false && _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(Types->Tag);
  64. }
  65. return types;
  66. }
  67. /*}}}*/
  68. }