]> git.saurik.com Git - apt.git/blame - apt-private/private-cachefile.cc
move EditSources into its own file
[apt.git] / apt-private / private-cachefile.cc
CommitLineData
b9179170
MV
1// Include files /*{{{*/
2#include<config.h>
3
4#include <apt-pkg/algorithms.h>
82e369c4 5#include <apt-pkg/upgrade.h>
b9179170
MV
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
16using namespace std;
17
18// CacheFile::NameComp - QSort compare by name /*{{{*/
19// ---------------------------------------------------------------------
20/* */
21pkgCache *CacheFile::SortCache = 0;
22int 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/* */
36void 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. */
53bool 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 /*}}}*/