]>
git.saurik.com Git - apt.git/blob - apt-pkg/orderlist.cc
616714e2927f4cb4a674be6e9cfdba802b3f5b37
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: orderlist.cc,v 1.14 2001/05/07 05:49:43 jgg Exp $
4 /* ######################################################################
6 Order List - Represents and Manipulates an ordered list of packages.
8 A list of packages can be ordered by a number of conflicting criteria
9 each given a specific priority. Each package also has a set of flags
10 indicating some useful things about it that are derived in the
11 course of sorting. The pkgPackageManager class uses this class for
12 all of it's installation ordering needs.
14 This is a modified version of Manoj's Routine B. It consists of four
15 independent ordering algorithms that can be applied at for different
16 points in the ordering. By appling progressivly fewer ordering
17 operations it is possible to give each consideration it's own
18 priority and create an order that satisfies the lowest applicable
21 The rules for unpacking ordering are:
22 1) Unpacking ignores Depends: on all packages
23 2) Unpacking requires Conflicts: on -ALL- packages to be satisfied
24 3) Unpacking requires PreDepends: on this package only to be satisfied
25 4) Removing requires that no packages depend on the package to be
28 And the rule for configuration ordering is:
29 1) Configuring requires that the Depends: of the package be satisfied
30 Conflicts+PreDepends are ignored because unpacking says they are
31 already correct [exageration, it does check but we need not be
34 And some features that are valuable for unpacking ordering.
35 f1) Unpacking a new package should advoid breaking dependencies of
37 f2) Removal should not require a force, corrolory of f1
38 f3) Unpacking should order by depends rather than fall back to random
41 Each of the features can be enabled in the sorting routine at an
42 arbitary priority to give quite abit of control over the final unpacking
45 The rules listed above may never be violated and are called Critical.
46 When a critical rule is violated then a loop condition is recorded
47 and will have to be delt with in the caller.
49 The ordering keeps two lists, the main list and the 'After List'. The
50 purpose of the after list is to allow packages to be delayed. This is done
51 by setting the after flag on the package. Any package which requires this
52 package to be ordered before will inherit the after flag and so on. This
53 is used for CD swap ordering where all packages on a second CD have the
54 after flag set. This forces them and all their dependents to be ordered
57 There are complications in this algorithm when presented with cycles.
58 For all known practical cases it works, all cases where it doesn't work
59 is fixable by tweaking the package descriptions. However, it should be
60 possible to impove this further to make some better choices when
61 presented with cycles.
63 ##################################################################### */
65 // Include Files /*{{{*/
66 #include <apt-pkg/orderlist.h>
67 #include <apt-pkg/depcache.h>
68 #include <apt-pkg/error.h>
69 #include <apt-pkg/version.h>
70 #include <apt-pkg/sptr.h>
71 #include <apt-pkg/configuration.h>
78 pkgOrderList
*pkgOrderList::Me
= 0;
80 // OrderList::pkgOrderList - Constructor /*{{{*/
81 // ---------------------------------------------------------------------
83 pkgOrderList::pkgOrderList(pkgDepCache
*pCache
) : Cache(*pCache
)
91 Debug
= _config
->FindB("Debug::pkgOrderList",false);
93 /* Construct the arrays, egcs 1.0.1 bug requires the package count
95 unsigned long Size
= Cache
.Head().PackageCount
;
96 Flags
= new unsigned short[Size
];
97 End
= List
= new Package
*[Size
];
98 memset(Flags
,0,sizeof(*Flags
)*Size
);
101 // OrderList::~pkgOrderList - Destructor /*{{{*/
102 // ---------------------------------------------------------------------
104 pkgOrderList::~pkgOrderList()
110 // OrderList::IsMissing - Check if a file is missing /*{{{*/
111 // ---------------------------------------------------------------------
113 bool pkgOrderList::IsMissing(PkgIterator Pkg
)
115 // Skip packages to erase
116 if (Cache
[Pkg
].Delete() == true)
119 // Skip Packages that need configure only.
120 if (Pkg
.State() == pkgCache::PkgIterator::NeedsConfigure
&&
121 Cache
[Pkg
].Keep() == true)
127 if (FileList
[Pkg
->ID
].empty() == false)
133 // OrderList::DoRun - Does an order run /*{{{*/
134 // ---------------------------------------------------------------------
135 /* The caller is expeted to have setup the desired probe state */
136 bool pkgOrderList::DoRun()
139 unsigned long Size
= Cache
.Head().PackageCount
;
140 SPtrArray
<Package
*> NList
= new Package
*[Size
];
141 SPtrArray
<Package
*> AfterList
= new Package
*[Size
];
142 AfterEnd
= AfterList
;
145 WipeFlags(Added
| AddPending
| Loop
| InList
);
147 for (iterator I
= List
; I
!= End
; I
++)
150 // Rebuild the main list into the temp list.
151 iterator OldEnd
= End
;
153 for (iterator I
= List
; I
!= OldEnd
; I
++)
154 if (VisitNode(PkgIterator(Cache
,*I
)) == false)
160 // Copy the after list to the end of the main list
161 for (Package
**I
= AfterList
; I
!= AfterEnd
; I
++)
164 // Swap the main list to the new list
166 List
= NList
.UnGuard();
170 // OrderList::OrderCritical - Perform critical unpacking ordering /*{{{*/
171 // ---------------------------------------------------------------------
172 /* This performs predepends and immediate configuration ordering only.
173 This is termed critical unpacking ordering. Any loops that form are
174 fatal and indicate that the packages cannot be installed. */
175 bool pkgOrderList::OrderCritical()
179 Primary
= &pkgOrderList::DepUnPackPre
;
187 qsort(List
,End
- List
,sizeof(*List
),&OrderCompareB
);
189 if (DoRun() == false)
193 return _error
->Error("Fatal, predepends looping detected");
197 // OrderList::OrderUnpack - Perform complete unpacking ordering /*{{{*/
198 // ---------------------------------------------------------------------
199 /* This performs complete unpacking ordering and creates an order that is
200 suitable for unpacking */
201 bool pkgOrderList::OrderUnpack(string
*FileList
)
203 this->FileList
= FileList
;
205 // Setup the after flags
210 // Set the inlist flag
211 for (iterator I
= List
; I
!= End
; I
++)
213 PkgIterator
P(Cache
,*I
);
214 if (IsMissing(P
) == true && IsNow(P
) == true)
219 Primary
= &pkgOrderList::DepUnPackCrit
;
220 Secondary
= &pkgOrderList::DepConfigure
;
221 RevDepends
= &pkgOrderList::DepUnPackDep
;
222 Remove
= &pkgOrderList::DepRemove
;
227 qsort(List
,End
- List
,sizeof(*List
),&OrderCompareA
);
230 clog
<< "** Pass A" << endl
;
231 if (DoRun() == false)
235 clog
<< "** Pass B" << endl
;
237 if (DoRun() == false)
241 clog
<< "** Pass C" << endl
;
244 Remove
= 0; // Otherwise the libreadline remove problem occures
245 if (DoRun() == false)
249 clog
<< "** Pass D" << endl
;
251 Primary
= &pkgOrderList::DepUnPackPre
;
252 if (DoRun() == false)
257 clog
<< "** Unpack ordering done" << endl
;
259 for (iterator I
= List
; I
!= End
; I
++)
261 PkgIterator
P(Cache
,*I
);
262 if (IsNow(P
) == true)
263 clog
<< P
.Name() << ' ' << IsMissing(P
) << ',' << IsFlag(P
,After
) << endl
;
270 // OrderList::OrderConfigure - Perform configuration ordering /*{{{*/
271 // ---------------------------------------------------------------------
272 /* This orders by depends only and produces an order which is suitable
274 bool pkgOrderList::OrderConfigure()
277 Primary
= &pkgOrderList::DepConfigure
;
286 // OrderList::Score - Score the package for sorting /*{{{*/
287 // ---------------------------------------------------------------------
288 /* Higher scores order earlier */
289 int pkgOrderList::Score(PkgIterator Pkg
)
291 // Removal is always done first
292 if (Cache
[Pkg
].Delete() == true)
295 // This should never happen..
296 if (Cache
[Pkg
].InstVerIter(Cache
).end() == true)
300 if ((Pkg
->Flags
& pkgCache::Flag::Essential
) == pkgCache::Flag::Essential
)
303 if (IsFlag(Pkg
,Immediate
) == true)
306 for (DepIterator D
= Cache
[Pkg
].InstVerIter(Cache
).DependsList();
307 D
.end() == false; D
++)
308 if (D
->Type
== pkgCache::Dep::PreDepends
)
314 // Important Required Standard Optional Extra
315 signed short PrioMap
[] = {0,5,4,3,1,0};
316 if (Cache
[Pkg
].InstVerIter(Cache
)->Priority
<= 5)
317 Score
+= PrioMap
[Cache
[Pkg
].InstVerIter(Cache
)->Priority
];
321 // OrderList::FileCmp - Compare by package file /*{{{*/
322 // ---------------------------------------------------------------------
323 /* This compares by the package file that the install version is in. */
324 int pkgOrderList::FileCmp(PkgIterator A
,PkgIterator B
)
326 if (Cache
[A
].Delete() == true && Cache
[B
].Delete() == true)
328 if (Cache
[A
].Delete() == true)
330 if (Cache
[B
].Delete() == true)
333 if (Cache
[A
].InstVerIter(Cache
).FileList().end() == true)
335 if (Cache
[B
].InstVerIter(Cache
).FileList().end() == true)
338 pkgCache::PackageFile
*FA
= Cache
[A
].InstVerIter(Cache
).FileList().File();
339 pkgCache::PackageFile
*FB
= Cache
[B
].InstVerIter(Cache
).FileList().File();
347 // BoolCompare - Comparison function for two booleans /*{{{*/
348 // ---------------------------------------------------------------------
350 static int BoolCompare(bool A
,bool B
)
359 // OrderList::OrderCompareA - Order the installation by op /*{{{*/
360 // ---------------------------------------------------------------------
361 /* This provides a first-pass sort of the list and gives a decent starting
362 point for further complete ordering. It is used by OrderUnpack only */
363 int pkgOrderList::OrderCompareA(const void *a
, const void *b
)
365 PkgIterator
A(Me
->Cache
,*(Package
**)a
);
366 PkgIterator
B(Me
->Cache
,*(Package
**)b
);
368 // We order packages with a set state toward the front
370 if ((Res
= BoolCompare(Me
->IsNow(A
),Me
->IsNow(B
))) != 0)
373 // We order missing files to toward the end
374 /* if (Me->FileList != 0)
376 if ((Res = BoolCompare(Me->IsMissing(A),
377 Me->IsMissing(B))) != 0)
381 if (A
.State() != pkgCache::PkgIterator::NeedsNothing
&&
382 B
.State() == pkgCache::PkgIterator::NeedsNothing
)
385 if (A
.State() == pkgCache::PkgIterator::NeedsNothing
&&
386 B
.State() != pkgCache::PkgIterator::NeedsNothing
)
389 int ScoreA
= Me
->Score(A
);
390 int ScoreB
= Me
->Score(B
);
397 return strcmp(A
.Name(),B
.Name());
400 // OrderList::OrderCompareB - Order the installation by source /*{{{*/
401 // ---------------------------------------------------------------------
402 /* This orders by installation source. This is useful to handle
403 inter-source breaks */
404 int pkgOrderList::OrderCompareB(const void *a
, const void *b
)
406 PkgIterator
A(Me
->Cache
,*(Package
**)a
);
407 PkgIterator
B(Me
->Cache
,*(Package
**)b
);
409 if (A
.State() != pkgCache::PkgIterator::NeedsNothing
&&
410 B
.State() == pkgCache::PkgIterator::NeedsNothing
)
413 if (A
.State() == pkgCache::PkgIterator::NeedsNothing
&&
414 B
.State() != pkgCache::PkgIterator::NeedsNothing
)
417 int F
= Me
->FileCmp(A
,B
);
425 int ScoreA
= Me
->Score(A
);
426 int ScoreB
= Me
->Score(B
);
433 return strcmp(A
.Name(),B
.Name());
437 // OrderList::VisitDeps - Visit forward install dependencies /*{{{*/
438 // ---------------------------------------------------------------------
439 /* This calls the dependency function for the normal forwards dependencies
441 bool pkgOrderList::VisitDeps(DepFunc F
,PkgIterator Pkg
)
443 if (F
== 0 || Pkg
.end() == true || Cache
[Pkg
].InstallVer
== 0)
446 return (this->*F
)(Cache
[Pkg
].InstVerIter(Cache
).DependsList());
449 // OrderList::VisitRDeps - Visit reverse dependencies /*{{{*/
450 // ---------------------------------------------------------------------
451 /* This calls the dependency function for all of the normal reverse depends
453 bool pkgOrderList::VisitRDeps(DepFunc F
,PkgIterator Pkg
)
455 if (F
== 0 || Pkg
.end() == true)
458 return (this->*F
)(Pkg
.RevDependsList());
461 // OrderList::VisitRProvides - Visit provides reverse dependencies /*{{{*/
462 // ---------------------------------------------------------------------
463 /* This calls the dependency function for all reverse dependencies
464 generated by the provides line on the package. */
465 bool pkgOrderList::VisitRProvides(DepFunc F
,VerIterator Ver
)
467 if (F
== 0 || Ver
.end() == true)
471 for (PrvIterator P
= Ver
.ProvidesList(); P
.end() == false; P
++)
472 Res
&= (this->*F
)(P
.ParentPkg().RevDependsList());
476 // OrderList::VisitProvides - Visit all of the providing packages /*{{{*/
477 // ---------------------------------------------------------------------
478 /* This routine calls visit on all providing packages. */
479 bool pkgOrderList::VisitProvides(DepIterator D
,bool Critical
)
481 SPtrArray
<Version
*> List
= D
.AllTargets();
482 for (Version
**I
= List
; *I
!= 0; I
++)
484 VerIterator
Ver(Cache
,*I
);
485 PkgIterator Pkg
= Ver
.ParentPkg();
487 if (Cache
[Pkg
].Keep() == true && Pkg
.State() == PkgIterator::NeedsNothing
)
490 if (D
->Type
!= pkgCache::Dep::Conflicts
&&
491 D
->Type
!= pkgCache::Dep::DpkgBreaks
&&
492 D
->Type
!= pkgCache::Dep::Obsoletes
&&
493 Cache
[Pkg
].InstallVer
!= *I
)
496 if ((D
->Type
== pkgCache::Dep::Conflicts
||
497 D
->Type
== pkgCache::Dep::DpkgBreaks
||
498 D
->Type
== pkgCache::Dep::Obsoletes
) &&
499 (Version
*)Pkg
.CurrentVer() != *I
)
502 // Skip over missing files
503 if (Critical
== false && IsMissing(D
.ParentPkg()) == true)
506 if (VisitNode(Pkg
) == false)
512 // OrderList::VisitNode - Recursive ordering director /*{{{*/
513 // ---------------------------------------------------------------------
514 /* This is the core ordering routine. It calls the set dependency
515 consideration functions which then potentialy call this again. Finite
516 depth is achived through the colouring mechinism. */
517 bool pkgOrderList::VisitNode(PkgIterator Pkg
)
519 // Looping or irrelevent.
520 // This should probably trancend not installed packages
521 if (Pkg
.end() == true || IsFlag(Pkg
,Added
) == true ||
522 IsFlag(Pkg
,AddPending
) == true || IsFlag(Pkg
,InList
) == false)
527 for (int j
= 0; j
!= Depth
; j
++) clog
<< ' ';
528 clog
<< "Visit " << Pkg
.Name() << endl
;
534 Flag(Pkg
,AddPending
);
536 DepFunc Old
= Primary
;
538 // Perform immedate configuration of the package if so flagged.
539 if (IsFlag(Pkg
,Immediate
) == true && Primary
!= &pkgOrderList::DepUnPackPre
)
540 Primary
= &pkgOrderList::DepUnPackPreD
;
542 if (IsNow(Pkg
) == true)
545 if (Cache
[Pkg
].Delete() == false)
548 Res
&= Res
&& VisitDeps(Primary
,Pkg
);
549 Res
&= Res
&& VisitRDeps(Primary
,Pkg
);
550 Res
&= Res
&& VisitRProvides(Primary
,Pkg
.CurrentVer());
551 Res
&= Res
&& VisitRProvides(Primary
,Cache
[Pkg
].InstVerIter(Cache
));
554 Res
&= Res
&& VisitRDeps(RevDepends
,Pkg
);
555 Res
&= Res
&& VisitRProvides(RevDepends
,Pkg
.CurrentVer());
556 Res
&= Res
&& VisitRProvides(RevDepends
,Cache
[Pkg
].InstVerIter(Cache
));
559 Res
&= Res
&& VisitDeps(Secondary
,Pkg
);
560 Res
&= Res
&& VisitRDeps(Secondary
,Pkg
);
561 Res
&= Res
&& VisitRProvides(Secondary
,Pkg
.CurrentVer());
562 Res
&= Res
&& VisitRProvides(Secondary
,Cache
[Pkg
].InstVerIter(Cache
));
567 Res
&= Res
&& VisitRDeps(Remove
,Pkg
);
568 Res
&= Res
&& VisitRProvides(Remove
,Pkg
.CurrentVer());
572 if (IsFlag(Pkg
,Added
) == false)
574 Flag(Pkg
,Added
,Added
| AddPending
);
575 if (IsFlag(Pkg
,After
) == true)
586 for (int j
= 0; j
!= Depth
; j
++) clog
<< ' ';
587 clog
<< "Leave " << Pkg
.Name() << ' ' << IsFlag(Pkg
,Added
) << ',' << IsFlag(Pkg
,AddPending
) << endl
;
594 // OrderList::DepUnPackCrit - Critical UnPacking ordering /*{{{*/
595 // ---------------------------------------------------------------------
596 /* Critical unpacking ordering strives to satisfy Conflicts: and
597 PreDepends: only. When a prdepends is encountered the Primary
598 DepFunc is changed to be DepUnPackPreD.
600 Loops are preprocessed and logged. */
601 bool pkgOrderList::DepUnPackCrit(DepIterator D
)
603 for (; D
.end() == false; D
++)
605 if (D
.Reverse() == true)
607 /* Reverse depenanices are only interested in conflicts,
608 predepend breakage is ignored here */
609 if (D
->Type
!= pkgCache::Dep::Conflicts
&&
610 D
->Type
!= pkgCache::Dep::Obsoletes
)
613 // Duplication elimination, consider only the current version
614 if (D
.ParentPkg().CurrentVer() != D
.ParentVer())
617 /* For reverse dependencies we wish to check if the
618 dependency is satisifed in the install state. The
619 target package (caller) is going to be in the installed
621 if (CheckDep(D
) == true)
624 if (VisitNode(D
.ParentPkg()) == false)
629 /* Forward critical dependencies MUST be correct before the
630 package can be unpacked. */
631 if (D
->Type
!= pkgCache::Dep::Conflicts
&&
632 D
->Type
!= pkgCache::Dep::DpkgBreaks
&&
633 D
->Type
!= pkgCache::Dep::Obsoletes
&&
634 D
->Type
!= pkgCache::Dep::PreDepends
)
637 /* We wish to check if the dep is okay in the now state of the
638 target package against the install state of this package. */
639 if (CheckDep(D
) == true)
641 /* We want to catch predepends loops with the code below.
642 Conflicts loops that are Dep OK are ignored */
643 if (IsFlag(D
.TargetPkg(),AddPending
) == false ||
644 D
->Type
!= pkgCache::Dep::PreDepends
)
648 // This is the loop detection
649 if (IsFlag(D
.TargetPkg(),Added
) == true ||
650 IsFlag(D
.TargetPkg(),AddPending
) == true)
652 if (IsFlag(D
.TargetPkg(),AddPending
) == true)
657 /* Predepends require a special ordering stage, they must have
658 all dependents installed as well */
659 DepFunc Old
= Primary
;
661 if (D
->Type
== pkgCache::Dep::PreDepends
)
662 Primary
= &pkgOrderList::DepUnPackPreD
;
663 Res
= VisitProvides(D
,true);
672 // OrderList::DepUnPackPreD - Critical UnPacking ordering with depends /*{{{*/
673 // ---------------------------------------------------------------------
674 /* Critical PreDepends (also configure immediate and essential) strives to
675 ensure not only that all conflicts+predepends are met but that this
676 package will be immediately configurable when it is unpacked.
678 Loops are preprocessed and logged. */
679 bool pkgOrderList::DepUnPackPreD(DepIterator D
)
681 if (D
.Reverse() == true)
682 return DepUnPackCrit(D
);
684 for (; D
.end() == false; D
++)
686 if (D
.IsCritical() == false)
689 /* We wish to check if the dep is okay in the now state of the
690 target package against the install state of this package. */
691 if (CheckDep(D
) == true)
693 /* We want to catch predepends loops with the code below.
694 Conflicts loops that are Dep OK are ignored */
695 if (IsFlag(D
.TargetPkg(),AddPending
) == false ||
696 D
->Type
!= pkgCache::Dep::PreDepends
)
700 // This is the loop detection
701 if (IsFlag(D
.TargetPkg(),Added
) == true ||
702 IsFlag(D
.TargetPkg(),AddPending
) == true)
704 if (IsFlag(D
.TargetPkg(),AddPending
) == true)
709 if (VisitProvides(D
,true) == false)
715 // OrderList::DepUnPackPre - Critical Predepends ordering /*{{{*/
716 // ---------------------------------------------------------------------
717 /* Critical PreDepends (also configure immediate and essential) strives to
718 ensure not only that all conflicts+predepends are met but that this
719 package will be immediately configurable when it is unpacked.
721 Loops are preprocessed and logged. All loops will be fatal. */
722 bool pkgOrderList::DepUnPackPre(DepIterator D
)
724 if (D
.Reverse() == true)
727 for (; D
.end() == false; D
++)
729 /* Only consider the PreDepends or Depends. Depends are only
730 considered at the lowest depth or in the case of immediate
732 if (D
->Type
!= pkgCache::Dep::PreDepends
)
734 if (D
->Type
== pkgCache::Dep::Depends
)
736 if (Depth
== 1 && IsFlag(D
.ParentPkg(),Immediate
) == false)
743 /* We wish to check if the dep is okay in the now state of the
744 target package against the install state of this package. */
745 if (CheckDep(D
) == true)
747 /* We want to catch predepends loops with the code below.
748 Conflicts loops that are Dep OK are ignored */
749 if (IsFlag(D
.TargetPkg(),AddPending
) == false)
753 // This is the loop detection
754 if (IsFlag(D
.TargetPkg(),Added
) == true ||
755 IsFlag(D
.TargetPkg(),AddPending
) == true)
757 if (IsFlag(D
.TargetPkg(),AddPending
) == true)
762 if (VisitProvides(D
,true) == false)
768 // OrderList::DepUnPackDep - Reverse dependency considerations /*{{{*/
769 // ---------------------------------------------------------------------
770 /* Reverse dependencies are considered to determine if unpacking this
771 package will break any existing dependencies. If so then those
772 packages are ordered before this one so that they are in the
775 The forwards depends loop is designed to bring the packages dependents
776 close to the package. This helps reduce deconfigure time.
778 Loops are irrelevent to this. */
779 bool pkgOrderList::DepUnPackDep(DepIterator D
)
782 for (; D
.end() == false; D
++)
783 if (D
.IsCritical() == true)
785 if (D
.Reverse() == true)
787 /* Duplication prevention. We consider rev deps only on
788 the current version, a not installed package
790 if (D
.ParentPkg()->CurrentVer
== 0 ||
791 D
.ParentPkg().CurrentVer() != D
.ParentVer())
794 // The dep will not break so it is irrelevent.
795 if (CheckDep(D
) == true)
798 // Skip over missing files
799 if (IsMissing(D
.ParentPkg()) == true)
802 if (VisitNode(D
.ParentPkg()) == false)
807 if (D
->Type
== pkgCache::Dep::Depends
)
808 if (VisitProvides(D
,false) == false)
811 if (D
->Type
== pkgCache::Dep::DpkgBreaks
)
813 if (CheckDep(D
) == true)
816 if (VisitNode(D
.TargetPkg()) == false)
824 // OrderList::DepConfigure - Configuration ordering /*{{{*/
825 // ---------------------------------------------------------------------
826 /* Configuration only ordering orders by the Depends: line only. It
827 orders configuration so that when a package comes to be configured it's
828 dependents are configured.
830 Loops are ingored. Depends loop entry points are chaotic. */
831 bool pkgOrderList::DepConfigure(DepIterator D
)
833 // Never consider reverse configuration dependencies.
834 if (D
.Reverse() == true)
837 for (; D
.end() == false; D
++)
838 if (D
->Type
== pkgCache::Dep::Depends
)
839 if (VisitProvides(D
,false) == false)
844 // OrderList::DepRemove - Removal ordering /*{{{*/
845 // ---------------------------------------------------------------------
846 /* Removal visits all reverse depends. It considers if the dependency
847 of the Now state version to see if it is okay with removing this
848 package. This check should always fail, but is provided for symetery
849 with the other critical handlers.
851 Loops are preprocessed and logged. Removal loops can also be
852 detected in the critical handler. They are characterized by an
853 old version of A depending on B but the new version of A conflicting
854 with B, thus either A or B must break to install. */
855 bool pkgOrderList::DepRemove(DepIterator D
)
857 if (D
.Reverse() == false)
859 for (; D
.end() == false; D
++)
860 if (D
->Type
== pkgCache::Dep::Depends
|| D
->Type
== pkgCache::Dep::PreDepends
)
862 // Duplication elimination, consider the current version only
863 if (D
.ParentPkg().CurrentVer() != D
.ParentVer())
866 /* We wish to see if the dep on the parent package is okay
867 in the removed (install) state of the target pkg. */
868 if (CheckDep(D
) == true)
870 // We want to catch loops with the code below.
871 if (IsFlag(D
.ParentPkg(),AddPending
) == false)
875 // This is the loop detection
876 if (IsFlag(D
.ParentPkg(),Added
) == true ||
877 IsFlag(D
.ParentPkg(),AddPending
) == true)
879 if (IsFlag(D
.ParentPkg(),AddPending
) == true)
884 // Skip over missing files
885 if (IsMissing(D
.ParentPkg()) == true)
888 if (VisitNode(D
.ParentPkg()) == false)
896 // OrderList::AddLoop - Add a loop to the loop list /*{{{*/
897 // ---------------------------------------------------------------------
898 /* We record the loops. This is a relic since loop breaking is done
899 genericaly as part of the safety routines. */
900 bool pkgOrderList::AddLoop(DepIterator D
)
902 if (LoopCount
< 0 || LoopCount
>= 20)
908 if (Loops
[LoopCount
- 1].ParentPkg() == D
.ParentPkg() ||
909 Loops
[LoopCount
- 1].TargetPkg() == D
.ParentPkg())
913 Loops
[LoopCount
++] = D
;
915 // Mark the packages as being part of a loop.
916 Flag(D
.TargetPkg(),Loop
);
917 Flag(D
.ParentPkg(),Loop
);
921 // OrderList::WipeFlags - Unset the given flags from all packages /*{{{*/
922 // ---------------------------------------------------------------------
924 void pkgOrderList::WipeFlags(unsigned long F
)
926 unsigned long Size
= Cache
.Head().PackageCount
;
927 for (unsigned long I
= 0; I
!= Size
; I
++)
931 // OrderList::CheckDep - Check a dependency for truth /*{{{*/
932 // ---------------------------------------------------------------------
933 /* This performs a complete analysis of the dependency wrt to the
934 current add list. It returns true if after all events are
935 performed it is still true. This sort of routine can be approximated
936 by examining the DepCache, however in convoluted cases of provides
937 this fails to produce a suitable result. */
938 bool pkgOrderList::CheckDep(DepIterator D
)
940 SPtrArray
<Version
*> List
= D
.AllTargets();
942 for (Version
**I
= List
; *I
!= 0; I
++)
944 VerIterator
Ver(Cache
,*I
);
945 PkgIterator Pkg
= Ver
.ParentPkg();
947 /* The meaning of Added and AddPending is subtle. AddPending is
948 an indication that the package is looping. Because of the
949 way ordering works Added means the package will be unpacked
950 before this one and AddPending means after. It is therefore
951 correct to ignore AddPending in all cases, but that exposes
952 reverse-ordering loops which should be ignored. */
953 if (IsFlag(Pkg
,Added
) == true ||
954 (IsFlag(Pkg
,AddPending
) == true && D
.Reverse() == true))
956 if (Cache
[Pkg
].InstallVer
!= *I
)
960 if ((Version
*)Pkg
.CurrentVer() != *I
||
961 Pkg
.State() != PkgIterator::NeedsNothing
)
964 /* Conflicts requires that all versions are not present, depends
966 if (D
->Type
!= pkgCache::Dep::Conflicts
&&
967 D
->Type
!= pkgCache::Dep::DpkgBreaks
&&
968 D
->Type
!= pkgCache::Dep::Obsoletes
)
970 /* Try to find something that does not have the after flag set
971 if at all possible */
972 if (IsFlag(Pkg
,After
) == true)
982 if (IsFlag(Pkg
,After
) == true)
983 Flag(D
.ParentPkg(),After
);
989 // We found a hit, but it had the after flag set
990 if (Hit
== true && D
->Type
== pkgCache::Dep::PreDepends
)
992 Flag(D
.ParentPkg(),After
);
996 /* Conflicts requires that all versions are not present, depends
998 if (D
->Type
== pkgCache::Dep::Conflicts
||
999 D
->Type
== pkgCache::Dep::Obsoletes
)