You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

152 lines
5.6 KiB

  1. // Include Files /*{{{*/
  2. #include <config.h>
  3. #include <apt-pkg/algorithms.h>
  4. #include <apt-pkg/cachefile.h>
  5. #include <apt-pkg/cacheset.h>
  6. #include <apt-pkg/cmndline.h>
  7. #include <apt-pkg/configuration.h>
  8. #include <apt-pkg/error.h>
  9. #include <apt-pkg/pkgcache.h>
  10. #include <apt-private/private-cacheset.h>
  11. #include <apt-private/private-depends.h>
  12. #include <iostream>
  13. #include <string>
  14. #include <vector>
  15. #include <stddef.h>
  16. #include <apti18n.h>
  17. /*}}}*/
  18. // ShowDepends - Helper for printing out a dependency tree /*{{{*/
  19. static bool ShowDepends(CommandLine &CmdL, bool const RevDepends)
  20. {
  21. pkgCacheFile CacheFile;
  22. pkgCache * const Cache = CacheFile.GetPkgCache();
  23. if (unlikely(Cache == nullptr || CacheFile.GetDepCache() == nullptr))
  24. return false;
  25. CacheSetHelperVirtuals helper(false);
  26. APT::VersionList verset = APT::VersionList::FromCommandLine(CacheFile, CmdL.FileList + 1, APT::CacheSetHelper::CANDIDATE, helper);
  27. if (verset.empty() == true && helper.virtualPkgs.empty() == true)
  28. return _error->Error(_("No packages found"));
  29. std::vector<bool> Shown(Cache->Head().PackageCount);
  30. bool const Recurse = _config->FindB("APT::Cache::RecurseDepends", false);
  31. bool const Installed = _config->FindB("APT::Cache::Installed", false);
  32. bool const Important = _config->FindB("APT::Cache::Important", false);
  33. bool const ShowDepType = _config->FindB("APT::Cache::ShowDependencyType", RevDepends == false);
  34. bool const ShowVersion = _config->FindB("APT::Cache::ShowVersion", false);
  35. bool const ShowPreDepends = _config->FindB("APT::Cache::ShowPre-Depends", true);
  36. bool const ShowDepends = _config->FindB("APT::Cache::ShowDepends", true);
  37. bool const ShowRecommends = _config->FindB("APT::Cache::ShowRecommends", Important == false);
  38. bool const ShowSuggests = _config->FindB("APT::Cache::ShowSuggests", Important == false);
  39. bool const ShowReplaces = _config->FindB("APT::Cache::ShowReplaces", Important == false);
  40. bool const ShowConflicts = _config->FindB("APT::Cache::ShowConflicts", Important == false);
  41. bool const ShowBreaks = _config->FindB("APT::Cache::ShowBreaks", Important == false);
  42. bool const ShowEnhances = _config->FindB("APT::Cache::ShowEnhances", Important == false);
  43. bool const ShowOnlyFirstOr = _config->FindB("APT::Cache::ShowOnlyFirstOr", false);
  44. bool const ShowImplicit = _config->FindB("APT::Cache::ShowImplicit", false);
  45. while (verset.empty() != true)
  46. {
  47. pkgCache::VerIterator Ver = *verset.begin();
  48. verset.erase(verset.begin());
  49. pkgCache::PkgIterator Pkg = Ver.ParentPkg();
  50. Shown[Pkg->ID] = true;
  51. std::cout << Pkg.FullName(true) << std::endl;
  52. if (RevDepends == true)
  53. std::cout << "Reverse Depends:" << std::endl;
  54. for (pkgCache::DepIterator D = RevDepends ? Pkg.RevDependsList() : Ver.DependsList();
  55. D.end() == false; ++D)
  56. {
  57. switch (D->Type) {
  58. case pkgCache::Dep::PreDepends: if (!ShowPreDepends) continue; break;
  59. case pkgCache::Dep::Depends: if (!ShowDepends) continue; break;
  60. case pkgCache::Dep::Recommends: if (!ShowRecommends) continue; break;
  61. case pkgCache::Dep::Suggests: if (!ShowSuggests) continue; break;
  62. case pkgCache::Dep::Replaces: if (!ShowReplaces) continue; break;
  63. case pkgCache::Dep::Conflicts: if (!ShowConflicts) continue; break;
  64. case pkgCache::Dep::DpkgBreaks: if (!ShowBreaks) continue; break;
  65. case pkgCache::Dep::Enhances: if (!ShowEnhances) continue; break;
  66. }
  67. if (ShowImplicit == false && D.IsImplicit())
  68. continue;
  69. pkgCache::PkgIterator Trg = RevDepends ? D.ParentPkg() : D.TargetPkg();
  70. if((Installed && Trg->CurrentVer != 0) || !Installed)
  71. {
  72. if ((D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or && ShowOnlyFirstOr == false)
  73. std::cout << " |";
  74. else
  75. std::cout << " ";
  76. // Show the package
  77. if (ShowDepType == true)
  78. std::cout << D.DepType() << ": ";
  79. if (Trg->VersionList == 0)
  80. std::cout << "<" << Trg.FullName(true) << ">";
  81. else
  82. std::cout << Trg.FullName(true);
  83. if (ShowVersion == true && D->Version != 0)
  84. std::cout << " (" << pkgCache::CompTypeDeb(D->CompareOp) << ' ' << D.TargetVer() << ')';
  85. std::cout << std::endl;
  86. if (Recurse == true && Shown[Trg->ID] == false)
  87. {
  88. Shown[Trg->ID] = true;
  89. verset.insert(APT::VersionSet::FromPackage(CacheFile, Trg, APT::CacheSetHelper::CANDIDATE, helper));
  90. }
  91. }
  92. // Display all solutions
  93. std::unique_ptr<pkgCache::Version *[]> List(D.AllTargets());
  94. pkgPrioSortList(*Cache,List.get());
  95. for (pkgCache::Version **I = List.get(); *I != 0; I++)
  96. {
  97. pkgCache::VerIterator V(*Cache,*I);
  98. if (V != Cache->VerP + V.ParentPkg()->VersionList ||
  99. V->ParentPkg == D->Package)
  100. continue;
  101. std::cout << " " << V.ParentPkg().FullName(true) << std::endl;
  102. if (Recurse == true && Shown[V.ParentPkg()->ID] == false)
  103. {
  104. Shown[V.ParentPkg()->ID] = true;
  105. verset.insert(APT::VersionSet::FromPackage(CacheFile, V.ParentPkg(), APT::CacheSetHelper::CANDIDATE, helper));
  106. }
  107. }
  108. if (ShowOnlyFirstOr == true)
  109. while ((D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or) ++D;
  110. }
  111. }
  112. for (APT::PackageSet::const_iterator Pkg = helper.virtualPkgs.begin();
  113. Pkg != helper.virtualPkgs.end(); ++Pkg)
  114. std::cout << '<' << Pkg.FullName(true) << '>' << std::endl;
  115. return true;
  116. }
  117. /*}}}*/
  118. // Depends - Print out a dependency tree /*{{{*/
  119. bool Depends(CommandLine &CmdL)
  120. {
  121. return ShowDepends(CmdL, false);
  122. }
  123. /*}}}*/
  124. // RDepends - Print out a reverse dependency tree /*{{{*/
  125. bool RDepends(CommandLine &CmdL)
  126. {
  127. return ShowDepends(CmdL, true);
  128. }
  129. /*}}}*/