edsplistparser.cc 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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::string edspListParser::Description()
  51. {
  52. return "";
  53. }
  54. std::string edspListParser::DescriptionLanguage()
  55. {
  56. return "";
  57. }
  58. MD5SumValue edspListParser::Description_md5()
  59. {
  60. return MD5SumValue("");
  61. }
  62. /*}}}*/
  63. // ListParser::VersionHash - Compute a unique hash for this version /*{{{*/
  64. // ---------------------------------------------------------------------
  65. /* */
  66. unsigned short edspListParser::VersionHash()
  67. {
  68. if (Section.Exists("APT-Hash") == true)
  69. return Section.FindI("APT-Hash");
  70. else if (Section.Exists("APT-ID") == true)
  71. return Section.FindI("APT-ID");
  72. return 0;
  73. }
  74. /*}}}*/
  75. // ListParser::ParseStatus - Parse the status field /*{{{*/
  76. // ---------------------------------------------------------------------
  77. /* The Status: line here is not a normal dpkg one but just one which tells
  78. use if the package is installed or not, where missing means not. */
  79. bool edspListParser::ParseStatus(pkgCache::PkgIterator &Pkg,
  80. pkgCache::VerIterator &Ver)
  81. {
  82. unsigned long state = 0;
  83. if (Section.FindFlag("Hold",state,pkgCache::State::Hold) == false)
  84. return false;
  85. if (state != 0)
  86. Pkg->SelectedState = pkgCache::State::Hold;
  87. state = 0;
  88. if (Section.FindFlag("Installed",state,pkgCache::State::Installed) == false)
  89. return false;
  90. if (state != 0)
  91. {
  92. Pkg->CurrentState = pkgCache::State::Installed;
  93. Pkg->CurrentVer = Ver.Index();
  94. }
  95. if (Section.FindB("APT-Automatic", false))
  96. {
  97. std::string out;
  98. strprintf(out, "Package: %s\nArchitecture: %s\nAuto-Installed: 1\n\n", Pkg.Name(), Pkg.Arch());
  99. if (d->extendedstates.Write(out.c_str(), out.length()) == false)
  100. return false;
  101. }
  102. // FIXME: Using an overriding pin is wrong.
  103. if (Section.FindB("APT-Candidate", false))
  104. {
  105. std::string out;
  106. strprintf(out, "Package: %s\nPin: version %s\nPin-Priority: 9999\n\n", Pkg.FullName().c_str(), Ver.VerStr());
  107. if (d->preferences.Write(out.c_str(), out.length()) == false)
  108. return false;
  109. }
  110. signed short const pinvalue = Section.FindI("APT-Pin", 500);
  111. if (pinvalue != 500)
  112. {
  113. std::string out;
  114. strprintf(out, "Package: %s\nPin: version %s\nPin-Priority: %d\n\n", Pkg.FullName().c_str(), Ver.VerStr(), pinvalue);
  115. if (d->preferences.Write(out.c_str(), out.length()) == false)
  116. return false;
  117. }
  118. return true;
  119. }
  120. /*}}}*/
  121. // ListParser::LoadReleaseInfo - Load the release information /*{{{*/
  122. APT_CONST bool edspListParser::LoadReleaseInfo(pkgCache::RlsFileIterator & /*FileI*/,
  123. FileFd & /*File*/, std::string const &/*component*/)
  124. {
  125. return true;
  126. }
  127. /*}}}*/
  128. edspListParser::~edspListParser() /*{{{*/
  129. {
  130. delete d;
  131. }
  132. /*}}}*/