edsplistparser.cc 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. /* ######################################################################
  4. Package Cache Generator - Generator for the cache structure.
  5. This builds the cache structure from the abstract package list parser.
  6. ##################################################################### */
  7. /*}}}*/
  8. // Include Files /*{{{*/
  9. #include <config.h>
  10. #include <apt-pkg/configuration.h>
  11. #include <apt-pkg/edsplistparser.h>
  12. #include <apt-pkg/md5.h>
  13. #include <apt-pkg/deblistparser.h>
  14. #include <apt-pkg/pkgcache.h>
  15. #include <apt-pkg/cacheiterators.h>
  16. #include <apt-pkg/tagfile.h>
  17. #include <apt-pkg/fileutl.h>
  18. /*}}}*/
  19. class edspListParserPrivate /*{{{*/
  20. {
  21. public:
  22. FileFd extendedstates;
  23. FileFd preferences;
  24. edspListParserPrivate()
  25. {
  26. std::string const states = _config->FindFile("Dir::State::extended_states");
  27. RemoveFile("edspListParserPrivate", states);
  28. extendedstates.Open(states, FileFd::WriteOnly | FileFd::Create | FileFd::Exclusive, 0600);
  29. std::string const prefs = _config->FindFile("Dir::Etc::preferences");
  30. RemoveFile("edspListParserPrivate", prefs);
  31. preferences.Open(prefs, FileFd::WriteOnly | FileFd::Create | FileFd::Exclusive, 0600);
  32. }
  33. };
  34. /*}}}*/
  35. // ListParser::edspListParser - Constructor /*{{{*/
  36. edspListParser::edspListParser(FileFd *File) : debListParser(File), d(new edspListParserPrivate())
  37. {
  38. }
  39. /*}}}*/
  40. // ListParser::NewVersion - Fill in the version structure /*{{{*/
  41. bool edspListParser::NewVersion(pkgCache::VerIterator &Ver)
  42. {
  43. Ver->ID = Section.FindI("APT-ID", Ver->ID);
  44. return debListParser::NewVersion(Ver);
  45. }
  46. /*}}}*/
  47. // ListParser::Description - Return the description string /*{{{*/
  48. // ---------------------------------------------------------------------
  49. /* Sorry, no description for the resolvers… */
  50. std::vector<std::string> edspListParser::AvailableDescriptionLanguages()
  51. {
  52. return {};
  53. }
  54. MD5SumValue edspListParser::Description_md5()
  55. {
  56. return MD5SumValue("");
  57. }
  58. /*}}}*/
  59. // ListParser::VersionHash - Compute a unique hash for this version /*{{{*/
  60. // ---------------------------------------------------------------------
  61. /* */
  62. unsigned short edspListParser::VersionHash()
  63. {
  64. if (Section.Exists("APT-Hash") == true)
  65. return Section.FindI("APT-Hash");
  66. else if (Section.Exists("APT-ID") == true)
  67. return Section.FindI("APT-ID");
  68. return 0;
  69. }
  70. /*}}}*/
  71. // ListParser::ParseStatus - Parse the status field /*{{{*/
  72. // ---------------------------------------------------------------------
  73. /* The Status: line here is not a normal dpkg one but just one which tells
  74. use if the package is installed or not, where missing means not. */
  75. bool edspListParser::ParseStatus(pkgCache::PkgIterator &Pkg,
  76. pkgCache::VerIterator &Ver)
  77. {
  78. unsigned long state = 0;
  79. if (Section.FindFlag("Hold",state,pkgCache::State::Hold) == false)
  80. return false;
  81. if (state != 0)
  82. Pkg->SelectedState = pkgCache::State::Hold;
  83. state = 0;
  84. if (Section.FindFlag("Installed",state,pkgCache::State::Installed) == false)
  85. return false;
  86. if (state != 0)
  87. {
  88. Pkg->CurrentState = pkgCache::State::Installed;
  89. Pkg->CurrentVer = Ver.Index();
  90. }
  91. if (Section.FindB("APT-Automatic", false))
  92. {
  93. std::string out;
  94. strprintf(out, "Package: %s\nArchitecture: %s\nAuto-Installed: 1\n\n", Pkg.Name(), Pkg.Arch());
  95. if (d->extendedstates.Write(out.c_str(), out.length()) == false)
  96. return false;
  97. }
  98. // FIXME: Using an overriding pin is wrong.
  99. if (Section.FindB("APT-Candidate", false))
  100. {
  101. std::string out;
  102. strprintf(out, "Package: %s\nPin: version %s\nPin-Priority: 9999\n\n", Pkg.FullName().c_str(), Ver.VerStr());
  103. if (d->preferences.Write(out.c_str(), out.length()) == false)
  104. return false;
  105. }
  106. signed short const pinvalue = Section.FindI("APT-Pin", 500);
  107. if (pinvalue != 500)
  108. {
  109. std::string out;
  110. strprintf(out, "Package: %s\nPin: version %s\nPin-Priority: %d\n\n", Pkg.FullName().c_str(), Ver.VerStr(), pinvalue);
  111. if (d->preferences.Write(out.c_str(), out.length()) == false)
  112. return false;
  113. }
  114. return true;
  115. }
  116. /*}}}*/
  117. // ListParser::LoadReleaseInfo - Load the release information /*{{{*/
  118. APT_CONST bool edspListParser::LoadReleaseInfo(pkgCache::RlsFileIterator & /*FileI*/,
  119. FileFd & /*File*/, std::string const &/*component*/)
  120. {
  121. return true;
  122. }
  123. /*}}}*/
  124. edspListParser::~edspListParser() /*{{{*/
  125. {
  126. delete d;
  127. }
  128. /*}}}*/