edsplistparser.cc 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. class edspListParserPrivate /*{{{*/
  21. {
  22. public:
  23. FileFd extendedstates;
  24. FileFd preferences;
  25. edspListParserPrivate()
  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. /*}}}*/
  36. // ListParser::edspListParser - Constructor /*{{{*/
  37. edspListParser::edspListParser(FileFd *File) : debListParser(File), d(new edspListParserPrivate())
  38. {
  39. }
  40. /*}}}*/
  41. // ListParser::NewVersion - Fill in the version structure /*{{{*/
  42. bool edspListParser::NewVersion(pkgCache::VerIterator &Ver)
  43. {
  44. _system->SetVersionMapping(Ver->ID, Section.FindI("APT-ID", Ver->ID));
  45. return debListParser::NewVersion(Ver);
  46. }
  47. /*}}}*/
  48. // ListParser::Description - Return the description string /*{{{*/
  49. // ---------------------------------------------------------------------
  50. /* Sorry, no description for the resolvers… */
  51. std::vector<std::string> edspListParser::AvailableDescriptionLanguages()
  52. {
  53. return {};
  54. }
  55. MD5SumValue edspListParser::Description_md5()
  56. {
  57. return MD5SumValue("");
  58. }
  59. /*}}}*/
  60. // ListParser::VersionHash - Compute a unique hash for this version /*{{{*/
  61. // ---------------------------------------------------------------------
  62. /* */
  63. unsigned short edspListParser::VersionHash()
  64. {
  65. if (Section.Exists("APT-Hash") == true)
  66. return Section.FindI("APT-Hash");
  67. else if (Section.Exists("APT-ID") == true)
  68. return Section.FindI("APT-ID");
  69. return 0;
  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 (d->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 (d->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 (d->preferences.Write(out.c_str(), out.length()) == false)
  113. return false;
  114. }
  115. return true;
  116. }
  117. /*}}}*/
  118. // ListParser::LoadReleaseInfo - Load the release information /*{{{*/
  119. APT_CONST bool edspListParser::LoadReleaseInfo(pkgCache::RlsFileIterator & /*FileI*/,
  120. FileFd & /*File*/, std::string const &/*component*/)
  121. {
  122. return true;
  123. }
  124. /*}}}*/
  125. edspListParser::~edspListParser() /*{{{*/
  126. {
  127. delete d;
  128. }
  129. /*}}}*/