]>
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>
7 #include <apt-pkg/configuration.h>
8 #include <apt-pkg/depcache.h>
9 #include <apt-pkg/pkgcache.h>
10 #include <apt-pkg/cacheiterators.h>
12 #include <apt-private/private-output.h>
13 #include <apt-private/private-cachefile.h>
24 // CacheFile::NameComp - QSort compare by name /*{{{*/
25 // ---------------------------------------------------------------------
27 pkgCache
*CacheFile::SortCache
= 0;
28 int CacheFile::NameComp(const void *a
,const void *b
)
30 if (*(pkgCache::Package
**)a
== 0 || *(pkgCache::Package
**)b
== 0)
31 return *(pkgCache::Package
**)a
- *(pkgCache::Package
**)b
;
33 const pkgCache::Package
&A
= **(pkgCache::Package
**)a
;
34 const pkgCache::Package
&B
= **(pkgCache::Package
**)b
;
36 return strcmp(SortCache
->StrP
+ A
.Name
,SortCache
->StrP
+ B
.Name
);
39 // CacheFile::Sort - Sort by name /*{{{*/
40 // ---------------------------------------------------------------------
42 void CacheFile::Sort()
45 List
= new pkgCache::Package
*[Cache
->Head().PackageCount
];
46 memset(List
,0,sizeof(*List
)*Cache
->Head().PackageCount
);
47 pkgCache::PkgIterator I
= Cache
->PkgBegin();
48 for (;I
.end() != true; ++I
)
52 qsort(List
,Cache
->Head().PackageCount
,sizeof(*List
),NameComp
);
55 // CacheFile::CheckDeps - Open the cache file /*{{{*/
56 // ---------------------------------------------------------------------
57 /* This routine generates the caches and then opens the dependency cache
58 and verifies that the system is OK. */
59 bool CacheFile::CheckDeps(bool AllowBroken
)
61 bool FixBroken
= _config
->FindB("APT::Get::Fix-Broken",false);
63 if (_error
->PendingError() == true)
66 // Check that the system is OK
67 if (DCache
->DelCount() != 0 || DCache
->InstCount() != 0)
68 return _error
->Error("Internal error, non-zero counts");
70 // Apply corrections for half-installed packages
71 if (pkgApplyStatus(*DCache
) == false)
74 if (_config
->FindB("APT::Get::Fix-Policy-Broken",false) == true)
77 if ((DCache
->PolicyBrokenCount() > 0))
79 // upgrade all policy-broken packages with ForceImportantDeps=True
80 for (pkgCache::PkgIterator I
= Cache
->PkgBegin(); !I
.end(); ++I
)
81 if ((*DCache
)[I
].NowPolicyBroken() == true)
82 DCache
->MarkInstall(I
,true,0, false, true);
87 if (DCache
->BrokenCount() == 0 || AllowBroken
== true)
90 // Attempt to fix broken things
91 if (FixBroken
== true)
93 c1out
<< _("Correcting dependencies...") << flush
;
94 if (pkgFixBroken(*DCache
) == false || DCache
->BrokenCount() != 0)
96 c1out
<< _(" failed.") << endl
;
97 ShowBroken(c1out
,*this,true);
99 return _error
->Error(_("Unable to correct dependencies"));
101 if (pkgMinimizeUpgrade(*DCache
) == false)
102 return _error
->Error(_("Unable to minimize the upgrade set"));
104 c1out
<< _(" Done") << endl
;
108 c1out
<< _("You might want to run 'apt-get -f install' to correct these.") << endl
;
109 ShowBroken(c1out
,*this,true);
111 return _error
->Error(_("Unmet dependencies. Try using -f."));