edsplistparser.cc 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. #include <apt-pkg/pkgsystem.h>
  19. #include <apt-pkg/string_view.h>
  20. #include <array>
  21. /*}}}*/
  22. // ListParser::edspListParser - Constructor /*{{{*/
  23. edspLikeListParser::edspLikeListParser(FileFd * const File) : debListParser(File)
  24. {
  25. }
  26. edspListParser::edspListParser(FileFd * const File) : edspLikeListParser(File)
  27. {
  28. std::string const states = _config->FindFile("Dir::State::extended_states");
  29. RemoveFile("edspListParserPrivate", states);
  30. extendedstates.Open(states, FileFd::WriteOnly | FileFd::Create | FileFd::Exclusive, 0600);
  31. std::string const prefs = _config->FindFile("Dir::Etc::preferences");
  32. RemoveFile("edspListParserPrivate", prefs);
  33. preferences.Open(prefs, FileFd::WriteOnly | FileFd::Create | FileFd::Exclusive, 0600);
  34. }
  35. /*}}}*/
  36. // ListParser::NewVersion - Fill in the version structure /*{{{*/
  37. bool edspLikeListParser::NewVersion(pkgCache::VerIterator &Ver)
  38. {
  39. _system->SetVersionMapping(Ver->ID, Section.FindI("APT-ID", Ver->ID));
  40. return debListParser::NewVersion(Ver);
  41. }
  42. /*}}}*/
  43. // ListParser::Description - Return the description string /*{{{*/
  44. // ---------------------------------------------------------------------
  45. /* Sorry, no description for the resolvers… */
  46. std::vector<std::string> edspLikeListParser::AvailableDescriptionLanguages()
  47. {
  48. return {};
  49. }
  50. APT::StringView edspLikeListParser::Description_md5()
  51. {
  52. return APT::StringView();
  53. }
  54. /*}}}*/
  55. // ListParser::VersionHash - Compute a unique hash for this version /*{{{*/
  56. unsigned short edspLikeListParser::VersionHash()
  57. {
  58. if (Section.Exists("APT-Hash") == true)
  59. return Section.FindI("APT-Hash");
  60. else if (Section.Exists("APT-ID") == true)
  61. return Section.FindI("APT-ID");
  62. return 0;
  63. }
  64. /*}}}*/
  65. // ListParser::LoadReleaseInfo - Load the release information /*{{{*/
  66. APT_CONST bool edspLikeListParser::LoadReleaseInfo(pkgCache::RlsFileIterator & /*FileI*/,
  67. FileFd & /*File*/, std::string const &/*component*/)
  68. {
  69. return true;
  70. }
  71. /*}}}*/
  72. // ListParser::ParseStatus - Parse the status field /*{{{*/
  73. // ---------------------------------------------------------------------
  74. /* The Status: line here is not a normal dpkg one but just one which tells
  75. use if the package is installed or not, where missing means not. */
  76. bool edspListParser::ParseStatus(pkgCache::PkgIterator &Pkg,
  77. pkgCache::VerIterator &Ver)
  78. {
  79. unsigned long state = 0;
  80. if (Section.FindFlag("Hold",state,pkgCache::State::Hold) == false)
  81. return false;
  82. if (state != 0)
  83. Pkg->SelectedState = pkgCache::State::Hold;
  84. state = 0;
  85. if (Section.FindFlag("Installed",state,pkgCache::State::Installed) == false)
  86. return false;
  87. if (state != 0)
  88. {
  89. Pkg->CurrentState = pkgCache::State::Installed;
  90. Pkg->CurrentVer = Ver.Index();
  91. }
  92. if (Section.FindB("APT-Automatic", false))
  93. {
  94. std::string out;
  95. strprintf(out, "Package: %s\nArchitecture: %s\nAuto-Installed: 1\n\n", Pkg.Name(), Pkg.Arch());
  96. if (extendedstates.Write(out.c_str(), out.length()) == false)
  97. return false;
  98. }
  99. // FIXME: Using an overriding pin is wrong.
  100. if (Section.FindB("APT-Candidate", false))
  101. {
  102. std::string out;
  103. strprintf(out, "Package: %s\nPin: version %s\nPin-Priority: 9999\n\n", Pkg.FullName().c_str(), Ver.VerStr());
  104. if (preferences.Write(out.c_str(), out.length()) == false)
  105. return false;
  106. }
  107. signed short const pinvalue = Section.FindI("APT-Pin", 500);
  108. if (pinvalue != 500)
  109. {
  110. std::string out;
  111. strprintf(out, "Package: %s\nPin: version %s\nPin-Priority: %d\n\n", Pkg.FullName().c_str(), Ver.VerStr(), pinvalue);
  112. if (preferences.Write(out.c_str(), out.length()) == false)
  113. return false;
  114. }
  115. return true;
  116. }
  117. /*}}}*/
  118. // ListParser::eippListParser - Constructor /*{{{*/
  119. eippListParser::eippListParser(FileFd *File) : edspLikeListParser(File)
  120. {
  121. }
  122. /*}}}*/
  123. // ListParser::ParseStatus - Parse the status field /*{{{*/
  124. // ---------------------------------------------------------------------
  125. /* The Status: line here is not a normal dpkg one but just one which tells
  126. use if the package is installed or not, where missing means not. */
  127. bool eippListParser::ParseStatus(pkgCache::PkgIterator &Pkg,
  128. pkgCache::VerIterator &Ver)
  129. {
  130. // Process the flag field
  131. static std::array<WordList, 8> const statusvalues = {{
  132. {"not-installed",pkgCache::State::NotInstalled},
  133. {"config-files",pkgCache::State::ConfigFiles},
  134. {"half-installed",pkgCache::State::HalfInstalled},
  135. {"unpacked",pkgCache::State::UnPacked},
  136. {"half-configured",pkgCache::State::HalfConfigured},
  137. {"triggers-awaited",pkgCache::State::TriggersAwaited},
  138. {"triggers-pending",pkgCache::State::TriggersPending},
  139. {"installed",pkgCache::State::Installed},
  140. }};
  141. auto const status = Section.Find("Status");
  142. if (status.empty() == false)
  143. {
  144. for (auto && sv: statusvalues)
  145. {
  146. if (status != sv.Str)
  147. continue;
  148. Pkg->CurrentState = sv.Val;
  149. switch (Pkg->CurrentState)
  150. {
  151. case pkgCache::State::NotInstalled:
  152. case pkgCache::State::ConfigFiles:
  153. break;
  154. case pkgCache::State::HalfInstalled:
  155. case pkgCache::State::UnPacked:
  156. case pkgCache::State::HalfConfigured:
  157. case pkgCache::State::TriggersAwaited:
  158. case pkgCache::State::TriggersPending:
  159. case pkgCache::State::Installed:
  160. Pkg->CurrentVer = Ver.Index();
  161. break;
  162. }
  163. break;
  164. }
  165. }
  166. return true;
  167. }
  168. /*}}}*/
  169. edspLikeListParser::~edspLikeListParser() {}
  170. edspListParser::~edspListParser() {}
  171. eippListParser::~eippListParser() {}