summaryrefslogtreecommitdiffstats
path: root/apt-private/private-unmet.cc
blob: f5161fcc35e8402613c869044fa07c8413294ed4 (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
// -*- mode: cpp; mode: fold -*-
// Include Files							/*{{{*/
#include <config.h>

#include <apt-pkg/cachefile.h>
#include <apt-pkg/cmndline.h>
#include <apt-pkg/configuration.h>
#include <apt-pkg/strutl.h>

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

#include <stddef.h>

#include <iostream>

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

// UnMet - Show unmet dependencies					/*{{{*/
static bool ShowUnMet(pkgCache::VerIterator const &V, bool const Important)
{
	 bool Header = false;
	 for (pkgCache::DepIterator D = V.DependsList(); D.end() == false;)
	 {
	    // Collect or groups
	    pkgCache::DepIterator Start;
	    pkgCache::DepIterator End;
	    D.GlobOr(Start,End);

	    // Important deps only
	    if (Important == true)
	       if (End->Type != pkgCache::Dep::PreDepends &&
	           End->Type != pkgCache::Dep::Depends)
		  continue;

	    // Skip conflicts and replaces
	    if (End.IsNegative() == true || End->Type == pkgCache::Dep::Replaces)
	       continue;

	    // Verify the or group
	    bool OK = false;
	    pkgCache::DepIterator RealStart = Start;
	    do
	    {
	       // See if this dep is Ok
	       pkgCache::Version **VList = Start.AllTargets();
	       if (*VList != 0)
	       {
		  OK = true;
		  delete [] VList;
		  break;
	       }
	       delete [] VList;

	       if (Start == End)
		  break;
	       ++Start;
	    }
	    while (1);

	    // The group is OK
	    if (OK == true)
	       continue;

	    // Oops, it failed..
	    if (Header == false)
	       ioprintf(std::cout,_("Package %s version %s has an unmet dep:\n"),
			V.ParentPkg().FullName(true).c_str(),V.VerStr());
	    Header = true;

	    // Print out the dep type
	    std::cout << " " << End.DepType() << ": ";

	    // Show the group
	    Start = RealStart;
	    do
	    {
	       std::cout << Start.TargetPkg().FullName(true);
	       if (Start.TargetVer() != 0)
		  std::cout << " (" << Start.CompType() << " " << Start.TargetVer() <<
		  ")";
	       if (Start == End)
		  break;
	       std::cout << " | ";
	       ++Start;
	    }
	    while (1);

	    std::cout << std::endl;
	 }
   return true;
}
bool UnMet(CommandLine &CmdL)
{
   bool const Important = _config->FindB("APT::Cache::Important",false);

   pkgCacheFile CacheFile;
   if (unlikely(CacheFile.GetPkgCache() == NULL))
      return false;

   if (CmdL.FileSize() <= 1)
   {
      for (pkgCache::PkgIterator P = CacheFile.GetPkgCache()->PkgBegin(); P.end() == false; ++P)
	 for (pkgCache::VerIterator V = P.VersionList(); V.end() == false; ++V)
	    if (ShowUnMet(V, Important) == false)
	       return false;
   }
   else
   {
      CacheSetHelperVirtuals helper(true, GlobalError::NOTICE);
      APT::VersionList verset = APT::VersionList::FromCommandLine(CacheFile, CmdL.FileList + 1,
				APT::CacheSetHelper::CANDIDATE, helper);
      for (APT::VersionList::iterator V = verset.begin(); V != verset.end(); ++V)
	 if (ShowUnMet(V, Important) == false)
	    return false;
   }
   return true;
}
									/*}}}*/