edsplistparser.cc 6.1 KB

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