summaryrefslogtreecommitdiffstats
path: root/apt-private/private-depends.cc
blob: 95c747ee388de50e7dbd4777b8ec805b5b80a543 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
// Include Files							/*{{{*/
#include <config.h>

#include <apt-pkg/algorithms.h>
#include <apt-pkg/cachefile.h>
#include <apt-pkg/cacheset.h>
#include <apt-pkg/cmndline.h>
#include <apt-pkg/configuration.h>
#include <apt-pkg/error.h>
#include <apt-pkg/pkgcache.h>

#include <apt-private/private-cacheset.h>
#include <apt-private/private-depends.h>

#include <iostream>
#include <string>
#include <vector>

#include <stddef.h>

#include <apti18n.h>
									/*}}}*/

// ShowDepends - Helper for printing out a dependency tree		/*{{{*/
static bool ShowDepends(CommandLine &CmdL, bool const RevDepends)
{
   pkgCacheFile CacheFile;
   pkgCache * const Cache = CacheFile.GetPkgCache();
   if (unlikely(Cache == nullptr || CacheFile.GetDepCache() == nullptr))
      return false;

   CacheSetHelperVirtuals helper(false);
   APT::VersionList verset = APT::VersionList::FromCommandLine(CacheFile, CmdL.FileList + 1, APT::CacheSetHelper::CANDIDATE, helper);
   if (verset.empty() == true && helper.virtualPkgs.empty() == true)
      return _error->Error(_("No packages found"));
   std::vector<bool> Shown(Cache->Head().PackageCount);

   bool const Recurse = _config->FindB("APT::Cache::RecurseDepends", false);
   bool const Installed = _config->FindB("APT::Cache::Installed", false);
   bool const Important = _config->FindB("APT::Cache::Important", false);
   bool const ShowDepType = _config->FindB("APT::Cache::ShowDependencyType", RevDepends == false);
   bool const ShowVersion = _config->FindB("APT::Cache::ShowVersion", false);
   bool const ShowPreDepends = _config->FindB("APT::Cache::ShowPre-Depends", true);
   bool const ShowDepends = _config->FindB("APT::Cache::ShowDepends", true);
   bool const ShowRecommends = _config->FindB("APT::Cache::ShowRecommends", Important == false);
   bool const ShowSuggests = _config->FindB("APT::Cache::ShowSuggests", Important == false);
   bool const ShowReplaces = _config->FindB("APT::Cache::ShowReplaces", Important == false);
   bool const ShowConflicts = _config->FindB("APT::Cache::ShowConflicts", Important == false);
   bool const ShowBreaks = _config->FindB("APT::Cache::ShowBreaks", Important == false);
   bool const ShowEnhances = _config->FindB("APT::Cache::ShowEnhances", Important == false);
   bool const ShowOnlyFirstOr = _config->FindB("APT::Cache::ShowOnlyFirstOr", false);
   bool const ShowImplicit = _config->FindB("APT::Cache::ShowImplicit", false);

   while (verset.empty() != true)
   {
      pkgCache::VerIterator Ver = *verset.begin();
      verset.erase(verset.begin());
      pkgCache::PkgIterator Pkg = Ver.ParentPkg();
      Shown[Pkg->ID] = true;

      std::cout << Pkg.FullName(true) << std::endl;

      if (RevDepends == true)
	 std::cout << "Reverse Depends:" << std::endl;
      for (pkgCache::DepIterator D = RevDepends ? Pkg.RevDependsList() : Ver.DependsList();
	    D.end() == false; ++D)
      {
	 switch (D->Type) {
	    case pkgCache::Dep::PreDepends: if (!ShowPreDepends) continue; break;
	    case pkgCache::Dep::Depends: if (!ShowDepends) continue; break;
	    case pkgCache::Dep::Recommends: if (!ShowRecommends) continue; break;
	    case pkgCache::Dep::Suggests: if (!ShowSuggests) continue; break;
	    case pkgCache::Dep::Replaces: if (!ShowReplaces) continue; break;
	    case pkgCache::Dep::Conflicts: if (!ShowConflicts) continue; break;
	    case pkgCache::Dep::DpkgBreaks: if (!ShowBreaks) continue; break;
	    case pkgCache::Dep::Enhances: if (!ShowEnhances) continue; break;
	 }
	 if (ShowImplicit == false && D.IsImplicit())
	    continue;

	 pkgCache::PkgIterator Trg = RevDepends ? D.ParentPkg() : D.TargetPkg();

	 if((Installed && Trg->CurrentVer != 0) || !Installed)
	 {

	    if ((D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or && ShowOnlyFirstOr == false)
	       std::cout << " |";
	    else
	       std::cout << "  ";

	    // Show the package
	    if (ShowDepType == true)
	       std::cout << D.DepType() << ": ";
	    if (Trg->VersionList == 0)
	       std::cout << "<" << Trg.FullName(true) << ">";
	    else
	       std::cout << Trg.FullName(true);
	    if (ShowVersion == true && D->Version != 0)
	       std::cout << " (" << pkgCache::CompTypeDeb(D->CompareOp) << ' ' << D.TargetVer() << ')';
	    std::cout << std::endl;

	    if (Recurse == true && Shown[Trg->ID] == false)
	    {
	       Shown[Trg->ID] = true;
	       verset.insert(APT::VersionSet::FromPackage(CacheFile, Trg, APT::CacheSetHelper::CANDIDATE, helper));
	    }

	    // Display all solutions
	    std::unique_ptr<pkgCache::Version *[]> List(D.AllTargets());
	    pkgPrioSortList(*Cache,List.get());
	    for (pkgCache::Version **I = List.get(); *I != 0; I++)
	    {
	       pkgCache::VerIterator V(*Cache,*I);
	       if (V != Cache->VerP + V.ParentPkg()->VersionList ||
		   V->ParentPkg == D->Package)
		  continue;
	       std::cout << "    " << V.ParentPkg().FullName(true) << std::endl;

	       if (Recurse == true && Shown[V.ParentPkg()->ID] == false)
	       {
		  Shown[V.ParentPkg()->ID] = true;
		  verset.insert(APT::VersionSet::FromPackage(CacheFile, V.ParentPkg(), APT::CacheSetHelper::CANDIDATE, helper));
	       }
	    }

	 }

	 if (ShowOnlyFirstOr == true)
	    while ((D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or) ++D;
      }
   }

   for (APT::PackageSet::const_iterator Pkg = helper.virtualPkgs.begin();
	 Pkg != helper.virtualPkgs.end(); ++Pkg)
      std::cout << '<' << Pkg.FullName(true) << '>' << std::endl;

   return true;
}
									/*}}}*/
// Depends - Print out a dependency tree				/*{{{*/
bool Depends(CommandLine &CmdL)
{
   return ShowDepends(CmdL, false);
}
									/*}}}*/
// RDepends - Print out a reverse dependency tree			/*{{{*/
bool RDepends(CommandLine &CmdL)
{
   return ShowDepends(CmdL, true);
}
									/*}}}*/