edsplistparser.cc 4.5 KB

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