]>
git.saurik.com Git - apt.git/blob - apt-pkg/orderlist.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: orderlist.cc,v 1.13 2001/04/27 04:47:58 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 /*{{{*/
67 #pragma implementation "apt-pkg/orderlist.h"
69 #include <apt-pkg/orderlist.h>
70 #include <apt-pkg/depcache.h>
71 #include <apt-pkg/error.h>
72 #include <apt-pkg/version.h>
73 #include <apt-pkg/sptr.h>
74 #include <apt-pkg/configuration.h>
77 pkgOrderList
*pkgOrderList::Me
= 0;
79 // OrderList::pkgOrderList - Constructor /*{{{*/
80 // ---------------------------------------------------------------------
82 pkgOrderList::pkgOrderList(pkgDepCache
*pCache
) : Cache(*pCache
)
90 Debug
= _config
->FindB("Debug::pkgOrderList",false);
92 /* Construct the arrays, egcs 1.0.1 bug requires the package count
94 unsigned long Size
= Cache
.Head().PackageCount
;
95 Flags
= new unsigned short[Size
];
96 End
= List
= new Package
*[Size
];
97 memset(Flags
,0,sizeof(*Flags
)*Size
);
100 // OrderList::~pkgOrderList - Destructor /*{{{*/
101 // ---------------------------------------------------------------------
103 pkgOrderList::~pkgOrderList()
109 // OrderList::IsMissing - Check if a file is missing /*{{{*/
110 // ---------------------------------------------------------------------
112 bool pkgOrderList::IsMissing(PkgIterator Pkg
)
114 // Skip packages to erase
115 if (Cache
[Pkg
].Delete() == true)
118 // Skip Packages that need configure only.
119 if (Pkg
.State() == pkgCache::PkgIterator::NeedsConfigure
&&
120 Cache
[Pkg
].Keep() == true)
126 if (FileList
[Pkg
->ID
].empty() == false)
132 // OrderList::DoRun - Does an order run /*{{{*/
133 // ---------------------------------------------------------------------
134 /* The caller is expeted to have setup the desired probe state */
135 bool pkgOrderList::DoRun()
138 unsigned long Size
= Cache
.Head().PackageCount
;
139 SPtrArray
<Package
*> NList
= new Package
*[Size
];
140 SPtrArray
<Package
*> AfterList
= new Package
*[Size
];
141 AfterEnd
= AfterList
;
144 WipeFlags(Added
| AddPending
| Loop
| InList
);
146 for (iterator I
= List
; I
!= End
; I
++)
149 // Rebuild the main list into the temp list.
150 iterator OldEnd
= End
;
152 for (iterator I
= List
; I
!= OldEnd
; I
++)
153 if (VisitNode(PkgIterator(Cache
,*I
)) == false)
159 // Copy the after list to the end of the main list
160 for (Package
**I
= AfterList
; I
!= AfterEnd
; I
++)
163 // Swap the main list to the new list
165 List
= NList
.UnGuard();
169 // OrderList::OrderCritical - Perform critical unpacking ordering /*{{{*/
170 // ---------------------------------------------------------------------
171 /* This performs predepends and immediate configuration ordering only.
172 This is termed critical unpacking ordering. Any loops that form are
173 fatal and indicate that the packages cannot be installed. */
174 bool pkgOrderList::OrderCritical()
178 Primary
= &pkgOrderList::DepUnPackPre
;
186 qsort(List
,End
- List
,sizeof(*List
),&OrderCompareB
);
188 if (DoRun() == false)
192 return _error
->Error("Fatal, predepends looping detected");
196 // OrderList::OrderUnpack - Perform complete unpacking ordering /*{{{*/
197 // ---------------------------------------------------------------------
198 /* This performs complete unpacking ordering and creates an order that is
199 suitable for unpacking */
200 bool pkgOrderList::OrderUnpack(string
*FileList
)
202 this->FileList
= FileList
;
204 // Setup the after flags
209 // Set the inlist flag
210 for (iterator I
= List
; I
!= End
; I
++)
212 PkgIterator
P(Cache
,*I
);
213 if (IsMissing(P
) == true && IsNow(P
) == true)
218 Primary
= &pkgOrderList::DepUnPackCrit
;
219 Secondary
= &pkgOrderList::DepConfigure
;
220 RevDepends
= &pkgOrderList::DepUnPackDep
;
221 Remove
= &pkgOrderList::DepRemove
;
226 qsort(List
,End
- List
,sizeof(*List
),&OrderCompareA
);
229 clog
<< "** Pass A" << endl
;
230 if (DoRun() == false)
234 clog
<< "** Pass B" << endl
;
236 if (DoRun() == false)
240 clog
<< "** Pass C" << endl
;
243 Remove
= 0; // Otherwise the libreadline remove problem occures
244 if (DoRun() == false)
248 clog
<< "** Pass D" << endl
;
250 Primary
= &pkgOrderList::DepUnPackPre
;
251 if (DoRun() == false)
256 clog
<< "** Unpack ordering done" << endl
;
258 for (iterator I
= List
; I
!= End
; I
++)
260 PkgIterator
P(Cache
,*I
);
261 if (IsNow(P
) == true)
262 clog
<< P
.Name() << ' ' << IsMissing(P
) << ',' << IsFlag(P
,After
) << endl
;
269 // OrderList::OrderConfigure - Perform configuration ordering /*{{{*/
270 // ---------------------------------------------------------------------
271 /* This orders by depends only and produces an order which is suitable
273 bool pkgOrderList::OrderConfigure()
276 Primary
= &pkgOrderList::DepConfigure
;
285 // OrderList::Score - Score the package for sorting /*{{{*/
286 // ---------------------------------------------------------------------
287 /* Higher scores order earlier */
288 int pkgOrderList::Score(PkgIterator Pkg
)
290 // Removal is always done first
291 if (Cache
[Pkg
].Delete() == true)
294 // This should never happen..
295 if (Cache
[Pkg
].InstVerIter(Cache
).end() == true)
299 if ((Pkg
->Flags
& pkgCache::Flag::Essential
) == pkgCache::Flag::Essential
)
302 if (IsFlag(Pkg
,Immediate
) == true)
305 for (DepIterator D
= Cache
[Pkg
].InstVerIter(Cache
).DependsList();
306 D
.end() == false; D
++)
307 if (D
->Type
== pkgCache::Dep::PreDepends
)
313 // Important Required Standard Optional Extra
314 signed short PrioMap
[] = {0,5,4,3,1,0};
315 if (Cache
[Pkg
].InstVerIter(Cache
)->Priority
<= 5)
316 Score
+= PrioMap
[Cache
[Pkg
].InstVerIter(Cache
)->Priority
];
320 // OrderList::FileCmp - Compare by package file /*{{{*/
321 // ---------------------------------------------------------------------
322 /* This compares by the package file that the install version is in. */
323 int pkgOrderList::FileCmp(PkgIterator A
,PkgIterator B
)
325 if (Cache
[A
].Delete() == true && Cache
[B
].Delete() == true)
327 if (Cache
[A
].Delete() == true)
329 if (Cache
[B
].Delete() == true)
332 if (Cache
[A
].InstVerIter(Cache
).FileList().end() == true)
334 if (Cache
[B
].InstVerIter(Cache
).FileList().end() == true)
337 pkgCache::PackageFile
*FA
= Cache
[A
].InstVerIter(Cache
).FileList().File();
338 pkgCache::PackageFile
*FB
= Cache
[B
].InstVerIter(Cache
).FileList().File();
346 // BoolCompare - Comparison function for two booleans /*{{{*/
347 // ---------------------------------------------------------------------
349 static int BoolCompare(bool A
,bool B
)
358 // OrderList::OrderCompareA - Order the installation by op /*{{{*/
359 // ---------------------------------------------------------------------
360 /* This provides a first-pass sort of the list and gives a decent starting
361 point for further complete ordering. It is used by OrderUnpack only */
362 int pkgOrderList::OrderCompareA(const void *a
, const void *b
)
364 PkgIterator
A(Me
->Cache
,*(Package
**)a
);
365 PkgIterator
B(Me
->Cache
,*(Package
**)b
);
367 // We order packages with a set state toward the front
369 if ((Res
= BoolCompare(Me
->IsNow(A
),Me
->IsNow(B
))) != 0)
372 // We order missing files to toward the end
373 /* if (Me->FileList != 0)
375 if ((Res = BoolCompare(Me->IsMissing(A),
376 Me->IsMissing(B))) != 0)
380 if (A
.State() != pkgCache::PkgIterator::NeedsNothing
&&
381 B
.State() == pkgCache::PkgIterator::NeedsNothing
)
384 if (A
.State() == pkgCache::PkgIterator::NeedsNothing
&&
385 B
.State() != pkgCache::PkgIterator::NeedsNothing
)
388 int ScoreA
= Me
->Score(A
);
389 int ScoreB
= Me
->Score(B
);
396 return strcmp(A
.Name(),B
.Name());
399 // OrderList::OrderCompareB - Order the installation by source /*{{{*/
400 // ---------------------------------------------------------------------
401 /* This orders by installation source. This is useful to handle
402 inter-source breaks */
403 int pkgOrderList::OrderCompareB(const void *a
, const void *b
)
405 PkgIterator
A(Me
->Cache
,*(Package
**)a
);
406 PkgIterator
B(Me
->Cache
,*(Package
**)b
);
408 if (A
.State() != pkgCache::PkgIterator::NeedsNothing
&&
409 B
.State() == pkgCache::PkgIterator::NeedsNothing
)
412 if (A
.State() == pkgCache::PkgIterator::NeedsNothing
&&
413 B
.State() != pkgCache::PkgIterator::NeedsNothing
)
416 int F
= Me
->FileCmp(A
,B
);
424 int ScoreA
= Me
->Score(A
);
425 int ScoreB
= Me
->Score(B
);
432 return strcmp(A
.Name(),B
.Name());
436 // OrderList::VisitDeps - Visit forward install dependencies /*{{{*/
437 // ---------------------------------------------------------------------
438 /* This calls the dependency function for the normal forwards dependencies
440 bool pkgOrderList::VisitDeps(DepFunc F
,PkgIterator Pkg
)
442 if (F
== 0 || Pkg
.end() == true || Cache
[Pkg
].InstallVer
== 0)
445 return (this->*F
)(Cache
[Pkg
].InstVerIter(Cache
).DependsList());
448 // OrderList::VisitRDeps - Visit reverse dependencies /*{{{*/
449 // ---------------------------------------------------------------------
450 /* This calls the dependency function for all of the normal reverse depends
452 bool pkgOrderList::VisitRDeps(DepFunc F
,PkgIterator Pkg
)
454 if (F
== 0 || Pkg
.end() == true)
457 return (this->*F
)(Pkg
.RevDependsList());
460 // OrderList::VisitRProvides - Visit provides reverse dependencies /*{{{*/
461 // ---------------------------------------------------------------------
462 /* This calls the dependency function for all reverse dependencies
463 generated by the provides line on the package. */
464 bool pkgOrderList::VisitRProvides(DepFunc F
,VerIterator Ver
)
466 if (F
== 0 || Ver
.end() == true)
470 for (PrvIterator P
= Ver
.ProvidesList(); P
.end() == false; P
++)
471 Res
&= (this->*F
)(P
.ParentPkg().RevDependsList());
475 // OrderList::VisitProvides - Visit all of the providing packages /*{{{*/
476 // ---------------------------------------------------------------------
477 /* This routine calls visit on all providing packages. */
478 bool pkgOrderList::VisitProvides(DepIterator D
,bool Critical
)
480 SPtrArray
<Version
*> List
= D
.AllTargets();
481 for (Version
**I
= List
; *I
!= 0; I
++)
483 VerIterator
Ver(Cache
,*I
);
484 PkgIterator Pkg
= Ver
.ParentPkg();
486 if (Cache
[Pkg
].Keep() == true && Pkg
.State() == PkgIterator::NeedsNothing
)
489 if (D
->Type
!= pkgCache::Dep::Conflicts
&&
490 D
->Type
!= pkgCache::Dep::Obsoletes
&&
491 Cache
[Pkg
].InstallVer
!= *I
)
494 if ((D
->Type
== pkgCache::Dep::Conflicts
||
495 D
->Type
== pkgCache::Dep::Obsoletes
) &&
496 (Version
*)Pkg
.CurrentVer() != *I
)
499 // Skip over missing files
500 if (Critical
== false && IsMissing(D
.ParentPkg()) == true)
503 if (VisitNode(Pkg
) == false)
509 // OrderList::VisitNode - Recursive ordering director /*{{{*/
510 // ---------------------------------------------------------------------
511 /* This is the core ordering routine. It calls the set dependency
512 consideration functions which then potentialy call this again. Finite
513 depth is achived through the colouring mechinism. */
514 bool pkgOrderList::VisitNode(PkgIterator Pkg
)
516 // Looping or irrelevent.
517 // This should probably trancend not installed packages
518 if (Pkg
.end() == true || IsFlag(Pkg
,Added
) == true ||
519 IsFlag(Pkg
,AddPending
) == true || IsFlag(Pkg
,InList
) == false)
524 for (int j
= 0; j
!= Depth
; j
++) clog
<< ' ';
525 clog
<< "Visit " << Pkg
.Name() << endl
;
531 Flag(Pkg
,AddPending
);
533 DepFunc Old
= Primary
;
535 // Perform immedate configuration of the package if so flagged.
536 if (IsFlag(Pkg
,Immediate
) == true && Primary
!= &pkgOrderList::DepUnPackPre
)
537 Primary
= &pkgOrderList::DepUnPackPreD
;
539 if (IsNow(Pkg
) == true)
542 if (Cache
[Pkg
].Delete() == false)
545 Res
&= Res
&& VisitDeps(Primary
,Pkg
);
546 Res
&= Res
&& VisitRDeps(Primary
,Pkg
);
547 Res
&= Res
&& VisitRProvides(Primary
,Pkg
.CurrentVer());
548 Res
&= Res
&& VisitRProvides(Primary
,Cache
[Pkg
].InstVerIter(Cache
));
551 Res
&= Res
&& VisitRDeps(RevDepends
,Pkg
);
552 Res
&= Res
&& VisitRProvides(RevDepends
,Pkg
.CurrentVer());
553 Res
&= Res
&& VisitRProvides(RevDepends
,Cache
[Pkg
].InstVerIter(Cache
));
556 Res
&= Res
&& VisitDeps(Secondary
,Pkg
);
557 Res
&= Res
&& VisitRDeps(Secondary
,Pkg
);
558 Res
&= Res
&& VisitRProvides(Secondary
,Pkg
.CurrentVer());
559 Res
&= Res
&& VisitRProvides(Secondary
,Cache
[Pkg
].InstVerIter(Cache
));
564 Res
&= Res
&& VisitRDeps(Remove
,Pkg
);
565 Res
&= Res
&& VisitRProvides(Remove
,Pkg
.CurrentVer());
569 if (IsFlag(Pkg
,Added
) == false)
571 Flag(Pkg
,Added
,Added
| AddPending
);
572 if (IsFlag(Pkg
,After
) == true)
583 for (int j
= 0; j
!= Depth
; j
++) clog
<< ' ';
584 clog
<< "Leave " << Pkg
.Name() << ' ' << IsFlag(Pkg
,Added
) << ',' << IsFlag(Pkg
,AddPending
) << endl
;
591 // OrderList::DepUnPackCrit - Critical UnPacking ordering /*{{{*/
592 // ---------------------------------------------------------------------
593 /* Critical unpacking ordering strives to satisfy Conflicts: and
594 PreDepends: only. When a prdepends is encountered the Primary
595 DepFunc is changed to be DepUnPackPreD.
597 Loops are preprocessed and logged. */
598 bool pkgOrderList::DepUnPackCrit(DepIterator D
)
600 for (; D
.end() == false; D
++)
602 if (D
.Reverse() == true)
604 /* Reverse depenanices are only interested in conflicts,
605 predepend breakage is ignored here */
606 if (D
->Type
!= pkgCache::Dep::Conflicts
&&
607 D
->Type
!= pkgCache::Dep::Obsoletes
)
610 // Duplication elimination, consider only the current version
611 if (D
.ParentPkg().CurrentVer() != D
.ParentVer())
614 /* For reverse dependencies we wish to check if the
615 dependency is satisifed in the install state. The
616 target package (caller) is going to be in the installed
618 if (CheckDep(D
) == true)
621 if (VisitNode(D
.ParentPkg()) == false)
626 /* Forward critical dependencies MUST be correct before the
627 package can be unpacked. */
628 if (D
->Type
!= pkgCache::Dep::Conflicts
&&
629 D
->Type
!= pkgCache::Dep::Obsoletes
&&
630 D
->Type
!= pkgCache::Dep::PreDepends
)
633 /* We wish to check if the dep is okay in the now state of the
634 target package against the install state of this package. */
635 if (CheckDep(D
) == true)
637 /* We want to catch predepends loops with the code below.
638 Conflicts loops that are Dep OK are ignored */
639 if (IsFlag(D
.TargetPkg(),AddPending
) == false ||
640 D
->Type
!= pkgCache::Dep::PreDepends
)
644 // This is the loop detection
645 if (IsFlag(D
.TargetPkg(),Added
) == true ||
646 IsFlag(D
.TargetPkg(),AddPending
) == true)
648 if (IsFlag(D
.TargetPkg(),AddPending
) == true)
653 /* Predepends require a special ordering stage, they must have
654 all dependents installed as well */
655 DepFunc Old
= Primary
;
657 if (D
->Type
== pkgCache::Dep::PreDepends
)
658 Primary
= &pkgOrderList::DepUnPackPreD
;
659 Res
= VisitProvides(D
,true);
668 // OrderList::DepUnPackPreD - Critical UnPacking ordering with depends /*{{{*/
669 // ---------------------------------------------------------------------
670 /* Critical PreDepends (also configure immediate and essential) strives to
671 ensure not only that all conflicts+predepends are met but that this
672 package will be immediately configurable when it is unpacked.
674 Loops are preprocessed and logged. */
675 bool pkgOrderList::DepUnPackPreD(DepIterator D
)
677 if (D
.Reverse() == true)
678 return DepUnPackCrit(D
);
680 for (; D
.end() == false; D
++)
682 if (D
.IsCritical() == false)
685 /* We wish to check if the dep is okay in the now state of the
686 target package against the install state of this package. */
687 if (CheckDep(D
) == true)
689 /* We want to catch predepends loops with the code below.
690 Conflicts loops that are Dep OK are ignored */
691 if (IsFlag(D
.TargetPkg(),AddPending
) == false ||
692 D
->Type
!= pkgCache::Dep::PreDepends
)
696 // This is the loop detection
697 if (IsFlag(D
.TargetPkg(),Added
) == true ||
698 IsFlag(D
.TargetPkg(),AddPending
) == true)
700 if (IsFlag(D
.TargetPkg(),AddPending
) == true)
705 if (VisitProvides(D
,true) == false)
711 // OrderList::DepUnPackPre - Critical Predepends ordering /*{{{*/
712 // ---------------------------------------------------------------------
713 /* Critical PreDepends (also configure immediate and essential) strives to
714 ensure not only that all conflicts+predepends are met but that this
715 package will be immediately configurable when it is unpacked.
717 Loops are preprocessed and logged. All loops will be fatal. */
718 bool pkgOrderList::DepUnPackPre(DepIterator D
)
720 if (D
.Reverse() == true)
723 for (; D
.end() == false; D
++)
725 /* Only consider the PreDepends or Depends. Depends are only
726 considered at the lowest depth or in the case of immediate
728 if (D
->Type
!= pkgCache::Dep::PreDepends
)
730 if (D
->Type
== pkgCache::Dep::Depends
)
732 if (Depth
== 1 && IsFlag(D
.ParentPkg(),Immediate
) == false)
739 /* We wish to check if the dep is okay in the now state of the
740 target package against the install state of this package. */
741 if (CheckDep(D
) == true)
743 /* We want to catch predepends loops with the code below.
744 Conflicts loops that are Dep OK are ignored */
745 if (IsFlag(D
.TargetPkg(),AddPending
) == false)
749 // This is the loop detection
750 if (IsFlag(D
.TargetPkg(),Added
) == true ||
751 IsFlag(D
.TargetPkg(),AddPending
) == true)
753 if (IsFlag(D
.TargetPkg(),AddPending
) == true)
758 if (VisitProvides(D
,true) == false)
764 // OrderList::DepUnPackDep - Reverse dependency considerations /*{{{*/
765 // ---------------------------------------------------------------------
766 /* Reverse dependencies are considered to determine if unpacking this
767 package will break any existing dependencies. If so then those
768 packages are ordered before this one so that they are in the
771 The forwards depends loop is designed to bring the packages dependents
772 close to the package. This helps reduce deconfigure time.
774 Loops are irrelevent to this. */
775 bool pkgOrderList::DepUnPackDep(DepIterator D
)
778 for (; D
.end() == false; D
++)
779 if (D
.IsCritical() == true)
781 if (D
.Reverse() == true)
783 /* Duplication prevention. We consider rev deps only on
784 the current version, a not installed package
786 if (D
.ParentPkg()->CurrentVer
== 0 ||
787 D
.ParentPkg().CurrentVer() != D
.ParentVer())
790 // The dep will not break so it is irrelevent.
791 if (CheckDep(D
) == true)
794 // Skip over missing files
795 if (IsMissing(D
.ParentPkg()) == true)
798 if (VisitNode(D
.ParentPkg()) == false)
802 if (D
->Type
== pkgCache::Dep::Depends
)
803 if (VisitProvides(D
,false) == false)
809 // OrderList::DepConfigure - Configuration ordering /*{{{*/
810 // ---------------------------------------------------------------------
811 /* Configuration only ordering orders by the Depends: line only. It
812 orders configuration so that when a package comes to be configured it's
813 dependents are configured.
815 Loops are ingored. Depends loop entry points are chaotic. */
816 bool pkgOrderList::DepConfigure(DepIterator D
)
818 // Never consider reverse configuration dependencies.
819 if (D
.Reverse() == true)
822 for (; D
.end() == false; D
++)
823 if (D
->Type
== pkgCache::Dep::Depends
)
824 if (VisitProvides(D
,false) == false)
829 // OrderList::DepRemove - Removal ordering /*{{{*/
830 // ---------------------------------------------------------------------
831 /* Removal visits all reverse depends. It considers if the dependency
832 of the Now state version to see if it is okay with removing this
833 package. This check should always fail, but is provided for symetery
834 with the other critical handlers.
836 Loops are preprocessed and logged. Removal loops can also be
837 detected in the critical handler. They are characterized by an
838 old version of A depending on B but the new version of A conflicting
839 with B, thus either A or B must break to install. */
840 bool pkgOrderList::DepRemove(DepIterator D
)
842 if (D
.Reverse() == false)
844 for (; D
.end() == false; D
++)
845 if (D
->Type
== pkgCache::Dep::Depends
|| D
->Type
== pkgCache::Dep::PreDepends
)
847 // Duplication elimination, consider the current version only
848 if (D
.ParentPkg().CurrentVer() != D
.ParentVer())
851 /* We wish to see if the dep on the parent package is okay
852 in the removed (install) state of the target pkg. */
853 if (CheckDep(D
) == true)
855 // We want to catch loops with the code below.
856 if (IsFlag(D
.ParentPkg(),AddPending
) == false)
860 // This is the loop detection
861 if (IsFlag(D
.ParentPkg(),Added
) == true ||
862 IsFlag(D
.ParentPkg(),AddPending
) == true)
864 if (IsFlag(D
.ParentPkg(),AddPending
) == true)
869 // Skip over missing files
870 if (IsMissing(D
.ParentPkg()) == true)
873 if (VisitNode(D
.ParentPkg()) == false)
881 // OrderList::AddLoop - Add a loop to the loop list /*{{{*/
882 // ---------------------------------------------------------------------
883 /* We record the loops. This is a relic since loop breaking is done
884 genericaly as part of the safety routines. */
885 bool pkgOrderList::AddLoop(DepIterator D
)
887 if (LoopCount
< 0 || LoopCount
>= 20)
893 if (Loops
[LoopCount
- 1].ParentPkg() == D
.ParentPkg() ||
894 Loops
[LoopCount
- 1].TargetPkg() == D
.ParentPkg())
898 Loops
[LoopCount
++] = D
;
900 // Mark the packages as being part of a loop.
901 Flag(D
.TargetPkg(),Loop
);
902 Flag(D
.ParentPkg(),Loop
);
906 // OrderList::WipeFlags - Unset the given flags from all packages /*{{{*/
907 // ---------------------------------------------------------------------
909 void pkgOrderList::WipeFlags(unsigned long F
)
911 unsigned long Size
= Cache
.Head().PackageCount
;
912 for (unsigned long I
= 0; I
!= Size
; I
++)
916 // OrderList::CheckDep - Check a dependency for truth /*{{{*/
917 // ---------------------------------------------------------------------
918 /* This performs a complete analysis of the dependency wrt to the
919 current add list. It returns true if after all events are
920 performed it is still true. This sort of routine can be approximated
921 by examining the DepCache, however in convoluted cases of provides
922 this fails to produce a suitable result. */
923 bool pkgOrderList::CheckDep(DepIterator D
)
925 SPtrArray
<Version
*> List
= D
.AllTargets();
927 for (Version
**I
= List
; *I
!= 0; I
++)
929 VerIterator
Ver(Cache
,*I
);
930 PkgIterator Pkg
= Ver
.ParentPkg();
932 /* The meaning of Added and AddPending is subtle. AddPending is
933 an indication that the package is looping. Because of the
934 way ordering works Added means the package will be unpacked
935 before this one and AddPending means after. It is therefore
936 correct to ignore AddPending in all cases, but that exposes
937 reverse-ordering loops which should be ignored. */
938 if (IsFlag(Pkg
,Added
) == true ||
939 (IsFlag(Pkg
,AddPending
) == true && D
.Reverse() == true))
941 if (Cache
[Pkg
].InstallVer
!= *I
)
945 if ((Version
*)Pkg
.CurrentVer() != *I
||
946 Pkg
.State() != PkgIterator::NeedsNothing
)
949 /* Conflicts requires that all versions are not present, depends
951 if (D
->Type
!= pkgCache::Dep::Conflicts
&&
952 D
->Type
!= pkgCache::Dep::Obsoletes
)
954 /* Try to find something that does not have the after flag set
955 if at all possible */
956 if (IsFlag(Pkg
,After
) == true)
966 if (IsFlag(Pkg
,After
) == true)
967 Flag(D
.ParentPkg(),After
);
973 // We found a hit, but it had the after flag set
974 if (Hit
== true && D
->Type
== pkgCache::Dep::PreDepends
)
976 Flag(D
.ParentPkg(),After
);
980 /* Conflicts requires that all versions are not present, depends
982 if (D
->Type
== pkgCache::Dep::Conflicts
||
983 D
->Type
== pkgCache::Dep::Obsoletes
)