aptconfiguration.cc 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. #include <algorithm>
  15. /*}}}*/
  16. namespace APT {
  17. // getCompressionTypes - Return Vector of usbale compressiontypes /*{{{*/
  18. // ---------------------------------------------------------------------
  19. /* return a vector of compression types in the prefered order. */
  20. std::vector<std::string>
  21. const Configuration::getCompressionTypes(bool const &Cached) {
  22. static std::vector<std::string> types;
  23. if (types.empty() == false) {
  24. if (Cached == true)
  25. return types;
  26. else
  27. types.clear();
  28. }
  29. // setup the defaults for the compressiontypes => method mapping
  30. _config->CndSet("Acquire::CompressionTypes::bz2","bzip2");
  31. _config->CndSet("Acquire::CompressionTypes::lzma","lzma");
  32. _config->CndSet("Acquire::CompressionTypes::gz","gzip");
  33. // Set default application paths to check for optional compression types
  34. _config->CndSet("Dir::Bin::lzma", "/usr/bin/lzma");
  35. _config->CndSet("Dir::Bin::bzip2", "/bin/bzip2");
  36. // accept non-list order as override setting for config settings on commandline
  37. std::string const overrideOrder = _config->Find("Acquire::CompressionTypes::Order","");
  38. if (overrideOrder.empty() == false)
  39. types.push_back(overrideOrder);
  40. // load the order setting into our vector
  41. std::vector<std::string> const order = _config->FindVector("Acquire::CompressionTypes::Order");
  42. for (std::vector<std::string>::const_iterator o = order.begin();
  43. o != order.end(); o++) {
  44. if ((*o).empty() == true)
  45. continue;
  46. // ignore types we have no method ready to use
  47. if (_config->Exists(string("Acquire::CompressionTypes::").append(*o)) == false)
  48. continue;
  49. // ignore types we have no app ready to use
  50. string const appsetting = string("Dir::Bin::").append(*o);
  51. if (_config->Exists(appsetting) == true) {
  52. std::string const app = _config->FindFile(appsetting.c_str(), "");
  53. if (app.empty() == false && FileExists(app) == false)
  54. continue;
  55. }
  56. types.push_back(*o);
  57. }
  58. // move again over the option tree to add all missing compression types
  59. ::Configuration::Item const *Types = _config->Tree("Acquire::CompressionTypes");
  60. if (Types != 0)
  61. Types = Types->Child;
  62. for (; Types != 0; Types = Types->Next) {
  63. if (Types->Tag == "Order" || Types->Tag.empty() == true)
  64. continue;
  65. // ignore types we already have in the vector
  66. if (std::find(types.begin(),types.end(),Types->Tag) != types.end())
  67. continue;
  68. // ignore types we have no app ready to use
  69. string const appsetting = string("Dir::Bin::").append(Types->Value);
  70. if (appsetting.empty() == false && _config->Exists(appsetting) == true) {
  71. std::string const app = _config->FindFile(appsetting.c_str(), "");
  72. if (app.empty() == false && FileExists(app) == false)
  73. continue;
  74. }
  75. types.push_back(Types->Tag);
  76. }
  77. return types;
  78. }
  79. /*}}}*/
  80. }