edsplistparser.cc 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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 <array>
  20. /*}}}*/
  21. // ListParser::edspListParser - Constructor /*{{{*/
  22. edspLikeListParser::edspLikeListParser(FileFd * const File) : debListParser(File)
  23. {
  24. }
  25. edspListParser::edspListParser(FileFd * const File) : edspLikeListParser(File)
  26. {
  27. std::string const states = _config->FindFile("Dir::State::extended_states");
  28. RemoveFile("edspListParserPrivate", states);
  29. extendedstates.Open(states, FileFd::WriteOnly | FileFd::Create | FileFd::Exclusive, 0600);
  30. std::string const prefs = _config->FindFile("Dir::Etc::preferences");
  31. RemoveFile("edspListParserPrivate", prefs);
  32. preferences.Open(prefs, FileFd::WriteOnly | FileFd::Create | FileFd::Exclusive, 0600);
  33. }
  34. /*}}}*/
  35. // ListParser::NewVersion - Fill in the version structure /*{{{*/
  36. bool edspLikeListParser::NewVersion(pkgCache::VerIterator &Ver)
  37. {
  38. _system->SetVersionMapping(Ver->ID, Section.FindI("APT-ID", Ver->ID));
  39. return debListParser::NewVersion(Ver);
  40. }
  41. /*}}}*/
  42. // ListParser::Description - Return the description string /*{{{*/
  43. // ---------------------------------------------------------------------
  44. /* Sorry, no description for the resolvers… */
  45. std::vector<std::string> edspLikeListParser::AvailableDescriptionLanguages()
  46. {
  47. return {};
  48. }
  49. MD5SumValue edspLikeListParser::Description_md5()
  50. {
  51. return MD5SumValue("");
  52. }
  53. /*}}}*/
  54. // ListParser::VersionHash - Compute a unique hash for this version /*{{{*/
  55. unsigned short edspLikeListParser::VersionHash()
  56. {
  57. if (Section.Exists("APT-Hash") == true)
  58. return Section.FindI("APT-Hash");
  59. else if (Section.Exists("APT-ID") == true)
  60. return Section.FindI("APT-ID");
  61. return 0;
  62. }
  63. /*}}}*/
  64. // ListParser::LoadReleaseInfo - Load the release information /*{{{*/
  65. APT_CONST bool edspLikeListParser::LoadReleaseInfo(pkgCache::RlsFileIterator & /*FileI*/,
  66. FileFd & /*File*/, std::string const &/*component*/)
  67. {
  68. return true;
  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 (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 (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 (preferences.Write(out.c_str(), out.length()) == false)
  112. return false;
  113. }
  114. return true;
  115. }
  116. /*}}}*/
  117. // ListParser::eippListParser - Constructor /*{{{*/
  118. eippListParser::eippListParser(FileFd *File) : edspLikeListParser(File)
  119. {
  120. }
  121. /*}}}*/
  122. // ListParser::ParseStatus - Parse the status field /*{{{*/
  123. // ---------------------------------------------------------------------
  124. /* The Status: line here is not a normal dpkg one but just one which tells
  125. use if the package is installed or not, where missing means not. */
  126. bool eippListParser::ParseStatus(pkgCache::PkgIterator &Pkg,
  127. pkgCache::VerIterator &Ver)
  128. {
  129. // Process the flag field
  130. static std::array<WordList, 8> const statusvalues = {{
  131. {"not-installed",pkgCache::State::NotInstalled},
  132. {"config-files",pkgCache::State::ConfigFiles},
  133. {"half-installed",pkgCache::State::HalfInstalled},
  134. {"unpacked",pkgCache::State::UnPacked},
  135. {"half-configured",pkgCache::State::HalfConfigured},
  136. {"triggers-awaited",pkgCache::State::TriggersAwaited},
  137. {"triggers-pending",pkgCache::State::TriggersPending},
  138. {"installed",pkgCache::State::Installed},
  139. }};
  140. auto const status = Section.Find("Status");
  141. if (status.empty() == false)
  142. {
  143. for (auto && sv: statusvalues)
  144. {
  145. if (status != sv.Str)
  146. continue;
  147. Pkg->CurrentState = sv.Val;
  148. switch (Pkg->CurrentState)
  149. {
  150. case pkgCache::State::NotInstalled:
  151. case pkgCache::State::ConfigFiles:
  152. break;
  153. case pkgCache::State::HalfInstalled:
  154. case pkgCache::State::UnPacked:
  155. case pkgCache::State::HalfConfigured:
  156. case pkgCache::State::TriggersAwaited:
  157. case pkgCache::State::TriggersPending:
  158. case pkgCache::State::Installed:
  159. Pkg->CurrentVer = Ver.Index();
  160. break;
  161. }
  162. break;
  163. }
  164. }
  165. return true;
  166. }
  167. /*}}}*/
  168. edspLikeListParser::~edspLikeListParser() {}
  169. edspListParser::~edspListParser() {}
  170. eippListParser::~eippListParser() {}