]>
git.saurik.com Git - apt.git/blob - apt-private/private-cachefile.cc
1 // Include files /*{{{*/
4 #include <apt-pkg/algorithms.h>
5 #include <apt-pkg/upgrade.h>
6 #include <apt-pkg/error.h>
10 #include "private-output.h"
11 #include "private-cachefile.h"
18 // CacheFile::NameComp - QSort compare by name /*{{{*/
19 // ---------------------------------------------------------------------
21 pkgCache
*CacheFile::SortCache
= 0;
22 int CacheFile::NameComp(const void *a
,const void *b
)
24 if (*(pkgCache::Package
**)a
== 0 || *(pkgCache::Package
**)b
== 0)
25 return *(pkgCache::Package
**)a
- *(pkgCache::Package
**)b
;
27 const pkgCache::Package
&A
= **(pkgCache::Package
**)a
;
28 const pkgCache::Package
&B
= **(pkgCache::Package
**)b
;
30 return strcmp(SortCache
->StrP
+ A
.Name
,SortCache
->StrP
+ B
.Name
);
33 // CacheFile::Sort - Sort by name /*{{{*/
34 // ---------------------------------------------------------------------
36 void CacheFile::Sort()
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
)
46 qsort(List
,Cache
->Head().PackageCount
,sizeof(*List
),NameComp
);
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
)
55 bool FixBroken
= _config
->FindB("APT::Get::Fix-Broken",false);
57 if (_error
->PendingError() == true)
60 // Check that the system is OK
61 if (DCache
->DelCount() != 0 || DCache
->InstCount() != 0)
62 return _error
->Error("Internal error, non-zero counts");
64 // Apply corrections for half-installed packages
65 if (pkgApplyStatus(*DCache
) == false)
68 if (_config
->FindB("APT::Get::Fix-Policy-Broken",false) == true)
71 if ((DCache
->PolicyBrokenCount() > 0))
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);
81 if (DCache
->BrokenCount() == 0 || AllowBroken
== true)
84 // Attempt to fix broken things
85 if (FixBroken
== true)
87 c1out
<< _("Correcting dependencies...") << flush
;
88 if (pkgFixBroken(*DCache
) == false || DCache
->BrokenCount() != 0)
90 c1out
<< _(" failed.") << endl
;
91 ShowBroken(c1out
,*this,true);
93 return _error
->Error(_("Unable to correct dependencies"));
95 if (pkgMinimizeUpgrade(*DCache
) == false)
96 return _error
->Error(_("Unable to minimize the upgrade set"));
98 c1out
<< _(" Done") << endl
;
102 c1out
<< _("You might want to run 'apt-get -f install' to correct these.") << endl
;
103 ShowBroken(c1out
,*this,true);
105 return _error
->Error(_("Unmet dependencies. Try using -f."));