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