]> git.saurik.com Git - apt.git/blame - apt-private/private-cachefile.cc
use Pkg.FullName() in disappearedPkgs and remove duplicated check
[apt.git] / apt-private / private-cachefile.cc
CommitLineData
b9179170
MV
1// Include files /*{{{*/
2#include<config.h>
3
4#include <apt-pkg/algorithms.h>
5#include <apt-pkg/error.h>
6
7#include <cstdlib>
8
9#include "private-output.h"
10#include "private-cachefile.h"
11
12#include <apti18n.h>
13 /*}}}*/
14
15using namespace std;
16
17// CacheFile::NameComp - QSort compare by name /*{{{*/
18// ---------------------------------------------------------------------
19/* */
20pkgCache *CacheFile::SortCache = 0;
21int CacheFile::NameComp(const void *a,const void *b)
22{
23 if (*(pkgCache::Package **)a == 0 || *(pkgCache::Package **)b == 0)
24 return *(pkgCache::Package **)a - *(pkgCache::Package **)b;
25
26 const pkgCache::Package &A = **(pkgCache::Package **)a;
27 const pkgCache::Package &B = **(pkgCache::Package **)b;
28
29 return strcmp(SortCache->StrP + A.Name,SortCache->StrP + B.Name);
30}
31 /*}}}*/
32// CacheFile::Sort - Sort by name /*{{{*/
33// ---------------------------------------------------------------------
34/* */
35void CacheFile::Sort()
36{
37 delete [] List;
38 List = new pkgCache::Package *[Cache->Head().PackageCount];
39 memset(List,0,sizeof(*List)*Cache->Head().PackageCount);
40 pkgCache::PkgIterator I = Cache->PkgBegin();
41 for (;I.end() != true; ++I)
42 List[I->ID] = I;
43
44 SortCache = *this;
45 qsort(List,Cache->Head().PackageCount,sizeof(*List),NameComp);
46}
47 /*}}}*/
48// CacheFile::CheckDeps - Open the cache file /*{{{*/
49// ---------------------------------------------------------------------
50/* This routine generates the caches and then opens the dependency cache
51 and verifies that the system is OK. */
52bool CacheFile::CheckDeps(bool AllowBroken)
53{
54 bool FixBroken = _config->FindB("APT::Get::Fix-Broken",false);
55
56 if (_error->PendingError() == true)
57 return false;
58
59 // Check that the system is OK
60 if (DCache->DelCount() != 0 || DCache->InstCount() != 0)
61 return _error->Error("Internal error, non-zero counts");
62
63 // Apply corrections for half-installed packages
64 if (pkgApplyStatus(*DCache) == false)
65 return false;
66
67 if (_config->FindB("APT::Get::Fix-Policy-Broken",false) == true)
68 {
69 FixBroken = true;
70 if ((DCache->PolicyBrokenCount() > 0))
71 {
72 // upgrade all policy-broken packages with ForceImportantDeps=True
73 for (pkgCache::PkgIterator I = Cache->PkgBegin(); !I.end(); ++I)
74 if ((*DCache)[I].NowPolicyBroken() == true)
75 DCache->MarkInstall(I,true,0, false, true);
76 }
77 }
78
79 // Nothing is broken
80 if (DCache->BrokenCount() == 0 || AllowBroken == true)
81 return true;
82
83 // Attempt to fix broken things
84 if (FixBroken == true)
85 {
86 c1out << _("Correcting dependencies...") << flush;
87 if (pkgFixBroken(*DCache) == false || DCache->BrokenCount() != 0)
88 {
89 c1out << _(" failed.") << endl;
90 ShowBroken(c1out,*this,true);
91
92 return _error->Error(_("Unable to correct dependencies"));
93 }
94 if (pkgMinimizeUpgrade(*DCache) == false)
95 return _error->Error(_("Unable to minimize the upgrade set"));
96
97 c1out << _(" Done") << endl;
98 }
99 else
100 {
101 c1out << _("You might want to run 'apt-get -f install' to correct these.") << endl;
102 ShowBroken(c1out,*this,true);
103
104 return _error->Error(_("Unmet dependencies. Try using -f."));
105 }
106
107 return true;
108}
109 /*}}}*/