]> git.saurik.com Git - apt.git/blame - apt-pkg/algorithms.cc
Add missing \n
[apt.git] / apt-pkg / algorithms.cc
CommitLineData
6c139d6e
AL
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
abc8419e 3// $Id: algorithms.cc,v 1.34 2001/04/06 05:40:03 jgg Exp $
6c139d6e
AL
4/* ######################################################################
5
6 Algorithms - A set of misc algorithms
7
0a8e3465
AL
8 The pkgProblemResolver class has become insanely complex and
9 very sophisticated, it handles every test case I have thrown at it
10 to my satisfaction. Understanding exactly why all the steps the class
11 does are required is difficult and changing though not very risky
12 may result in other cases not working.
13
6c139d6e
AL
14 ##################################################################### */
15 /*}}}*/
16// Include Files /*{{{*/
17#ifdef __GNUG__
094a497d 18#pragma implementation "apt-pkg/algorithms.h"
6c139d6e 19#endif
094a497d
AL
20#include <apt-pkg/algorithms.h>
21#include <apt-pkg/error.h>
0a8e3465 22#include <apt-pkg/configuration.h>
b2e465d6
AL
23#include <apt-pkg/sptr.h>
24
25#include <apti18n.h>
26
6c139d6e
AL
27#include <iostream.h>
28 /*}}}*/
29
30pkgProblemResolver *pkgProblemResolver::This = 0;
31
32// Simulate::Simulate - Constructor /*{{{*/
33// ---------------------------------------------------------------------
b2e465d6
AL
34/* The legacy translations here of input Pkg iterators is obsolete,
35 this is not necessary since the pkgCaches are fully shared now. */
36pkgSimulate::pkgSimulate(pkgDepCache *Cache) : pkgPackageManager(Cache),
37 iPolicy(Cache),
38 Sim(&Cache->GetCache(),&iPolicy)
6c139d6e 39{
b2e465d6
AL
40 Sim.Init(0);
41 Flags = new unsigned char[Cache->Head().PackageCount];
42 memset(Flags,0,sizeof(*Flags)*Cache->Head().PackageCount);
281daf46
AL
43
44 // Fake a filename so as not to activate the media swapping
45 string Jnk = "SIMULATE";
b2e465d6 46 for (unsigned int I = 0; I != Cache->Head().PackageCount; I++)
281daf46 47 FileNames[I] = Jnk;
6c139d6e
AL
48}
49 /*}}}*/
b2e465d6
AL
50// Simulate::Describe - Describe a package /*{{{*/
51// ---------------------------------------------------------------------
52/* */
53void pkgSimulate::Describe(PkgIterator Pkg,ostream &out,bool Now)
54{
55 VerIterator Ver(Sim);
56 if (Now == true)
57 Ver = Pkg.CurrentVer();
58 else
59 Ver = Sim[Pkg].CandidateVerIter(Sim);
60
61 out << Pkg.Name();
62
63 if (Ver.end() == true)
64 return;
65
66 out << " (" << Ver.VerStr() << ' ' << Ver.RelStr() << ')';
67}
68 /*}}}*/
6c139d6e
AL
69// Simulate::Install - Simulate unpacking of a package /*{{{*/
70// ---------------------------------------------------------------------
71/* */
72bool pkgSimulate::Install(PkgIterator iPkg,string /*File*/)
73{
74 // Adapt the iterator
75 PkgIterator Pkg = Sim.FindPkg(iPkg.Name());
76 Flags[Pkg->ID] = 1;
77
b2e465d6
AL
78 cout << "Inst ";
79 Describe(Pkg,cout,false);
6c139d6e
AL
80 Sim.MarkInstall(Pkg,false);
81
82 // Look for broken conflicts+predepends.
83 for (PkgIterator I = Sim.PkgBegin(); I.end() == false; I++)
84 {
85 if (Sim[I].InstallVer == 0)
86 continue;
87
b2e465d6
AL
88 for (DepIterator D = Sim[I].InstVerIter(Sim).DependsList(); D.end() == false;)
89 {
90 DepIterator Start;
91 DepIterator End;
92 D.GlobOr(Start,End);
93 if (Start->Type == pkgCache::Dep::Conflicts ||
94 Start->Type == pkgCache::Dep::Obsoletes ||
95 End->Type == pkgCache::Dep::PreDepends)
6c139d6e 96 {
b2e465d6 97 if ((Sim[End] & pkgDepCache::DepGInstall) == 0)
6c139d6e 98 {
b2e465d6
AL
99 cout << " [" << I.Name() << " on " << Start.TargetPkg().Name() << ']';
100 if (Start->Type == pkgCache::Dep::Conflicts)
6c139d6e
AL
101 _error->Error("Fatal, conflicts violated %s",I.Name());
102 }
b2e465d6
AL
103 }
104 }
6c139d6e
AL
105 }
106
107 if (Sim.BrokenCount() != 0)
108 ShortBreaks();
109 else
04aa15a8 110 cout << endl;
6c139d6e
AL
111 return true;
112}
113 /*}}}*/
114// Simulate::Configure - Simulate configuration of a Package /*{{{*/
115// ---------------------------------------------------------------------
116/* This is not an acurate simulation of relatity, we should really not
117 install the package.. For some investigations it may be necessary
118 however. */
119bool pkgSimulate::Configure(PkgIterator iPkg)
120{
121 // Adapt the iterator
122 PkgIterator Pkg = Sim.FindPkg(iPkg.Name());
123
124 Flags[Pkg->ID] = 2;
125// Sim.MarkInstall(Pkg,false);
126 if (Sim[Pkg].InstBroken() == true)
127 {
04aa15a8 128 cout << "Conf " << Pkg.Name() << " broken" << endl;
6c139d6e
AL
129
130 Sim.Update();
131
132 // Print out each package and the failed dependencies
133 for (pkgCache::DepIterator D = Sim[Pkg].InstVerIter(Sim).DependsList(); D.end() == false; D++)
134 {
135 if (Sim.IsImportantDep(D) == false ||
136 (Sim[D] & pkgDepCache::DepInstall) != 0)
137 continue;
138
b2e465d6
AL
139 if (D->Type == pkgCache::Dep::Obsoletes)
140 cout << " Obsoletes:" << D.TargetPkg().Name();
141 else if (D->Type == pkgCache::Dep::Conflicts)
04aa15a8 142 cout << " Conflicts:" << D.TargetPkg().Name();
6c139d6e 143 else
04aa15a8 144 cout << " Depends:" << D.TargetPkg().Name();
6c139d6e 145 }
04aa15a8 146 cout << endl;
6c139d6e
AL
147
148 _error->Error("Conf Broken %s",Pkg.Name());
149 }
150 else
b2e465d6
AL
151 {
152 cout << "Conf ";
153 Describe(Pkg,cout,false);
154 }
6c139d6e
AL
155
156 if (Sim.BrokenCount() != 0)
157 ShortBreaks();
158 else
04aa15a8 159 cout << endl;
6c139d6e
AL
160
161 return true;
162}
163 /*}}}*/
164// Simulate::Remove - Simulate the removal of a package /*{{{*/
165// ---------------------------------------------------------------------
166/* */
fc4b5c9f 167bool pkgSimulate::Remove(PkgIterator iPkg,bool Purge)
6c139d6e
AL
168{
169 // Adapt the iterator
170 PkgIterator Pkg = Sim.FindPkg(iPkg.Name());
171
172 Flags[Pkg->ID] = 3;
173 Sim.MarkDelete(Pkg);
fc4b5c9f 174 if (Purge == true)
b2e465d6 175 cout << "Purg ";
fc4b5c9f 176 else
b2e465d6
AL
177 cout << "Remv ";
178 Describe(Pkg,cout,false);
6c139d6e
AL
179
180 if (Sim.BrokenCount() != 0)
181 ShortBreaks();
182 else
04aa15a8 183 cout << endl;
6c139d6e
AL
184
185 return true;
186}
187 /*}}}*/
188// Simulate::ShortBreaks - Print out a short line describing all breaks /*{{{*/
189// ---------------------------------------------------------------------
190/* */
191void pkgSimulate::ShortBreaks()
192{
04aa15a8 193 cout << " [";
6c139d6e
AL
194 for (PkgIterator I = Sim.PkgBegin(); I.end() == false; I++)
195 {
196 if (Sim[I].InstBroken() == true)
197 {
198 if (Flags[I->ID] == 0)
04aa15a8 199 cout << I.Name() << ' ';
6c139d6e 200/* else
04aa15a8 201 cout << I.Name() << "! ";*/
6c139d6e
AL
202 }
203 }
04aa15a8 204 cout << ']' << endl;
6c139d6e
AL
205}
206 /*}}}*/
207// ApplyStatus - Adjust for non-ok packages /*{{{*/
208// ---------------------------------------------------------------------
209/* We attempt to change the state of the all packages that have failed
210 installation toward their real state. The ordering code will perform
211 the necessary calculations to deal with the problems. */
212bool pkgApplyStatus(pkgDepCache &Cache)
213{
214 for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++)
215 {
d38b7b3d
AL
216 // Only choice for a ReInstReq package is to reinstall
217 if (I->InstState == pkgCache::State::ReInstReq ||
218 I->InstState == pkgCache::State::HoldReInstReq)
219 {
813c8eea
AL
220 if (I.CurrentVer().Downloadable() == true)
221 Cache.MarkKeep(I);
222 else
223 {
224 // Is this right? Will dpkg choke on an upgrade?
225 if (Cache[I].CandidateVerIter(Cache).Downloadable() == true)
226 Cache.MarkInstall(I);
227 else
b2e465d6
AL
228 return _error->Error(_("The package %s needs to be reinstalled, "
229 "but I can't find an archive for it."),I.Name());
813c8eea
AL
230 }
231
d38b7b3d
AL
232 continue;
233 }
234
6c139d6e
AL
235 switch (I->CurrentState)
236 {
813c8eea
AL
237 /* This means installation failed somehow - it does not need to be
238 re-unpacked (probably) */
b518cca6
AL
239 case pkgCache::State::UnPacked:
240 case pkgCache::State::HalfConfigured:
813c8eea
AL
241 if (I.CurrentVer().Downloadable() == true ||
242 I.State() != pkgCache::PkgIterator::NeedsUnpack)
243 Cache.MarkKeep(I);
244 else
245 {
246 if (Cache[I].CandidateVerIter(Cache).Downloadable() == true)
247 Cache.MarkInstall(I);
248 else
249 Cache.MarkDelete(I);
250 }
6c139d6e
AL
251 break;
252
253 // This means removal failed
b518cca6 254 case pkgCache::State::HalfInstalled:
6c139d6e
AL
255 Cache.MarkDelete(I);
256 break;
257
258 default:
b518cca6 259 if (I->InstState != pkgCache::State::Ok)
6c139d6e
AL
260 return _error->Error("The package %s is not ok and I "
261 "don't know how to fix it!",I.Name());
262 }
263 }
264 return true;
265}
266 /*}}}*/
267// FixBroken - Fix broken packages /*{{{*/
268// ---------------------------------------------------------------------
0a8e3465
AL
269/* This autoinstalls every broken package and then runs the problem resolver
270 on the result. */
6c139d6e
AL
271bool pkgFixBroken(pkgDepCache &Cache)
272{
273 // Auto upgrade all broken packages
274 for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++)
275 if (Cache[I].NowBroken() == true)
276 Cache.MarkInstall(I,true);
7e798dd7 277
6c139d6e
AL
278 /* Fix packages that are in a NeedArchive state but don't have a
279 downloadable install version */
280 for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++)
281 {
282 if (I.State() != pkgCache::PkgIterator::NeedsUnpack ||
283 Cache[I].Delete() == true)
284 continue;
285
b518cca6 286 if (Cache[I].InstVerIter(Cache).Downloadable() == false)
6c139d6e
AL
287 continue;
288
7e798dd7 289 Cache.MarkInstall(I,true);
6c139d6e
AL
290 }
291
b2e465d6 292 pkgProblemResolver Fix(&Cache);
6c139d6e
AL
293 return Fix.Resolve(true);
294}
295 /*}}}*/
296// DistUpgrade - Distribution upgrade /*{{{*/
297// ---------------------------------------------------------------------
298/* This autoinstalls every package and then force installs every
299 pre-existing package. This creates the initial set of conditions which
300 most likely contain problems because too many things were installed.
301
0a8e3465 302 The problem resolver is used to resolve the problems.
6c139d6e
AL
303 */
304bool pkgDistUpgrade(pkgDepCache &Cache)
305{
306 /* Auto upgrade all installed packages, this provides the basis
307 for the installation */
308 for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++)
309 if (I->CurrentVer != 0)
310 Cache.MarkInstall(I,true);
311
312 /* Now, auto upgrade all essential packages - this ensures that
313 the essential packages are present and working */
314 for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++)
b518cca6 315 if ((I->Flags & pkgCache::Flag::Essential) == pkgCache::Flag::Essential)
6c139d6e
AL
316 Cache.MarkInstall(I,true);
317
318 /* We do it again over all previously installed packages to force
319 conflict resolution on them all. */
320 for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++)
321 if (I->CurrentVer != 0)
322 Cache.MarkInstall(I,false);
323
b2e465d6 324 pkgProblemResolver Fix(&Cache);
c88edf1d 325
6c139d6e 326 // Hold back held packages.
4490f2de 327 if (_config->FindB("APT::Ignore-Hold",false) == false)
6c139d6e 328 {
c88edf1d 329 for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++)
6c139d6e 330 {
c88edf1d
AL
331 if (I->SelectedState == pkgCache::State::Hold)
332 {
333 Fix.Protect(I);
334 Cache.MarkKeep(I);
335 }
6c139d6e
AL
336 }
337 }
338
339 return Fix.Resolve();
340}
341 /*}}}*/
0a8e3465
AL
342// AllUpgrade - Upgrade as many packages as possible /*{{{*/
343// ---------------------------------------------------------------------
344/* Right now the system must be consistent before this can be called.
345 It also will not change packages marked for install, it only tries
346 to install packages not marked for install */
347bool pkgAllUpgrade(pkgDepCache &Cache)
348{
b2e465d6 349 pkgProblemResolver Fix(&Cache);
0a8e3465
AL
350
351 if (Cache.BrokenCount() != 0)
352 return false;
353
354 // Upgrade all installed packages
355 for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++)
356 {
357 if (Cache[I].Install() == true)
358 Fix.Protect(I);
359
b2e465d6 360 if (_config->FindB("APT::Ignore-Hold",false) == false)
c88edf1d
AL
361 if (I->SelectedState == pkgCache::State::Hold)
362 continue;
0a8e3465
AL
363
364 if (I->CurrentVer != 0 && Cache[I].InstallVer != 0)
365 Cache.MarkInstall(I,false);
366 }
367
368 return Fix.ResolveByKeep();
369}
370 /*}}}*/
7e798dd7
AL
371// MinimizeUpgrade - Minimizes the set of packages to be upgraded /*{{{*/
372// ---------------------------------------------------------------------
373/* This simply goes over the entire set of packages and tries to keep
374 each package marked for upgrade. If a conflict is generated then
375 the package is restored. */
376bool pkgMinimizeUpgrade(pkgDepCache &Cache)
377{
378 if (Cache.BrokenCount() != 0)
379 return false;
380
abc8419e 381 // We loop for 10 tries to get the minimal set size.
7e798dd7 382 bool Change = false;
a005475e 383 unsigned int Count = 0;
7e798dd7
AL
384 do
385 {
386 Change = false;
387 for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++)
388 {
389 // Not interesting
390 if (Cache[I].Upgrade() == false || Cache[I].NewInstall() == true)
391 continue;
a005475e 392
7e798dd7
AL
393 // Keep it and see if that is OK
394 Cache.MarkKeep(I);
395 if (Cache.BrokenCount() != 0)
396 Cache.MarkInstall(I,false);
397 else
a005475e
AL
398 {
399 // If keep didnt actually do anything then there was no change..
400 if (Cache[I].Upgrade() == false)
401 Change = true;
402 }
7e798dd7 403 }
a005475e 404 Count++;
7e798dd7 405 }
a005475e 406 while (Change == true && Count < 10);
7e798dd7
AL
407
408 if (Cache.BrokenCount() != 0)
409 return _error->Error("Internal Error in pkgMinimizeUpgrade");
410
411 return true;
412}
413 /*}}}*/
6c139d6e
AL
414
415// ProblemResolver::pkgProblemResolver - Constructor /*{{{*/
416// ---------------------------------------------------------------------
417/* */
b2e465d6 418pkgProblemResolver::pkgProblemResolver(pkgDepCache *pCache) : Cache(*pCache)
6c139d6e
AL
419{
420 // Allocate memory
b2e465d6 421 unsigned long Size = Cache.Head().PackageCount;
6c139d6e
AL
422 Scores = new signed short[Size];
423 Flags = new unsigned char[Size];
424 memset(Flags,0,sizeof(*Flags)*Size);
425
426 // Set debug to true to see its decision logic
0a8e3465 427 Debug = _config->FindB("Debug::pkgProblemResolver",false);
6c139d6e
AL
428}
429 /*}}}*/
b2e465d6
AL
430// ProblemResolver::~pkgProblemResolver - Destructor /*{{{*/
431// ---------------------------------------------------------------------
432/* */
433pkgProblemResolver::~pkgProblemResolver()
434{
435 delete [] Scores;
436 delete [] Flags;
437}
438 /*}}}*/
6c139d6e
AL
439// ProblemResolver::ScoreSort - Sort the list by score /*{{{*/
440// ---------------------------------------------------------------------
441/* */
442int pkgProblemResolver::ScoreSort(const void *a,const void *b)
443{
444 Package const **A = (Package const **)a;
445 Package const **B = (Package const **)b;
446 if (This->Scores[(*A)->ID] > This->Scores[(*B)->ID])
447 return -1;
448 if (This->Scores[(*A)->ID] < This->Scores[(*B)->ID])
449 return 1;
450 return 0;
451}
452 /*}}}*/
453// ProblemResolver::MakeScores - Make the score table /*{{{*/
454// ---------------------------------------------------------------------
455/* */
456void pkgProblemResolver::MakeScores()
457{
b2e465d6 458 unsigned long Size = Cache.Head().PackageCount;
6c139d6e
AL
459 memset(Scores,0,sizeof(*Scores)*Size);
460
461 // Generate the base scores for a package based on its properties
462 for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++)
463 {
464 if (Cache[I].InstallVer == 0)
465 continue;
466
467 signed short &Score = Scores[I->ID];
468
469 /* This is arbitary, it should be high enough to elevate an
470 essantial package above most other packages but low enough
471 to allow an obsolete essential packages to be removed by
472 a conflicts on a powerfull normal package (ie libc6) */
b518cca6 473 if ((I->Flags & pkgCache::Flag::Essential) == pkgCache::Flag::Essential)
6c139d6e
AL
474 Score += 100;
475
476 // We transform the priority
477 // Important Required Standard Optional Extra
478 signed short PrioMap[] = {0,3,2,1,-1,-2};
479 if (Cache[I].InstVerIter(Cache)->Priority <= 5)
480 Score += PrioMap[Cache[I].InstVerIter(Cache)->Priority];
481
482 /* This helps to fix oddball problems with conflicting packages
483 on the same level. We enhance the score of installed packages */
484 if (I->CurrentVer != 0)
485 Score += 1;
486 }
487
488 // Now that we have the base scores we go and propogate dependencies
489 for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++)
490 {
491 if (Cache[I].InstallVer == 0)
492 continue;
493
494 for (pkgCache::DepIterator D = Cache[I].InstVerIter(Cache).DependsList(); D.end() == false; D++)
495 {
b518cca6 496 if (D->Type == pkgCache::Dep::Depends || D->Type == pkgCache::Dep::PreDepends)
6c139d6e
AL
497 Scores[D.TargetPkg()->ID]++;
498 }
499 }
500
501 // Copy the scores to advoid additive looping
b2e465d6 502 SPtrArray<signed short> OldScores = new signed short[Size];
6c139d6e
AL
503 memcpy(OldScores,Scores,sizeof(*Scores)*Size);
504
505 /* Now we cause 1 level of dependency inheritance, that is we add the
506 score of the packages that depend on the target Package. This
507 fortifies high scoring packages */
508 for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++)
509 {
510 if (Cache[I].InstallVer == 0)
511 continue;
512
513 for (pkgCache::DepIterator D = I.RevDependsList(); D.end() == false; D++)
514 {
515 // Only do it for the install version
516 if ((pkgCache::Version *)D.ParentVer() != Cache[D.ParentPkg()].InstallVer ||
b518cca6 517 (D->Type != pkgCache::Dep::Depends && D->Type != pkgCache::Dep::PreDepends))
6c139d6e
AL
518 continue;
519
520 Scores[I->ID] += abs(OldScores[D.ParentPkg()->ID]);
521 }
522 }
523
524 /* Now we propogate along provides. This makes the packages that
525 provide important packages extremely important */
526 for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++)
527 {
528 for (pkgCache::PrvIterator P = I.ProvidesList(); P.end() == false; P++)
529 {
530 // Only do it once per package
531 if ((pkgCache::Version *)P.OwnerVer() != Cache[P.OwnerPkg()].InstallVer)
532 continue;
533 Scores[P.OwnerPkg()->ID] += abs(Scores[I->ID] - OldScores[I->ID]);
534 }
535 }
536
537 /* Protected things are pushed really high up. This number should put them
538 ahead of everything */
539 for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++)
d2685fd6 540 {
6c139d6e
AL
541 if ((Flags[I->ID] & Protected) != 0)
542 Scores[I->ID] += 10000;
d2685fd6
AL
543 if ((I->Flags & pkgCache::Flag::Essential) == pkgCache::Flag::Essential)
544 Scores[I->ID] += 5000;
b2e465d6 545 }
6c139d6e
AL
546}
547 /*}}}*/
548// ProblemResolver::DoUpgrade - Attempt to upgrade this package /*{{{*/
549// ---------------------------------------------------------------------
550/* This goes through and tries to reinstall packages to make this package
551 installable */
552bool pkgProblemResolver::DoUpgrade(pkgCache::PkgIterator Pkg)
553{
554 if ((Flags[Pkg->ID] & Upgradable) == 0 || Cache[Pkg].Upgradable() == false)
555 return false;
0a8e3465 556
6c139d6e
AL
557 Flags[Pkg->ID] &= ~Upgradable;
558
559 bool WasKept = Cache[Pkg].Keep();
560 Cache.MarkInstall(Pkg,false);
561
0a8e3465
AL
562 // This must be a virtual package or something like that.
563 if (Cache[Pkg].InstVerIter(Cache).end() == true)
564 return false;
565
6c139d6e
AL
566 // Isolate the problem dependency
567 bool Fail = false;
568 for (pkgCache::DepIterator D = Cache[Pkg].InstVerIter(Cache).DependsList(); D.end() == false;)
569 {
570 // Compute a single dependency element (glob or)
571 pkgCache::DepIterator Start = D;
572 pkgCache::DepIterator End = D;
573 unsigned char State = 0;
4b1b89c5 574 for (bool LastOR = true; D.end() == false && LastOR == true;)
6c139d6e
AL
575 {
576 State |= Cache[D];
b518cca6 577 LastOR = (D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or;
4b1b89c5 578 D++;
6c139d6e
AL
579 if (LastOR == true)
580 End = D;
581 }
582
583 // We only worry about critical deps.
584 if (End.IsCritical() != true)
585 continue;
4b1b89c5
AL
586
587 // Iterate over all the members in the or group
588 while (1)
0a8e3465 589 {
4b1b89c5
AL
590 // Dep is ok now
591 if ((Cache[End] & pkgDepCache::DepGInstall) == pkgDepCache::DepGInstall)
592 break;
593
594 // Do not change protected packages
595 PkgIterator P = Start.SmartTargetPkg();
596 if ((Flags[P->ID] & Protected) == Protected)
597 {
598 if (Debug == true)
648e3cb4 599 clog << " Reinst Failed because of protected " << P.Name() << endl;
4b1b89c5 600 Fail = true;
4b1b89c5 601 }
648e3cb4 602 else
6c139d6e 603 {
648e3cb4
AL
604 // Upgrade the package if the candidate version will fix the problem.
605 if ((Cache[Start] & pkgDepCache::DepCVer) == pkgDepCache::DepCVer)
606 {
607 if (DoUpgrade(P) == false)
608 {
609 if (Debug == true)
610 clog << " Reinst Failed because of " << P.Name() << endl;
611 Fail = true;
612 }
613 else
614 {
615 Fail = false;
616 break;
617 }
618 }
619 else
4b1b89c5 620 {
648e3cb4
AL
621 /* We let the algorithm deal with conflicts on its next iteration,
622 it is much smarter than us */
b2e465d6
AL
623 if (Start->Type == pkgCache::Dep::Conflicts ||
624 Start->Type == pkgCache::Dep::Obsoletes)
625 break;
648e3cb4 626
4b1b89c5 627 if (Debug == true)
648e3cb4 628 clog << " Reinst Failed early because of " << Start.TargetPkg().Name() << endl;
4b1b89c5 629 Fail = true;
648e3cb4 630 }
4b1b89c5 631 }
6c139d6e 632
4b1b89c5
AL
633 if (Start == End)
634 break;
635 Start++;
636 }
637 if (Fail == true)
6c139d6e 638 break;
6c139d6e
AL
639 }
640
641 // Undo our operations - it might be smart to undo everything this did..
642 if (Fail == true)
643 {
644 if (WasKept == true)
645 Cache.MarkKeep(Pkg);
646 else
647 Cache.MarkDelete(Pkg);
648 return false;
649 }
650
651 if (Debug == true)
0a8e3465 652 clog << " Re-Instated " << Pkg.Name() << endl;
6c139d6e
AL
653 return true;
654}
655 /*}}}*/
656// ProblemResolver::Resolve - Run the resolution pass /*{{{*/
657// ---------------------------------------------------------------------
658/* This routines works by calculating a score for each package. The score
659 is derived by considering the package's priority and all reverse
660 dependents giving an integer that reflects the amount of breakage that
661 adjusting the package will inflict.
662
663 It goes from highest score to lowest and corrects all of the breaks by
664 keeping or removing the dependant packages. If that fails then it removes
665 the package itself and goes on. The routine should be able to intelligently
666 go from any broken state to a fixed state.
667
668 The BrokenFix flag enables a mode where the algorithm tries to
669 upgrade packages to advoid problems. */
670bool pkgProblemResolver::Resolve(bool BrokenFix)
671{
b2e465d6 672 unsigned long Size = Cache.Head().PackageCount;
6c139d6e
AL
673
674 // Record which packages are marked for install
675 bool Again = false;
676 do
677 {
678 Again = false;
679 for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++)
680 {
681 if (Cache[I].Install() == true)
682 Flags[I->ID] |= PreInstalled;
683 else
684 {
685 if (Cache[I].InstBroken() == true && BrokenFix == true)
686 {
687 Cache.MarkInstall(I,false);
688 if (Cache[I].Install() == true)
689 Again = true;
690 }
691
692 Flags[I->ID] &= ~PreInstalled;
693 }
694 Flags[I->ID] |= Upgradable;
695 }
696 }
697 while (Again == true);
698
699 if (Debug == true)
0a8e3465 700 clog << "Starting" << endl;
6c139d6e
AL
701
702 MakeScores();
703
704 /* We have to order the packages so that the broken fixing pass
705 operates from highest score to lowest. This prevents problems when
706 high score packages cause the removal of lower score packages that
707 would cause the removal of even lower score packages. */
b2e465d6 708 SPtrArray<pkgCache::Package *> PList = new pkgCache::Package *[Size];
6c139d6e
AL
709 pkgCache::Package **PEnd = PList;
710 for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++)
711 *PEnd++ = I;
712 This = this;
713 qsort(PList,PEnd - PList,sizeof(*PList),&ScoreSort);
714
715/* for (pkgCache::Package **K = PList; K != PEnd; K++)
716 if (Scores[(*K)->ID] != 0)
717 {
718 pkgCache::PkgIterator Pkg(Cache,*K);
0a8e3465 719 clog << Scores[(*K)->ID] << ' ' << Pkg.Name() <<
6c139d6e
AL
720 ' ' << (pkgCache::Version *)Pkg.CurrentVer() << ' ' <<
721 Cache[Pkg].InstallVer << ' ' << Cache[Pkg].CandidateVer << endl;
722 } */
723
724 if (Debug == true)
0a8e3465 725 clog << "Starting 2" << endl;
6c139d6e
AL
726
727 /* Now consider all broken packages. For each broken package we either
728 remove the package or fix it's problem. We do this once, it should
729 not be possible for a loop to form (that is a < b < c and fixing b by
730 changing a breaks c) */
731 bool Change = true;
732 for (int Counter = 0; Counter != 10 && Change == true; Counter++)
733 {
734 Change = false;
735 for (pkgCache::Package **K = PList; K != PEnd; K++)
736 {
737 pkgCache::PkgIterator I(Cache,*K);
738
739 /* We attempt to install this and see if any breaks result,
740 this takes care of some strange cases */
741 if (Cache[I].CandidateVer != Cache[I].InstallVer &&
742 I->CurrentVer != 0 && Cache[I].InstallVer != 0 &&
743 (Flags[I->ID] & PreInstalled) != 0 &&
0a8e3465
AL
744 (Flags[I->ID] & Protected) == 0 &&
745 (Flags[I->ID] & ReInstateTried) == 0)
6c139d6e
AL
746 {
747 if (Debug == true)
0a8e3465 748 clog << " Try to Re-Instate " << I.Name() << endl;
a6568219 749 unsigned long OldBreaks = Cache.BrokenCount();
6c139d6e 750 pkgCache::Version *OldVer = Cache[I].InstallVer;
0a8e3465
AL
751 Flags[I->ID] &= ReInstateTried;
752
6c139d6e
AL
753 Cache.MarkInstall(I,false);
754 if (Cache[I].InstBroken() == true ||
755 OldBreaks < Cache.BrokenCount())
756 {
757 if (OldVer == 0)
758 Cache.MarkDelete(I);
759 else
760 Cache.MarkKeep(I);
761 }
762 else
763 if (Debug == true)
0a8e3465 764 clog << "Re-Instated " << I.Name() << " (" << OldBreaks << " vs " << Cache.BrokenCount() << ')' << endl;
6c139d6e
AL
765 }
766
767 if (Cache[I].InstallVer == 0 || Cache[I].InstBroken() == false)
768 continue;
769
00b47c98
AL
770 if (Debug == true)
771 cout << "Investigating " << I.Name() << endl;
772
6c139d6e
AL
773 // Isolate the problem dependency
774 PackageKill KillList[100];
775 PackageKill *LEnd = KillList;
421c8d10
AL
776 bool InOr = false;
777 pkgCache::DepIterator Start;
778 pkgCache::DepIterator End;
b2e465d6 779 PackageKill *OldEnd = LEnd;
648e3cb4
AL
780
781 enum {OrRemove,OrKeep} OrOp = OrRemove;
421c8d10
AL
782 for (pkgCache::DepIterator D = Cache[I].InstVerIter(Cache).DependsList();
783 D.end() == false || InOr == true;)
6c139d6e
AL
784 {
785 // Compute a single dependency element (glob or)
648e3cb4
AL
786 if (Start == End)
787 {
788 // Decide what to do
789 if (InOr == true)
790 {
791 if (OldEnd == LEnd && OrOp == OrRemove)
70777d4b
AL
792 {
793 if ((Flags[I->ID] & Protected) != Protected)
00b47c98
AL
794 {
795 if (Debug == true)
796 clog << " Or group remove for " << I.Name() << endl;
70777d4b 797 Cache.MarkDelete(I);
00b47c98 798 }
70777d4b 799 }
648e3cb4 800 if (OldEnd == LEnd && OrOp == OrKeep)
00b47c98
AL
801 {
802 if (Debug == true)
803 clog << " Or group keep for " << I.Name() << endl;
648e3cb4 804 Cache.MarkKeep(I);
b2e465d6 805 }
648e3cb4
AL
806 }
807
b2e465d6
AL
808 /* We do an extra loop (as above) to finalize the or group
809 processing */
810 InOr = false;
648e3cb4 811 OrOp = OrRemove;
421c8d10 812 D.GlobOr(Start,End);
b2e465d6
AL
813 if (Start.end() == true)
814 break;
815
816 // We only worry about critical deps.
817 if (End.IsCritical() != true)
818 continue;
819
648e3cb4
AL
820 InOr = Start != End;
821 OldEnd = LEnd;
822 }
421c8d10
AL
823 else
824 Start++;
6c139d6e
AL
825
826 // Dep is ok
827 if ((Cache[End] & pkgDepCache::DepGInstall) == pkgDepCache::DepGInstall)
828 continue;
648e3cb4 829
6c139d6e 830 if (Debug == true)
421c8d10 831 clog << "Package " << I.Name() << " has broken dep on " << Start.TargetPkg().Name() << endl;
fcf85120
AL
832
833 /* Look across the version list. If there are no possible
834 targets then we keep the package and bail. This is necessary
835 if a package has a dep on another package that cant be found */
b2e465d6 836 SPtrArray<pkgCache::Version *> VList = Start.AllTargets();
fcf85120 837 if (*VList == 0 && (Flags[I->ID] & Protected) != Protected &&
648e3cb4 838 Start->Type != pkgCache::Dep::Conflicts &&
b2e465d6 839 Start->Type != pkgCache::Dep::Obsoletes &&
fcf85120 840 Cache[I].NowBroken() == false)
648e3cb4
AL
841 {
842 if (InOr == true)
843 {
844 /* No keep choice because the keep being OK could be the
845 result of another element in the OR group! */
846 continue;
847 }
848
fcf85120 849 Change = true;
648e3cb4 850 Cache.MarkKeep(I);
fcf85120
AL
851 break;
852 }
853
6c139d6e
AL
854 bool Done = false;
855 for (pkgCache::Version **V = VList; *V != 0; V++)
856 {
857 pkgCache::VerIterator Ver(Cache,*V);
858 pkgCache::PkgIterator Pkg = Ver.ParentPkg();
a6bfe583 859
6c139d6e 860 if (Debug == true)
421c8d10 861 clog << " Considering " << Pkg.Name() << ' ' << (int)Scores[Pkg->ID] <<
6c139d6e 862 " as a solution to " << I.Name() << ' ' << (int)Scores[I->ID] << endl;
a6bfe583
AL
863
864 /* Try to fix the package under consideration rather than
865 fiddle with the VList package */
6c139d6e 866 if (Scores[I->ID] <= Scores[Pkg->ID] ||
421c8d10 867 ((Cache[Start] & pkgDepCache::DepNow) == 0 &&
b2e465d6
AL
868 End->Type != pkgCache::Dep::Conflicts &&
869 End->Type != pkgCache::Dep::Obsoletes))
6c139d6e 870 {
200f8c52 871 // Try a little harder to fix protected packages..
3b5421b4 872 if ((Flags[I->ID] & Protected) == Protected)
200f8c52
AL
873 {
874 if (DoUpgrade(Pkg) == true)
0296c633 875 {
b2e465d6
AL
876 if (Scores[Pkg->ID] > Scores[I->ID])
877 Scores[Pkg->ID] = Scores[I->ID];
0296c633
AL
878 break;
879 }
880
6c139d6e 881 continue;
200f8c52
AL
882 }
883
884 /* See if a keep will do, unless the package is protected,
648e3cb4
AL
885 then installing it will be necessary */
886 bool Installed = Cache[I].Install();
6c139d6e
AL
887 Cache.MarkKeep(I);
888 if (Cache[I].InstBroken() == false)
889 {
648e3cb4
AL
890 // Unwind operation will be keep now
891 if (OrOp == OrRemove)
892 OrOp = OrKeep;
893
894 // Restore
895 if (InOr == true && Installed == true)
896 Cache.MarkInstall(I,false);
897
6c139d6e 898 if (Debug == true)
421c8d10 899 clog << " Holding Back " << I.Name() << " rather than change " << Start.TargetPkg().Name() << endl;
6c139d6e
AL
900 }
901 else
421c8d10 902 {
6c139d6e
AL
903 if (BrokenFix == false || DoUpgrade(I) == false)
904 {
421c8d10
AL
905 // Consider other options
906 if (InOr == false)
907 {
908 if (Debug == true)
909 clog << " Removing " << I.Name() << " rather than change " << Start.TargetPkg().Name() << endl;
910 Cache.MarkDelete(I);
911 if (Counter > 1)
b2e465d6
AL
912 {
913 if (Scores[Pkg->ID] > Scores[I->ID])
914 Scores[I->ID] = Scores[Pkg->ID];
915 }
421c8d10 916 }
0a8e3465 917 }
6c139d6e 918 }
b5dc9785 919
6c139d6e
AL
920 Change = true;
921 Done = true;
922 break;
923 }
924 else
925 {
a6bfe583
AL
926 /* This is a conflicts, and the version we are looking
927 at is not the currently selected version of the
928 package, which means it is not necessary to
929 remove/keep */
930 if (Cache[Pkg].InstallVer != Ver &&
931 (Start->Type == pkgCache::Dep::Conflicts ||
932 Start->Type == pkgCache::Dep::Obsoletes))
933 continue;
934
648e3cb4 935 // Skip adding to the kill list if it is protected
6c139d6e
AL
936 if ((Flags[Pkg->ID] & Protected) != 0)
937 continue;
a6bfe583
AL
938
939 if (Debug == true)
940 clog << " Added " << Pkg.Name() << " to the remove list" << endl;
6c139d6e
AL
941
942 LEnd->Pkg = Pkg;
943 LEnd->Dep = End;
944 LEnd++;
0a8e3465 945
b2e465d6
AL
946 if (Start->Type != pkgCache::Dep::Conflicts &&
947 Start->Type != pkgCache::Dep::Obsoletes)
6c139d6e
AL
948 break;
949 }
950 }
951
952 // Hm, nothing can possibly satisify this dep. Nuke it.
b2e465d6
AL
953 if (VList[0] == 0 &&
954 Start->Type != pkgCache::Dep::Conflicts &&
955 Start->Type != pkgCache::Dep::Obsoletes &&
648e3cb4 956 (Flags[I->ID] & Protected) != Protected)
6c139d6e 957 {
648e3cb4 958 bool Installed = Cache[I].Install();
6c139d6e
AL
959 Cache.MarkKeep(I);
960 if (Cache[I].InstBroken() == false)
961 {
648e3cb4
AL
962 // Unwind operation will be keep now
963 if (OrOp == OrRemove)
964 OrOp = OrKeep;
965
966 // Restore
967 if (InOr == true && Installed == true)
968 Cache.MarkInstall(I,false);
969
6c139d6e 970 if (Debug == true)
421c8d10 971 clog << " Holding Back " << I.Name() << " because I can't find " << Start.TargetPkg().Name() << endl;
6c139d6e
AL
972 }
973 else
974 {
975 if (Debug == true)
421c8d10 976 clog << " Removing " << I.Name() << " because I can't find " << Start.TargetPkg().Name() << endl;
648e3cb4
AL
977 if (InOr == false)
978 Cache.MarkDelete(I);
6c139d6e
AL
979 }
980
981 Change = true;
982 Done = true;
983 }
984
421c8d10
AL
985 // Try some more
986 if (InOr == true)
987 continue;
988
6c139d6e
AL
989 if (Done == true)
990 break;
991 }
992
993 // Apply the kill list now
994 if (Cache[I].InstallVer != 0)
648e3cb4 995 {
6c139d6e 996 for (PackageKill *J = KillList; J != LEnd; J++)
6c139d6e 997 {
648e3cb4
AL
998 Change = true;
999 if ((Cache[J->Dep] & pkgDepCache::DepGNow) == 0)
1000 {
b2e465d6
AL
1001 if (J->Dep->Type == pkgCache::Dep::Conflicts ||
1002 J->Dep->Type == pkgCache::Dep::Obsoletes)
648e3cb4
AL
1003 {
1004 if (Debug == true)
1005 clog << " Fixing " << I.Name() << " via remove of " << J->Pkg.Name() << endl;
1006 Cache.MarkDelete(J->Pkg);
1007 }
1008 }
1009 else
6c139d6e
AL
1010 {
1011 if (Debug == true)
648e3cb4
AL
1012 clog << " Fixing " << I.Name() << " via keep of " << J->Pkg.Name() << endl;
1013 Cache.MarkKeep(J->Pkg);
6c139d6e 1014 }
b2e465d6 1015
648e3cb4 1016 if (Counter > 1)
b2e465d6
AL
1017 {
1018 if (Scores[I->ID] > Scores[J->Pkg->ID])
1019 Scores[J->Pkg->ID] = Scores[I->ID];
1020 }
648e3cb4
AL
1021 }
1022 }
1023 }
6c139d6e
AL
1024 }
1025
1026 if (Debug == true)
0a8e3465 1027 clog << "Done" << endl;
b2e465d6 1028
6c139d6e 1029 if (Cache.BrokenCount() != 0)
b5dc9785
AL
1030 {
1031 // See if this is the result of a hold
1032 pkgCache::PkgIterator I = Cache.PkgBegin();
1033 for (;I.end() != true; I++)
1034 {
1035 if (Cache[I].InstBroken() == false)
1036 continue;
1037 if ((Flags[I->ID] & Protected) != Protected)
b2e465d6 1038 return _error->Error(_("Error, pkgProblemResolver::Resolve generated breaks, this may be caused by held packages."));
b5dc9785 1039 }
b2e465d6 1040 return _error->Error(_("Unable to correct problems, you have held broken packages."));
b5dc9785
AL
1041 }
1042
0a8e3465
AL
1043 return true;
1044}
1045 /*}}}*/
1046// ProblemResolver::ResolveByKeep - Resolve problems using keep /*{{{*/
1047// ---------------------------------------------------------------------
1048/* This is the work horse of the soft upgrade routine. It is very gental
1049 in that it does not install or remove any packages. It is assumed that the
1050 system was non-broken previously. */
1051bool pkgProblemResolver::ResolveByKeep()
1052{
b2e465d6 1053 unsigned long Size = Cache.Head().PackageCount;
0a8e3465
AL
1054
1055 if (Debug == true)
1056 clog << "Entering ResolveByKeep" << endl;
1057
1058 MakeScores();
1059
1060 /* We have to order the packages so that the broken fixing pass
1061 operates from highest score to lowest. This prevents problems when
1062 high score packages cause the removal of lower score packages that
1063 would cause the removal of even lower score packages. */
1064 pkgCache::Package **PList = new pkgCache::Package *[Size];
1065 pkgCache::Package **PEnd = PList;
1066 for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++)
1067 *PEnd++ = I;
1068 This = this;
1069 qsort(PList,PEnd - PList,sizeof(*PList),&ScoreSort);
1070
1071 // Consider each broken package
1072 pkgCache::Package **LastStop = 0;
1073 for (pkgCache::Package **K = PList; K != PEnd; K++)
1074 {
1075 pkgCache::PkgIterator I(Cache,*K);
1076
1077 if (Cache[I].InstallVer == 0 || Cache[I].InstBroken() == false)
1078 continue;
1079
1080 /* Keep the package. If this works then great, otherwise we have
b2e465d6 1081 to be significantly more agressive and manipulate its dependencies */
0a8e3465
AL
1082 if ((Flags[I->ID] & Protected) == 0)
1083 {
1084 if (Debug == true)
1085 clog << "Keeping package " << I.Name() << endl;
1086 Cache.MarkKeep(I);
1087 if (Cache[I].InstBroken() == false)
1088 {
b2e465d6 1089 K = PList - 1;
0a8e3465
AL
1090 continue;
1091 }
1092 }
1093
1094 // Isolate the problem dependencies
1095 for (pkgCache::DepIterator D = Cache[I].InstVerIter(Cache).DependsList(); D.end() == false;)
1096 {
1097 // Compute a single dependency element (glob or)
1098 pkgCache::DepIterator Start = D;
1099 pkgCache::DepIterator End = D;
1100 unsigned char State = 0;
1101 for (bool LastOR = true; D.end() == false && LastOR == true; D++)
1102 {
1103 State |= Cache[D];
1104 LastOR = (D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or;
1105 if (LastOR == true)
1106 End = D;
1107 }
1108
1109 // We only worry about critical deps.
1110 if (End.IsCritical() != true)
1111 continue;
1112
1113 // Dep is ok
1114 if ((Cache[End] & pkgDepCache::DepGInstall) == pkgDepCache::DepGInstall)
1115 continue;
1116
1117 // Hm, the group is broken.. I have no idea how to handle this
1118 if (Start != End)
1119 {
1120 clog << "Note, a broken or group was found in " << I.Name() << "." << endl;
1121 if ((Flags[I->ID] & Protected) == 0)
1122 Cache.MarkKeep(I);
1123 break;
1124 }
1125
1126 if (Debug == true)
1127 clog << "Package " << I.Name() << " has broken dep on " << End.TargetPkg().Name() << endl;
1128
1129 // Look at all the possible provides on this package
b2e465d6 1130 SPtrArray<pkgCache::Version *> VList = End.AllTargets();
0a8e3465
AL
1131 for (pkgCache::Version **V = VList; *V != 0; V++)
1132 {
1133 pkgCache::VerIterator Ver(Cache,*V);
1134 pkgCache::PkgIterator Pkg = Ver.ParentPkg();
1135
1136 // It is not keepable
1137 if (Cache[Pkg].InstallVer == 0 ||
1138 Pkg->CurrentVer == 0)
1139 continue;
1140
1141 if ((Flags[I->ID] & Protected) == 0)
1142 {
1143 if (Debug == true)
1144 clog << " Keeping Package " << Pkg.Name() << " due to dep" << endl;
1145 Cache.MarkKeep(Pkg);
1146 }
1147
1148 if (Cache[I].InstBroken() == false)
1149 break;
1150 }
1151
1152 if (Cache[I].InstBroken() == false)
1153 break;
1154 }
1155
1156 if (Cache[I].InstBroken() == true)
1157 continue;
1158
1159 // Restart again.
1160 if (K == LastStop)
1161 return _error->Error("Internal Error, pkgProblemResolver::ResolveByKeep is looping on package %s.",I.Name());
1162 LastStop = K;
b2e465d6 1163 K = PList - 1;
0a8e3465 1164 }
6c139d6e
AL
1165
1166 return true;
1167}
1168 /*}}}*/
3b5421b4
AL
1169// ProblemResolver::InstallProtect - Install all protected packages /*{{{*/
1170// ---------------------------------------------------------------------
1171/* This is used to make sure protected packages are installed */
1172void pkgProblemResolver::InstallProtect()
1173{
1174 for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++)
1175 {
1176 if ((Flags[I->ID] & Protected) == Protected)
1177 {
1178 if ((Flags[I->ID] & ToRemove) == ToRemove)
1179 Cache.MarkDelete(I);
1180 else
1181 Cache.MarkInstall(I,false);
1182 }
1183 }
1184}
1185 /*}}}*/
b2e465d6
AL
1186
1187// PrioSortList - Sort a list of versions by priority /*{{{*/
1188// ---------------------------------------------------------------------
1189/* This is ment to be used in conjunction with AllTargets to get a list
1190 of versions ordered by preference. */
1191static pkgCache *PrioCache;
1192static int PrioComp(const void *A,const void *B)
1193{
1194 pkgCache::VerIterator L(*PrioCache,*(pkgCache::Version **)A);
1195 pkgCache::VerIterator R(*PrioCache,*(pkgCache::Version **)B);
1196
1197 if ((L.ParentPkg()->Flags & pkgCache::Flag::Essential) == pkgCache::Flag::Essential &&
1198 (L.ParentPkg()->Flags & pkgCache::Flag::Essential) != pkgCache::Flag::Essential)
1199 return 1;
1200 if ((L.ParentPkg()->Flags & pkgCache::Flag::Essential) != pkgCache::Flag::Essential &&
1201 (L.ParentPkg()->Flags & pkgCache::Flag::Essential) == pkgCache::Flag::Essential)
1202 return -1;
1203
1204 if (L->Priority != R->Priority)
1205 return L->Priority - R->Priority;
1206 return strcmp(L.ParentPkg().Name(),R.ParentPkg().Name());
1207}
1208void pkgPrioSortList(pkgCache &Cache,pkgCache::Version **List)
1209{
1210 unsigned long Count = 0;
1211 PrioCache = &Cache;
1212 for (pkgCache::Version **I = List; *I != 0; I++)
1213 Count++;
1214 qsort(List,Count,sizeof(*List),PrioComp);
1215}
1216 /*}}}*/