]>
git.saurik.com Git - apt.git/blob - apt-pkg/algorithms.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: algorithms.cc,v 1.12 1998/11/23 07:02:58 jgg Exp $
4 /* ######################################################################
6 Algorithms - A set of misc algorithms
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.
14 ##################################################################### */
16 // Include Files /*{{{*/
18 #pragma implementation "apt-pkg/algorithms.h"
20 #include <apt-pkg/algorithms.h>
21 #include <apt-pkg/error.h>
22 #include <apt-pkg/configuration.h>
26 pkgProblemResolver
*pkgProblemResolver::This
= 0;
28 // Simulate::Simulate - Constructor /*{{{*/
29 // ---------------------------------------------------------------------
31 pkgSimulate::pkgSimulate(pkgDepCache
&Cache
) : pkgPackageManager(Cache
),
34 Flags
= new unsigned char[Cache
.HeaderP
->PackageCount
];
35 memset(Flags
,0,sizeof(*Flags
)*Cache
.HeaderP
->PackageCount
);
38 // Simulate::Install - Simulate unpacking of a package /*{{{*/
39 // ---------------------------------------------------------------------
41 bool pkgSimulate::Install(PkgIterator iPkg
,string
/*File*/)
44 PkgIterator Pkg
= Sim
.FindPkg(iPkg
.Name());
47 clog
<< "Inst " << Pkg
.Name();
48 Sim
.MarkInstall(Pkg
,false);
50 // Look for broken conflicts+predepends.
51 for (PkgIterator I
= Sim
.PkgBegin(); I
.end() == false; I
++)
53 if (Sim
[I
].InstallVer
== 0)
56 for (DepIterator D
= Sim
[I
].InstVerIter(Sim
).DependsList(); D
.end() == false; D
++)
57 if (D
->Type
== pkgCache::Dep::Conflicts
|| D
->Type
== pkgCache::Dep::PreDepends
)
59 if ((Sim
[D
] & pkgDepCache::DepInstall
) == 0)
61 clog
<< " [" << I
.Name() << " on " << D
.TargetPkg().Name() << ']';
62 if (D
->Type
== pkgCache::Dep::Conflicts
)
63 _error
->Error("Fatal, conflicts violated %s",I
.Name());
68 if (Sim
.BrokenCount() != 0)
75 // Simulate::Configure - Simulate configuration of a Package /*{{{*/
76 // ---------------------------------------------------------------------
77 /* This is not an acurate simulation of relatity, we should really not
78 install the package.. For some investigations it may be necessary
80 bool pkgSimulate::Configure(PkgIterator iPkg
)
83 PkgIterator Pkg
= Sim
.FindPkg(iPkg
.Name());
86 // Sim.MarkInstall(Pkg,false);
87 if (Sim
[Pkg
].InstBroken() == true)
89 clog
<< "Conf " << Pkg
.Name() << " broken" << endl
;
93 // Print out each package and the failed dependencies
94 for (pkgCache::DepIterator D
= Sim
[Pkg
].InstVerIter(Sim
).DependsList(); D
.end() == false; D
++)
96 if (Sim
.IsImportantDep(D
) == false ||
97 (Sim
[D
] & pkgDepCache::DepInstall
) != 0)
100 if (D
->Type
== pkgCache::Dep::Conflicts
)
101 clog
<< " Conflicts:" << D
.TargetPkg().Name();
103 clog
<< " Depends:" << D
.TargetPkg().Name();
107 _error
->Error("Conf Broken %s",Pkg
.Name());
110 clog
<< "Conf " << Pkg
.Name();
112 if (Sim
.BrokenCount() != 0)
120 // Simulate::Remove - Simulate the removal of a package /*{{{*/
121 // ---------------------------------------------------------------------
123 bool pkgSimulate::Remove(PkgIterator iPkg
)
125 // Adapt the iterator
126 PkgIterator Pkg
= Sim
.FindPkg(iPkg
.Name());
130 clog
<< "Remv " << Pkg
.Name();
132 if (Sim
.BrokenCount() != 0)
140 // Simulate::ShortBreaks - Print out a short line describing all breaks /*{{{*/
141 // ---------------------------------------------------------------------
143 void pkgSimulate::ShortBreaks()
146 for (PkgIterator I
= Sim
.PkgBegin(); I
.end() == false; I
++)
148 if (Sim
[I
].InstBroken() == true)
150 if (Flags
[I
->ID
] == 0)
151 clog
<< I
.Name() << ' ';
153 clog << I.Name() << "! ";*/
159 // ApplyStatus - Adjust for non-ok packages /*{{{*/
160 // ---------------------------------------------------------------------
161 /* We attempt to change the state of the all packages that have failed
162 installation toward their real state. The ordering code will perform
163 the necessary calculations to deal with the problems. */
164 bool pkgApplyStatus(pkgDepCache
&Cache
)
166 for (pkgCache::PkgIterator I
= Cache
.PkgBegin(); I
.end() == false; I
++)
168 // Only choice for a ReInstReq package is to reinstall
169 if (I
->InstState
== pkgCache::State::ReInstReq
||
170 I
->InstState
== pkgCache::State::HoldReInstReq
)
176 switch (I
->CurrentState
)
178 // This means installation failed somehow
179 case pkgCache::State::UnPacked
:
180 case pkgCache::State::HalfConfigured
:
184 // This means removal failed
185 case pkgCache::State::HalfInstalled
:
190 if (I
->InstState
!= pkgCache::State::Ok
)
191 return _error
->Error("The package %s is not ok and I "
192 "don't know how to fix it!",I
.Name());
198 // FixBroken - Fix broken packages /*{{{*/
199 // ---------------------------------------------------------------------
200 /* This autoinstalls every broken package and then runs the problem resolver
202 bool pkgFixBroken(pkgDepCache
&Cache
)
204 // Auto upgrade all broken packages
205 for (pkgCache::PkgIterator I
= Cache
.PkgBegin(); I
.end() == false; I
++)
206 if (Cache
[I
].NowBroken() == true)
207 Cache
.MarkInstall(I
,true);
209 /* Fix packages that are in a NeedArchive state but don't have a
210 downloadable install version */
211 for (pkgCache::PkgIterator I
= Cache
.PkgBegin(); I
.end() == false; I
++)
213 if (I
.State() != pkgCache::PkgIterator::NeedsUnpack
||
214 Cache
[I
].Delete() == true)
217 if (Cache
[I
].InstVerIter(Cache
).Downloadable() == false)
220 Cache
.MarkInstall(I
,true);
223 pkgProblemResolver
Fix(Cache
);
224 return Fix
.Resolve(true);
227 // DistUpgrade - Distribution upgrade /*{{{*/
228 // ---------------------------------------------------------------------
229 /* This autoinstalls every package and then force installs every
230 pre-existing package. This creates the initial set of conditions which
231 most likely contain problems because too many things were installed.
233 The problem resolver is used to resolve the problems.
235 bool pkgDistUpgrade(pkgDepCache
&Cache
)
237 /* Auto upgrade all installed packages, this provides the basis
238 for the installation */
239 for (pkgCache::PkgIterator I
= Cache
.PkgBegin(); I
.end() == false; I
++)
240 if (I
->CurrentVer
!= 0)
241 Cache
.MarkInstall(I
,true);
243 /* Now, auto upgrade all essential packages - this ensures that
244 the essential packages are present and working */
245 for (pkgCache::PkgIterator I
= Cache
.PkgBegin(); I
.end() == false; I
++)
246 if ((I
->Flags
& pkgCache::Flag::Essential
) == pkgCache::Flag::Essential
)
247 Cache
.MarkInstall(I
,true);
249 /* We do it again over all previously installed packages to force
250 conflict resolution on them all. */
251 for (pkgCache::PkgIterator I
= Cache
.PkgBegin(); I
.end() == false; I
++)
252 if (I
->CurrentVer
!= 0)
253 Cache
.MarkInstall(I
,false);
255 pkgProblemResolver
Fix(Cache
);
257 // Hold back held packages.
258 if (_config
->FindB("APT::Ingore-Hold",false) == false)
260 for (pkgCache::PkgIterator I
= Cache
.PkgBegin(); I
.end() == false; I
++)
262 if (I
->SelectedState
== pkgCache::State::Hold
)
270 return Fix
.Resolve();
273 // AllUpgrade - Upgrade as many packages as possible /*{{{*/
274 // ---------------------------------------------------------------------
275 /* Right now the system must be consistent before this can be called.
276 It also will not change packages marked for install, it only tries
277 to install packages not marked for install */
278 bool pkgAllUpgrade(pkgDepCache
&Cache
)
280 pkgProblemResolver
Fix(Cache
);
282 if (Cache
.BrokenCount() != 0)
285 // Upgrade all installed packages
286 for (pkgCache::PkgIterator I
= Cache
.PkgBegin(); I
.end() == false; I
++)
288 if (Cache
[I
].Install() == true)
291 if (_config
->FindB("APT::Ingore-Hold",false) == false)
292 if (I
->SelectedState
== pkgCache::State::Hold
)
295 if (I
->CurrentVer
!= 0 && Cache
[I
].InstallVer
!= 0)
296 Cache
.MarkInstall(I
,false);
299 return Fix
.ResolveByKeep();
302 // MinimizeUpgrade - Minimizes the set of packages to be upgraded /*{{{*/
303 // ---------------------------------------------------------------------
304 /* This simply goes over the entire set of packages and tries to keep
305 each package marked for upgrade. If a conflict is generated then
306 the package is restored. */
307 bool pkgMinimizeUpgrade(pkgDepCache
&Cache
)
309 if (Cache
.BrokenCount() != 0)
312 // We loop indefinately to get the minimal set size.
317 for (pkgCache::PkgIterator I
= Cache
.PkgBegin(); I
.end() == false; I
++)
320 if (Cache
[I
].Upgrade() == false || Cache
[I
].NewInstall() == true)
323 // Keep it and see if that is OK
325 if (Cache
.BrokenCount() != 0)
326 Cache
.MarkInstall(I
,false);
331 while (Change
== true);
333 if (Cache
.BrokenCount() != 0)
334 return _error
->Error("Internal Error in pkgMinimizeUpgrade");
340 // ProblemResolver::pkgProblemResolver - Constructor /*{{{*/
341 // ---------------------------------------------------------------------
343 pkgProblemResolver::pkgProblemResolver(pkgDepCache
&Cache
) : Cache(Cache
)
346 unsigned long Size
= Cache
.HeaderP
->PackageCount
;
347 Scores
= new signed short[Size
];
348 Flags
= new unsigned char[Size
];
349 memset(Flags
,0,sizeof(*Flags
)*Size
);
351 // Set debug to true to see its decision logic
352 Debug
= _config
->FindB("Debug::pkgProblemResolver",false);
355 // ProblemResolver::ScoreSort - Sort the list by score /*{{{*/
356 // ---------------------------------------------------------------------
358 int pkgProblemResolver::ScoreSort(const void *a
,const void *b
)
360 Package
const **A
= (Package
const **)a
;
361 Package
const **B
= (Package
const **)b
;
362 if (This
->Scores
[(*A
)->ID
] > This
->Scores
[(*B
)->ID
])
364 if (This
->Scores
[(*A
)->ID
] < This
->Scores
[(*B
)->ID
])
369 // ProblemResolver::MakeScores - Make the score table /*{{{*/
370 // ---------------------------------------------------------------------
372 void pkgProblemResolver::MakeScores()
374 unsigned long Size
= Cache
.HeaderP
->PackageCount
;
375 memset(Scores
,0,sizeof(*Scores
)*Size
);
377 // Generate the base scores for a package based on its properties
378 for (pkgCache::PkgIterator I
= Cache
.PkgBegin(); I
.end() == false; I
++)
380 if (Cache
[I
].InstallVer
== 0)
383 signed short &Score
= Scores
[I
->ID
];
385 /* This is arbitary, it should be high enough to elevate an
386 essantial package above most other packages but low enough
387 to allow an obsolete essential packages to be removed by
388 a conflicts on a powerfull normal package (ie libc6) */
389 if ((I
->Flags
& pkgCache::Flag::Essential
) == pkgCache::Flag::Essential
)
392 // We transform the priority
393 // Important Required Standard Optional Extra
394 signed short PrioMap
[] = {0,3,2,1,-1,-2};
395 if (Cache
[I
].InstVerIter(Cache
)->Priority
<= 5)
396 Score
+= PrioMap
[Cache
[I
].InstVerIter(Cache
)->Priority
];
398 /* This helps to fix oddball problems with conflicting packages
399 on the same level. We enhance the score of installed packages */
400 if (I
->CurrentVer
!= 0)
404 // Now that we have the base scores we go and propogate dependencies
405 for (pkgCache::PkgIterator I
= Cache
.PkgBegin(); I
.end() == false; I
++)
407 if (Cache
[I
].InstallVer
== 0)
410 for (pkgCache::DepIterator D
= Cache
[I
].InstVerIter(Cache
).DependsList(); D
.end() == false; D
++)
412 if (D
->Type
== pkgCache::Dep::Depends
|| D
->Type
== pkgCache::Dep::PreDepends
)
413 Scores
[D
.TargetPkg()->ID
]++;
417 // Copy the scores to advoid additive looping
418 signed short *OldScores
= new signed short[Size
];
419 memcpy(OldScores
,Scores
,sizeof(*Scores
)*Size
);
421 /* Now we cause 1 level of dependency inheritance, that is we add the
422 score of the packages that depend on the target Package. This
423 fortifies high scoring packages */
424 for (pkgCache::PkgIterator I
= Cache
.PkgBegin(); I
.end() == false; I
++)
426 if (Cache
[I
].InstallVer
== 0)
429 for (pkgCache::DepIterator D
= I
.RevDependsList(); D
.end() == false; D
++)
431 // Only do it for the install version
432 if ((pkgCache::Version
*)D
.ParentVer() != Cache
[D
.ParentPkg()].InstallVer
||
433 (D
->Type
!= pkgCache::Dep::Depends
&& D
->Type
!= pkgCache::Dep::PreDepends
))
436 Scores
[I
->ID
] += abs(OldScores
[D
.ParentPkg()->ID
]);
440 /* Now we propogate along provides. This makes the packages that
441 provide important packages extremely important */
442 for (pkgCache::PkgIterator I
= Cache
.PkgBegin(); I
.end() == false; I
++)
444 for (pkgCache::PrvIterator P
= I
.ProvidesList(); P
.end() == false; P
++)
446 // Only do it once per package
447 if ((pkgCache::Version
*)P
.OwnerVer() != Cache
[P
.OwnerPkg()].InstallVer
)
449 Scores
[P
.OwnerPkg()->ID
] += abs(Scores
[I
->ID
] - OldScores
[I
->ID
]);
453 /* Protected things are pushed really high up. This number should put them
454 ahead of everything */
455 for (pkgCache::PkgIterator I
= Cache
.PkgBegin(); I
.end() == false; I
++)
456 if ((Flags
[I
->ID
] & Protected
) != 0)
457 Scores
[I
->ID
] += 10000;
462 // ProblemResolver::DoUpgrade - Attempt to upgrade this package /*{{{*/
463 // ---------------------------------------------------------------------
464 /* This goes through and tries to reinstall packages to make this package
466 bool pkgProblemResolver::DoUpgrade(pkgCache::PkgIterator Pkg
)
468 if ((Flags
[Pkg
->ID
] & Upgradable
) == 0 || Cache
[Pkg
].Upgradable() == false)
471 Flags
[Pkg
->ID
] &= ~Upgradable
;
473 bool WasKept
= Cache
[Pkg
].Keep();
474 Cache
.MarkInstall(Pkg
,false);
476 // This must be a virtual package or something like that.
477 if (Cache
[Pkg
].InstVerIter(Cache
).end() == true)
480 // Isolate the problem dependency
482 for (pkgCache::DepIterator D
= Cache
[Pkg
].InstVerIter(Cache
).DependsList(); D
.end() == false;)
484 // Compute a single dependency element (glob or)
485 pkgCache::DepIterator Start
= D
;
486 pkgCache::DepIterator End
= D
;
487 unsigned char State
= 0;
488 for (bool LastOR
= true; D
.end() == false && LastOR
== true; D
++)
491 LastOR
= (D
->CompareOp
& pkgCache::Dep::Or
) == pkgCache::Dep::Or
;
496 // We only worry about critical deps.
497 if (End
.IsCritical() != true)
501 if ((Cache
[End
] & pkgDepCache::DepGInstall
) == pkgDepCache::DepGInstall
)
504 // Hm, the group is broken.. I have no idea how to handle this
507 clog
<< "Note, a broken or group was found in " << Pkg
.Name() << "." << endl
;
512 // Do not change protected packages
513 PkgIterator P
= Start
.SmartTargetPkg();
514 if ((Flags
[P
->ID
] & Protected
) == Protected
)
517 clog
<< " Reinet Failed because of protected " << P
.Name() << endl
;
522 // Upgrade the package if the candidate version will fix the problem.
523 if ((Cache
[Start
] & pkgDepCache::DepCVer
) == pkgDepCache::DepCVer
)
525 if (DoUpgrade(P
) == false)
528 clog
<< " Reinst Failed because of " << P
.Name() << endl
;
535 /* We let the algorithm deal with conflicts on its next iteration,
536 it is much smarter than us */
537 if (End
->Type
== pkgCache::Dep::Conflicts
)
541 clog
<< " Reinst Failed early because of " << Start
.TargetPkg().Name() << endl
;
547 // Undo our operations - it might be smart to undo everything this did..
553 Cache
.MarkDelete(Pkg
);
558 clog
<< " Re-Instated " << Pkg
.Name() << endl
;
562 // ProblemResolver::Resolve - Run the resolution pass /*{{{*/
563 // ---------------------------------------------------------------------
564 /* This routines works by calculating a score for each package. The score
565 is derived by considering the package's priority and all reverse
566 dependents giving an integer that reflects the amount of breakage that
567 adjusting the package will inflict.
569 It goes from highest score to lowest and corrects all of the breaks by
570 keeping or removing the dependant packages. If that fails then it removes
571 the package itself and goes on. The routine should be able to intelligently
572 go from any broken state to a fixed state.
574 The BrokenFix flag enables a mode where the algorithm tries to
575 upgrade packages to advoid problems. */
576 bool pkgProblemResolver::Resolve(bool BrokenFix
)
578 unsigned long Size
= Cache
.HeaderP
->PackageCount
;
580 // Record which packages are marked for install
585 for (pkgCache::PkgIterator I
= Cache
.PkgBegin(); I
.end() == false; I
++)
587 if (Cache
[I
].Install() == true)
588 Flags
[I
->ID
] |= PreInstalled
;
591 if (Cache
[I
].InstBroken() == true && BrokenFix
== true)
593 Cache
.MarkInstall(I
,false);
594 if (Cache
[I
].Install() == true)
598 Flags
[I
->ID
] &= ~PreInstalled
;
600 Flags
[I
->ID
] |= Upgradable
;
603 while (Again
== true);
606 clog
<< "Starting" << endl
;
610 /* We have to order the packages so that the broken fixing pass
611 operates from highest score to lowest. This prevents problems when
612 high score packages cause the removal of lower score packages that
613 would cause the removal of even lower score packages. */
614 pkgCache::Package
**PList
= new pkgCache::Package
*[Size
];
615 pkgCache::Package
**PEnd
= PList
;
616 for (pkgCache::PkgIterator I
= Cache
.PkgBegin(); I
.end() == false; I
++)
619 qsort(PList
,PEnd
- PList
,sizeof(*PList
),&ScoreSort
);
621 /* for (pkgCache::Package **K = PList; K != PEnd; K++)
622 if (Scores[(*K)->ID] != 0)
624 pkgCache::PkgIterator Pkg(Cache,*K);
625 clog << Scores[(*K)->ID] << ' ' << Pkg.Name() <<
626 ' ' << (pkgCache::Version *)Pkg.CurrentVer() << ' ' <<
627 Cache[Pkg].InstallVer << ' ' << Cache[Pkg].CandidateVer << endl;
631 clog
<< "Starting 2" << endl
;
633 /* Now consider all broken packages. For each broken package we either
634 remove the package or fix it's problem. We do this once, it should
635 not be possible for a loop to form (that is a < b < c and fixing b by
636 changing a breaks c) */
638 for (int Counter
= 0; Counter
!= 10 && Change
== true; Counter
++)
641 for (pkgCache::Package
**K
= PList
; K
!= PEnd
; K
++)
643 pkgCache::PkgIterator
I(Cache
,*K
);
645 /* We attempt to install this and see if any breaks result,
646 this takes care of some strange cases */
647 if (Cache
[I
].CandidateVer
!= Cache
[I
].InstallVer
&&
648 I
->CurrentVer
!= 0 && Cache
[I
].InstallVer
!= 0 &&
649 (Flags
[I
->ID
] & PreInstalled
) != 0 &&
650 (Flags
[I
->ID
] & Protected
) == 0 &&
651 (Flags
[I
->ID
] & ReInstateTried
) == 0)
654 clog
<< " Try to Re-Instate " << I
.Name() << endl
;
655 unsigned long OldBreaks
= Cache
.BrokenCount();
656 pkgCache::Version
*OldVer
= Cache
[I
].InstallVer
;
657 Flags
[I
->ID
] &= ReInstateTried
;
659 Cache
.MarkInstall(I
,false);
660 if (Cache
[I
].InstBroken() == true ||
661 OldBreaks
< Cache
.BrokenCount())
670 clog
<< "Re-Instated " << I
.Name() << " (" << OldBreaks
<< " vs " << Cache
.BrokenCount() << ')' << endl
;
673 if (Cache
[I
].InstallVer
== 0 || Cache
[I
].InstBroken() == false)
676 // Isolate the problem dependency
677 PackageKill KillList
[100];
678 PackageKill
*LEnd
= KillList
;
679 for (pkgCache::DepIterator D
= Cache
[I
].InstVerIter(Cache
).DependsList(); D
.end() == false;)
681 // Compute a single dependency element (glob or)
682 pkgCache::DepIterator Start
;
683 pkgCache::DepIterator End
;
686 // We only worry about critical deps.
687 if (End
.IsCritical() != true)
691 if ((Cache
[End
] & pkgDepCache::DepGInstall
) == pkgDepCache::DepGInstall
)
694 // Hm, the group is broken.. I have no idea how to handle this
697 clog
<< "Note, a broken or group was found in " << I
.Name() << "." << endl
;
703 clog
<< "Package " << I
.Name() << " has broken dep on " << End
.TargetPkg().Name() << endl
;
705 /* Look across the version list. If there are no possible
706 targets then we keep the package and bail. This is necessary
707 if a package has a dep on another package that cant be found */
708 pkgCache::Version
**VList
= End
.AllTargets();
709 if (*VList
== 0 && (Flags
[I
->ID
] & Protected
) != Protected
&&
710 End
->Type
!= pkgCache::Dep::Conflicts
&&
711 Cache
[I
].NowBroken() == false)
719 for (pkgCache::Version
**V
= VList
; *V
!= 0; V
++)
721 pkgCache::VerIterator
Ver(Cache
,*V
);
722 pkgCache::PkgIterator Pkg
= Ver
.ParentPkg();
725 clog
<< " Considering " << Pkg
.Name() << ' ' << (int)Scores
[Pkg
->ID
] <<
726 " as a solution to " << I
.Name() << ' ' << (int)Scores
[I
->ID
] << endl
;
727 if (Scores
[I
->ID
] <= Scores
[Pkg
->ID
] ||
728 ((Cache
[End
] & pkgDepCache::DepGNow
) == 0 &&
729 End
->Type
!= pkgCache::Dep::Conflicts
))
731 if ((Flags
[I
->ID
] & Protected
) == Protected
)
734 // See if a keep will do
736 if (Cache
[I
].InstBroken() == false)
739 clog
<< " Holding Back " << I
.Name() << " rather than change " << End
.TargetPkg().Name() << endl
;
743 if (BrokenFix
== false || DoUpgrade(I
) == false)
746 clog
<< " Removing " << I
.Name() << " rather than change " << End
.TargetPkg().Name() << endl
;
749 Scores
[I
->ID
] = Scores
[Pkg
->ID
];
759 // Skip this if it is protected
760 if ((Flags
[Pkg
->ID
] & Protected
) != 0)
767 if (End
->Type
!= pkgCache::Dep::Conflicts
)
772 // Hm, nothing can possibly satisify this dep. Nuke it.
773 if (VList
[0] == 0 && End
->Type
!= pkgCache::Dep::Conflicts
&&
774 (Flags
[I
->ID
] & Protected
) != Protected
)
777 if (Cache
[I
].InstBroken() == false)
780 clog
<< " Holding Back " << I
.Name() << " because I can't find " << End
.TargetPkg().Name() << endl
;
785 clog
<< " Removing " << I
.Name() << " because I can't find " << End
.TargetPkg().Name() << endl
;
798 // Apply the kill list now
799 if (Cache
[I
].InstallVer
!= 0)
800 for (PackageKill
*J
= KillList
; J
!= LEnd
; J
++)
803 if ((Cache
[J
->Dep
] & pkgDepCache::DepGNow
) == 0)
805 if (J
->Dep
->Type
== pkgCache::Dep::Conflicts
)
808 clog
<< " Fixing " << I
.Name() << " via remove of " << J
->Pkg
.Name() << endl
;
809 Cache
.MarkDelete(J
->Pkg
);
815 clog
<< " Fixing " << I
.Name() << " via keep of " << J
->Pkg
.Name() << endl
;
816 Cache
.MarkKeep(J
->Pkg
);
820 Scores
[J
->Pkg
->ID
] = Scores
[I
->ID
];
826 clog
<< "Done" << endl
;
831 if (Cache
.BrokenCount() != 0)
832 return _error
->Error("Internal error, pkgProblemResolver::Resolve generated breaks.");
837 // ProblemResolver::ResolveByKeep - Resolve problems using keep /*{{{*/
838 // ---------------------------------------------------------------------
839 /* This is the work horse of the soft upgrade routine. It is very gental
840 in that it does not install or remove any packages. It is assumed that the
841 system was non-broken previously. */
842 bool pkgProblemResolver::ResolveByKeep()
844 unsigned long Size
= Cache
.HeaderP
->PackageCount
;
847 clog
<< "Entering ResolveByKeep" << endl
;
851 /* We have to order the packages so that the broken fixing pass
852 operates from highest score to lowest. This prevents problems when
853 high score packages cause the removal of lower score packages that
854 would cause the removal of even lower score packages. */
855 pkgCache::Package
**PList
= new pkgCache::Package
*[Size
];
856 pkgCache::Package
**PEnd
= PList
;
857 for (pkgCache::PkgIterator I
= Cache
.PkgBegin(); I
.end() == false; I
++)
860 qsort(PList
,PEnd
- PList
,sizeof(*PList
),&ScoreSort
);
862 // Consider each broken package
863 pkgCache::Package
**LastStop
= 0;
864 for (pkgCache::Package
**K
= PList
; K
!= PEnd
; K
++)
866 pkgCache::PkgIterator
I(Cache
,*K
);
868 if (Cache
[I
].InstallVer
== 0 || Cache
[I
].InstBroken() == false)
871 /* Keep the package. If this works then great, otherwise we have
872 to be significantly more agressive and manipulate its dependencies */
873 if ((Flags
[I
->ID
] & Protected
) == 0)
876 clog
<< "Keeping package " << I
.Name() << endl
;
878 if (Cache
[I
].InstBroken() == false)
885 // Isolate the problem dependencies
886 for (pkgCache::DepIterator D
= Cache
[I
].InstVerIter(Cache
).DependsList(); D
.end() == false;)
888 // Compute a single dependency element (glob or)
889 pkgCache::DepIterator Start
= D
;
890 pkgCache::DepIterator End
= D
;
891 unsigned char State
= 0;
892 for (bool LastOR
= true; D
.end() == false && LastOR
== true; D
++)
895 LastOR
= (D
->CompareOp
& pkgCache::Dep::Or
) == pkgCache::Dep::Or
;
900 // We only worry about critical deps.
901 if (End
.IsCritical() != true)
905 if ((Cache
[End
] & pkgDepCache::DepGInstall
) == pkgDepCache::DepGInstall
)
908 // Hm, the group is broken.. I have no idea how to handle this
911 clog
<< "Note, a broken or group was found in " << I
.Name() << "." << endl
;
912 if ((Flags
[I
->ID
] & Protected
) == 0)
918 clog
<< "Package " << I
.Name() << " has broken dep on " << End
.TargetPkg().Name() << endl
;
920 // Look at all the possible provides on this package
921 pkgCache::Version
**VList
= End
.AllTargets();
922 for (pkgCache::Version
**V
= VList
; *V
!= 0; V
++)
924 pkgCache::VerIterator
Ver(Cache
,*V
);
925 pkgCache::PkgIterator Pkg
= Ver
.ParentPkg();
927 // It is not keepable
928 if (Cache
[Pkg
].InstallVer
== 0 ||
929 Pkg
->CurrentVer
== 0)
932 if ((Flags
[I
->ID
] & Protected
) == 0)
935 clog
<< " Keeping Package " << Pkg
.Name() << " due to dep" << endl
;
939 if (Cache
[I
].InstBroken() == false)
943 if (Cache
[I
].InstBroken() == false)
947 if (Cache
[I
].InstBroken() == true)
952 return _error
->Error("Internal Error, pkgProblemResolver::ResolveByKeep is looping on package %s.",I
.Name());
960 // ProblemResolver::InstallProtect - Install all protected packages /*{{{*/
961 // ---------------------------------------------------------------------
962 /* This is used to make sure protected packages are installed */
963 void pkgProblemResolver::InstallProtect()
965 for (pkgCache::PkgIterator I
= Cache
.PkgBegin(); I
.end() == false; I
++)
967 if ((Flags
[I
->ID
] & Protected
) == Protected
)
969 if ((Flags
[I
->ID
] & ToRemove
) == ToRemove
)
972 Cache
.MarkInstall(I
,false);