private-unmet.cc 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. // -*- mode: cpp; mode: fold -*-
  2. // Include Files /*{{{*/
  3. #include<config.h>
  4. #include <apt-pkg/cachefile.h>
  5. #include <apt-pkg/cmndline.h>
  6. #include <apt-pkg/configuration.h>
  7. #include <apt-pkg/strutl.h>
  8. #include <apt-private/private-cacheset.h>
  9. #include <apt-private/private-unmet.h>
  10. #include <stddef.h>
  11. #include <iostream>
  12. #include <apti18n.h>
  13. /*}}}*/
  14. // UnMet - Show unmet dependencies /*{{{*/
  15. static bool ShowUnMet(pkgCache::VerIterator const &V, bool const Important)
  16. {
  17. bool Header = false;
  18. for (pkgCache::DepIterator D = V.DependsList(); D.end() == false;)
  19. {
  20. // Collect or groups
  21. pkgCache::DepIterator Start;
  22. pkgCache::DepIterator End;
  23. D.GlobOr(Start,End);
  24. // Important deps only
  25. if (Important == true)
  26. if (End->Type != pkgCache::Dep::PreDepends &&
  27. End->Type != pkgCache::Dep::Depends)
  28. continue;
  29. // Skip conflicts and replaces
  30. if (End.IsNegative() == true || End->Type == pkgCache::Dep::Replaces)
  31. continue;
  32. // Verify the or group
  33. bool OK = false;
  34. pkgCache::DepIterator RealStart = Start;
  35. do
  36. {
  37. // See if this dep is Ok
  38. pkgCache::Version **VList = Start.AllTargets();
  39. if (*VList != 0)
  40. {
  41. OK = true;
  42. delete [] VList;
  43. break;
  44. }
  45. delete [] VList;
  46. if (Start == End)
  47. break;
  48. ++Start;
  49. }
  50. while (1);
  51. // The group is OK
  52. if (OK == true)
  53. continue;
  54. // Oops, it failed..
  55. if (Header == false)
  56. ioprintf(std::cout,_("Package %s version %s has an unmet dep:\n"),
  57. V.ParentPkg().FullName(true).c_str(),V.VerStr());
  58. Header = true;
  59. // Print out the dep type
  60. std::cout << " " << End.DepType() << ": ";
  61. // Show the group
  62. Start = RealStart;
  63. do
  64. {
  65. std::cout << Start.TargetPkg().FullName(true);
  66. if (Start.TargetVer() != 0)
  67. std::cout << " (" << Start.CompType() << " " << Start.TargetVer() <<
  68. ")";
  69. if (Start == End)
  70. break;
  71. std::cout << " | ";
  72. ++Start;
  73. }
  74. while (1);
  75. std::cout << std::endl;
  76. }
  77. return true;
  78. }
  79. bool UnMet(CommandLine &CmdL)
  80. {
  81. bool const Important = _config->FindB("APT::Cache::Important",false);
  82. pkgCacheFile CacheFile;
  83. if (unlikely(CacheFile.GetPkgCache() == NULL))
  84. return false;
  85. if (CmdL.FileSize() <= 1)
  86. {
  87. for (pkgCache::PkgIterator P = CacheFile.GetPkgCache()->PkgBegin(); P.end() == false; ++P)
  88. for (pkgCache::VerIterator V = P.VersionList(); V.end() == false; ++V)
  89. if (ShowUnMet(V, Important) == false)
  90. return false;
  91. }
  92. else
  93. {
  94. CacheSetHelperVirtuals helper(true, GlobalError::NOTICE);
  95. APT::VersionList verset = APT::VersionList::FromCommandLine(CacheFile, CmdL.FileList + 1,
  96. APT::CacheSetHelper::CANDIDATE, helper);
  97. for (APT::VersionList::iterator V = verset.begin(); V != verset.end(); ++V)
  98. if (ShowUnMet(V, Important) == false)
  99. return false;
  100. }
  101. return true;
  102. }
  103. /*}}}*/