X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/094a497dd2dba1f47157e07d57f97c338a5ddaa0..607bab3fe856d228f22e1cd96dbb7204e2f3375d:/apt-pkg/orderlist.cc?ds=sidebyside diff --git a/apt-pkg/orderlist.cc b/apt-pkg/orderlist.cc index 85d35d5a1..bfdc50e6c 100644 --- a/apt-pkg/orderlist.cc +++ b/apt-pkg/orderlist.cc @@ -1,13 +1,13 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ -// $Id: orderlist.cc,v 1.2 1998/07/12 23:58:28 jgg Exp $ +// $Id: orderlist.cc,v 1.14 2001/05/07 05:49:43 jgg Exp $ /* ###################################################################### Order List - Represents and Manipulates an ordered list of packages. A list of packages can be ordered by a number of conflicting criteria each given a specific priority. Each package also has a set of flags - indicating some usefull things about it that are derived in the + indicating some useful things about it that are derived in the course of sorting. The pkgPackageManager class uses this class for all of it's installation ordering needs. @@ -39,42 +39,62 @@ ordering. Each of the features can be enabled in the sorting routine at an - arbitary priority to give quite abit of control over the final unpacking + arbitrary priority to give quite abit of control over the final unpacking order. - The rules listed above my never be violated and are called Critical. + The rules listed above may never be violated and are called Critical. When a critical rule is violated then a loop condition is recorded and will have to be delt with in the caller. + + The ordering keeps two lists, the main list and the 'After List'. The + purpose of the after list is to allow packages to be delayed. This is done + by setting the after flag on the package. Any package which requires this + package to be ordered before will inherit the after flag and so on. This + is used for CD swap ordering where all packages on a second CD have the + after flag set. This forces them and all their dependents to be ordered + toward the end. + + There are complications in this algorithm when presented with cycles. + For all known practical cases it works, all cases where it doesn't work + is fixable by tweaking the package descriptions. However, it should be + possible to impove this further to make some better choices when + presented with cycles. ##################################################################### */ /*}}}*/ // Include Files /*{{{*/ -#ifdef __GNUG__ -#pragma implementation "apt-pkg/orderlist.h" -#endif +#include + #include #include #include -#include +#include +#include +#include + +#include +#include +#include +#include /*}}}*/ -pkgOrderList *pkgOrderList::Me = 0; +using namespace std; // OrderList::pkgOrderList - Constructor /*{{{*/ // --------------------------------------------------------------------- /* */ -pkgOrderList::pkgOrderList(pkgDepCache &Cache) : Cache(Cache) +pkgOrderList::pkgOrderList(pkgDepCache *pCache) : d(NULL), Cache(*pCache), + Primary(NULL), Secondary(NULL), + RevDepends(NULL), Remove(NULL), + AfterEnd(NULL), FileList(NULL), + LoopCount(-1), Depth(0) { - Primary = 0; - Secondary = 0; - RevDepends = 0; - Remove = 0; - LoopCount = -1; + Debug = _config->FindB("Debug::pkgOrderList",false); /* Construct the arrays, egcs 1.0.1 bug requires the package count hack */ - unsigned long Size = Cache.HeaderP->PackageCount; - Flags = new unsigned char[Size]; + unsigned long Size = Cache.Head().PackageCount; + Flags = new unsigned short[Size]; End = List = new Package *[Size]; memset(Flags,0,sizeof(*Flags)*Size); } @@ -88,36 +108,64 @@ pkgOrderList::~pkgOrderList() delete [] Flags; } /*}}}*/ +// OrderList::IsMissing - Check if a file is missing /*{{{*/ +// --------------------------------------------------------------------- +/* */ +bool pkgOrderList::IsMissing(PkgIterator Pkg) +{ + // Skip packages to erase + if (Cache[Pkg].Delete() == true) + return false; + // Skip Packages that need configure only. + if ((Pkg.State() == pkgCache::PkgIterator::NeedsConfigure || + Pkg.State() == pkgCache::PkgIterator::NeedsNothing) && + Cache[Pkg].Keep() == true) + return false; + + if (FileList == 0) + return false; + + if (FileList[Pkg->ID].empty() == false) + return false; + + return true; +} + /*}}}*/ // OrderList::DoRun - Does an order run /*{{{*/ // --------------------------------------------------------------------- /* The caller is expeted to have setup the desired probe state */ bool pkgOrderList::DoRun() -{ +{ // Temp list - unsigned long Size = Cache.HeaderP->PackageCount; - Package **NList = new Package *[Size]; - + unsigned long Size = Cache.Head().PackageCount; + std::unique_ptr NList(new Package *[Size]); + std::unique_ptr AfterList(new Package *[Size]); + AfterEnd = AfterList.get(); + Depth = 0; WipeFlags(Added | AddPending | Loop | InList); - for (iterator I = List; I != End; I++) + for (iterator I = List; I != End; ++I) Flag(*I,InList); - + // Rebuild the main list into the temp list. iterator OldEnd = End; - End = NList; - for (iterator I = List; I != OldEnd; I++) - if (VisitNode(PkgIterator(Cache,*I)) == false) + End = NList.get(); + for (iterator I = List; I != OldEnd; ++I) + if (VisitNode(PkgIterator(Cache,*I), "DoRun") == false) { End = OldEnd; - delete [] NList; return false; } + // Copy the after list to the end of the main list + for (Package **I = AfterList.get(); I != AfterEnd; I++) + *End++ = *I; + // Swap the main list to the new list delete [] List; - List = NList; + List = NList.release(); return true; } /*}}}*/ @@ -128,21 +176,35 @@ bool pkgOrderList::DoRun() fatal and indicate that the packages cannot be installed. */ bool pkgOrderList::OrderCritical() { - Primary = &DepUnPackPre; + FileList = 0; + + Primary = &pkgOrderList::DepUnPackPreD; Secondary = 0; RevDepends = 0; Remove = 0; LoopCount = 0; - + // Sort - Me = this; - qsort(List,End - List,sizeof(*List),&OrderCompareB); - + std::sort(List,End, [this](Package *a, Package *b) { return OrderCompareB(a, b) < 0; } ); + if (DoRun() == false) return false; - + if (LoopCount != 0) return _error->Error("Fatal, predepends looping detected"); + + if (Debug == true) + { + clog << "** Critical Unpack ordering done" << endl; + + for (iterator I = List; I != End; ++I) + { + PkgIterator P(Cache,*I); + if (IsNow(P) == true) + clog << " " << P.FullName() << ' ' << IsMissing(P) << ',' << IsFlag(P,After) << endl; + } + } + return true; } /*}}}*/ @@ -150,43 +212,70 @@ bool pkgOrderList::OrderCritical() // --------------------------------------------------------------------- /* This performs complete unpacking ordering and creates an order that is suitable for unpacking */ -bool pkgOrderList::OrderUnpack() +bool pkgOrderList::OrderUnpack(string *FileList) { - Primary = &DepUnPackCrit; - Secondary = &DepConfigure; - RevDepends = &DepUnPackDep; - Remove = &DepRemove; + this->FileList = FileList; + + // Setup the after flags + if (FileList != 0) + { + WipeFlags(After); + + // Set the inlist flag + for (iterator I = List; I != End; ++I) + { + PkgIterator P(Cache,*I); + if (IsMissing(P) == true && IsNow(P) == true) + Flag(*I,After); + } + } + + Primary = &pkgOrderList::DepUnPackCrit; + Secondary = &pkgOrderList::DepConfigure; + RevDepends = &pkgOrderList::DepUnPackDep; + Remove = &pkgOrderList::DepRemove; LoopCount = -1; // Sort - Me = this; - qsort(List,End - List,sizeof(*List),&OrderCompareA); - + std::sort(List,End, [this](Package *a, Package *b) { return OrderCompareA(a, b) < 0; }); + + if (Debug == true) + clog << "** Pass A" << endl; if (DoRun() == false) return false; - + + if (Debug == true) + clog << "** Pass B" << endl; Secondary = 0; if (DoRun() == false) return false; + if (Debug == true) + clog << "** Pass C" << endl; LoopCount = 0; RevDepends = 0; - Remove = 0; // Otherwise the libreadline remove problem occures + Remove = 0; // Otherwise the libreadline remove problem occurs if (DoRun() == false) return false; + if (Debug == true) + clog << "** Pass D" << endl; LoopCount = 0; - Primary = &DepUnPackPre; + Primary = &pkgOrderList::DepUnPackPre; if (DoRun() == false) return false; -/* cout << "----------END" << endl; - - for (iterator I = List; I != End; I++) + if (Debug == true) { - PkgIterator P(Cache,*I); - cout << P.Name() << endl; - }*/ + clog << "** Unpack ordering done" << endl; + + for (iterator I = List; I != End; ++I) + { + PkgIterator P(Cache,*I); + if (IsNow(P) == true) + clog << " " << P.FullName() << ' ' << IsMissing(P) << ',' << IsFlag(P,After) << endl; + } + } return true; } @@ -197,7 +286,8 @@ bool pkgOrderList::OrderUnpack() for configuration */ bool pkgOrderList::OrderConfigure() { - Primary = &DepConfigure; + FileList = 0; + Primary = &pkgOrderList::DepConfigure; Secondary = 0; RevDepends = 0; Remove = 0; @@ -205,32 +295,45 @@ bool pkgOrderList::OrderConfigure() return DoRun(); } /*}}}*/ - // OrderList::Score - Score the package for sorting /*{{{*/ // --------------------------------------------------------------------- /* Higher scores order earlier */ int pkgOrderList::Score(PkgIterator Pkg) { - // Removal is always done first + // Removals should be done after we dealt with essentials + static int const ScoreDelete = _config->FindI("OrderList::Score::Delete", 100); if (Cache[Pkg].Delete() == true) - return 200; + return ScoreDelete; + + // This should never happen.. + if (Cache[Pkg].InstVerIter(Cache).end() == true) + return -1; + + static int const ScoreEssential = _config->FindI("OrderList::Score::Essential", 200); + static int const ScoreImmediate = _config->FindI("OrderList::Score::Immediate", 10); + static int const ScorePreDepends = _config->FindI("OrderList::Score::PreDepends", 50); int Score = 0; if ((Pkg->Flags & pkgCache::Flag::Essential) == pkgCache::Flag::Essential) - Score += 100; + Score += ScoreEssential; + + if (IsFlag(Pkg,Immediate) == true) + Score += ScoreImmediate; - for (DepIterator D = Cache[Pkg].InstVerIter(Cache).DependsList(); - D.end() == false; D++) + for (DepIterator D = Cache[Pkg].InstVerIter(Cache).DependsList(); + D.end() == false; ++D) if (D->Type == pkgCache::Dep::PreDepends) { - Score += 50; + Score += ScorePreDepends; break; } - - // Important Required Standard Optional Extra - signed short PrioMap[] = {0,5,4,3,1,0}; + + // Required Important Standard Optional Extra if (Cache[Pkg].InstVerIter(Cache)->Priority <= 5) + { + signed short PrioMap[] = {0,5,4,3,1,0}; Score += PrioMap[Cache[Pkg].InstVerIter(Cache)->Priority]; + } return Score; } /*}}}*/ @@ -248,7 +351,7 @@ int pkgOrderList::FileCmp(PkgIterator A,PkgIterator B) if (Cache[A].InstVerIter(Cache).FileList().end() == true) return -1; - if (Cache[A].InstVerIter(Cache).FileList().end() == true) + if (Cache[B].InstVerIter(Cache).FileList().end() == true) return 1; pkgCache::PackageFile *FA = Cache[A].InstVerIter(Cache).FileList().File(); @@ -260,15 +363,40 @@ int pkgOrderList::FileCmp(PkgIterator A,PkgIterator B) return 0; } /*}}}*/ +// BoolCompare - Comparison function for two booleans /*{{{*/ +// --------------------------------------------------------------------- +/* */ +static int BoolCompare(bool A,bool B) +{ + if (A == B) + return 0; + if (A == false) + return -1; + return 1; +} + /*}}}*/ // OrderList::OrderCompareA - Order the installation by op /*{{{*/ // --------------------------------------------------------------------- /* This provides a first-pass sort of the list and gives a decent starting point for further complete ordering. It is used by OrderUnpack only */ -int pkgOrderList::OrderCompareA(const void *a, const void *b) +int pkgOrderList::OrderCompareA(Package *a, Package *b) { - PkgIterator A(Me->Cache,*(Package **)a); - PkgIterator B(Me->Cache,*(Package **)b); + PkgIterator A(Cache,a); + PkgIterator B(Cache,b); + // We order packages with a set state toward the front + int Res; + if ((Res = BoolCompare(IsNow(A),IsNow(B))) != 0) + return -1*Res; + + // We order missing files to toward the end +/* if (FileList != 0) + { + if ((Res = BoolCompare(IsMissing(A), + IsMissing(B))) != 0) + return Res; + }*/ + if (A.State() != pkgCache::PkgIterator::NeedsNothing && B.State() == pkgCache::PkgIterator::NeedsNothing) return -1; @@ -277,8 +405,9 @@ int pkgOrderList::OrderCompareA(const void *a, const void *b) B.State() != pkgCache::PkgIterator::NeedsNothing) return 1; - int ScoreA = Me->Score(A); - int ScoreB = Me->Score(B); + int ScoreA = Score(A); + int ScoreB = Score(B); + if (ScoreA > ScoreB) return -1; @@ -290,12 +419,12 @@ int pkgOrderList::OrderCompareA(const void *a, const void *b) /*}}}*/ // OrderList::OrderCompareB - Order the installation by source /*{{{*/ // --------------------------------------------------------------------- -/* This orders by installation source. This is usefull to handle +/* This orders by installation source. This is useful to handle inter-source breaks */ -int pkgOrderList::OrderCompareB(const void *a, const void *b) +int pkgOrderList::OrderCompareB(Package *a, Package *b) { - PkgIterator A(Me->Cache,*(Package **)a); - PkgIterator B(Me->Cache,*(Package **)b); + PkgIterator A(Cache,a); + PkgIterator B(Cache,b); if (A.State() != pkgCache::PkgIterator::NeedsNothing && B.State() == pkgCache::PkgIterator::NeedsNothing) @@ -305,7 +434,7 @@ int pkgOrderList::OrderCompareB(const void *a, const void *b) B.State() != pkgCache::PkgIterator::NeedsNothing) return 1; - int F = Me->FileCmp(A,B); + int F = FileCmp(A,B); if (F != 0) { if (F > 0) @@ -313,8 +442,9 @@ int pkgOrderList::OrderCompareB(const void *a, const void *b) return 1; } - int ScoreA = Me->Score(A); - int ScoreB = Me->Score(B); + int ScoreA = Score(A); + int ScoreB = Score(B); + if (ScoreA > ScoreB) return -1; @@ -324,7 +454,6 @@ int pkgOrderList::OrderCompareB(const void *a, const void *b) return strcmp(A.Name(),B.Name()); } /*}}}*/ - // OrderList::VisitDeps - Visit forward install dependencies /*{{{*/ // --------------------------------------------------------------------- /* This calls the dependency function for the normal forwards dependencies @@ -359,38 +488,76 @@ bool pkgOrderList::VisitRProvides(DepFunc F,VerIterator Ver) return true; bool Res = true; - for (PrvIterator P = Ver.ProvidesList(); P.end() == false; P++) + for (PrvIterator P = Ver.ProvidesList(); P.end() == false; ++P) Res &= (this->*F)(P.ParentPkg().RevDependsList()); - return true; + return Res; } /*}}}*/ // OrderList::VisitProvides - Visit all of the providing packages /*{{{*/ // --------------------------------------------------------------------- -/* This routine calls visit on all providing packages. */ -bool pkgOrderList::VisitProvides(DepIterator D) +/* This routine calls visit on all providing packages. + + If the dependency is negative it first visits packages which are + intended to be removed and after that all other packages. + It does so to avoid situations in which this package is used to + satisfy a (or-group/provides) dependency of another package which + could have been satisfied also by upgrading another package - + otherwise we have more broken packages dpkg needs to auto- + deconfigure and in very complicated situations it even decides + against it! */ +bool pkgOrderList::VisitProvides(DepIterator D,bool Critical) { - Version **List = D.AllTargets(); - for (Version **I = List; *I != 0; I++) + std::unique_ptr List(D.AllTargets()); + for (Version **I = List.get(); *I != 0; ++I) { VerIterator Ver(Cache,*I); PkgIterator Pkg = Ver.ParentPkg(); - - if (Cache[Pkg].Keep() == true) + + if (D.IsNegative() == true && Cache[Pkg].Delete() == false) continue; - - if (D->Type != pkgCache::Dep::Conflicts && Cache[Pkg].InstallVer != *I) + + if (Cache[Pkg].Keep() == true && Pkg.State() == PkgIterator::NeedsNothing) continue; - - if (D->Type == pkgCache::Dep::Conflicts && (Version *)Pkg.CurrentVer() != *I) + + if (D.IsNegative() == false && + Cache[Pkg].InstallVer != *I) continue; - - if (VisitNode(Pkg) == false) - { - delete [] List; + + if (D.IsNegative() == true && + (Version *)Pkg.CurrentVer() != *I) + continue; + + // Skip over missing files + if (Critical == false && IsMissing(D.ParentPkg()) == true) + continue; + + if (VisitNode(Pkg, "Provides-1") == false) return false; - } } - delete [] List; + if (D.IsNegative() == false) + return true; + for (Version **I = List.get(); *I != 0; ++I) + { + VerIterator Ver(Cache,*I); + PkgIterator Pkg = Ver.ParentPkg(); + + if (Cache[Pkg].Delete() == true) + continue; + + if (Cache[Pkg].Keep() == true && Pkg.State() == PkgIterator::NeedsNothing) + continue; + + if ((Version *)Pkg.CurrentVer() != *I) + continue; + + // Skip over missing files + if (Critical == false && IsMissing(D.ParentPkg()) == true) + continue; + + if (VisitNode(Pkg, "Provides-2") == false) + return false; + } + return true; } /*}}}*/ @@ -398,16 +565,21 @@ bool pkgOrderList::VisitProvides(DepIterator D) // --------------------------------------------------------------------- /* This is the core ordering routine. It calls the set dependency consideration functions which then potentialy call this again. Finite - depth is achived through the colouring mechinism. */ -bool pkgOrderList::VisitNode(PkgIterator Pkg) + depth is achieved through the colouring mechinism. */ +bool pkgOrderList::VisitNode(PkgIterator Pkg, char const* from) { - // Looping or irrelevent. + // Looping or irrelevant. + // This should probably trancend not installed packages if (Pkg.end() == true || IsFlag(Pkg,Added) == true || IsFlag(Pkg,AddPending) == true || IsFlag(Pkg,InList) == false) return true; -/* for (int j = 0; j != Depth; j++) cout << ' '; - cout << "Visit " << Pkg.Name() << endl;*/ + if (Debug == true) + { + for (int j = 0; j != Depth; j++) clog << ' '; + clog << "Visit " << Pkg.FullName() << " from " << from << endl; + } + Depth++; // Color grey @@ -416,53 +588,60 @@ bool pkgOrderList::VisitNode(PkgIterator Pkg) DepFunc Old = Primary; // Perform immedate configuration of the package if so flagged. - if (IsFlag(Pkg,Immediate) == true && Primary != &DepUnPackPre) - Primary = &DepUnPackPreD; - - bool Res = true; - if (Cache[Pkg].Delete() == false) + if (IsFlag(Pkg,Immediate) == true && Primary != &pkgOrderList::DepUnPackPre) + Primary = &pkgOrderList::DepUnPackPreD; + + if (IsNow(Pkg) == true) { - // Primary - Res &= Res && VisitDeps(Primary,Pkg); - Res &= Res && VisitRDeps(Primary,Pkg); - Res &= Res && VisitRProvides(Primary,Pkg.CurrentVer()); - Res &= Res && VisitRProvides(Primary,Cache[Pkg].InstVerIter(Cache)); - - // RevDep - Res &= Res && VisitRDeps(RevDepends,Pkg); - Res &= Res && VisitRProvides(RevDepends,Pkg.CurrentVer()); - Res &= Res && VisitRProvides(RevDepends,Cache[Pkg].InstVerIter(Cache)); - - // Secondary - Res &= Res && VisitDeps(Secondary,Pkg); - Res &= Res && VisitRDeps(Secondary,Pkg); - Res &= Res && VisitRProvides(Secondary,Pkg.CurrentVer()); - Res &= Res && VisitRProvides(Secondary,Cache[Pkg].InstVerIter(Cache)); - } - else - { - // RevDep - Res &= Res && VisitRDeps(Remove,Pkg); - Res &= Res && VisitRProvides(Remove,Pkg.CurrentVer()); + bool Res = true; + if (Cache[Pkg].Delete() == false) + { + // Primary + Res &= Res && VisitDeps(Primary,Pkg); + Res &= Res && VisitRDeps(Primary,Pkg); + Res &= Res && VisitRProvides(Primary,Pkg.CurrentVer()); + Res &= Res && VisitRProvides(Primary,Cache[Pkg].InstVerIter(Cache)); + + // RevDep + Res &= Res && VisitRDeps(RevDepends,Pkg); + Res &= Res && VisitRProvides(RevDepends,Pkg.CurrentVer()); + Res &= Res && VisitRProvides(RevDepends,Cache[Pkg].InstVerIter(Cache)); + + // Secondary + Res &= Res && VisitDeps(Secondary,Pkg); + Res &= Res && VisitRDeps(Secondary,Pkg); + Res &= Res && VisitRProvides(Secondary,Pkg.CurrentVer()); + Res &= Res && VisitRProvides(Secondary,Cache[Pkg].InstVerIter(Cache)); + } + else + { + // RevDep + Res &= Res && VisitRDeps(Remove,Pkg); + Res &= Res && VisitRProvides(Remove,Pkg.CurrentVer()); + } } - + if (IsFlag(Pkg,Added) == false) { Flag(Pkg,Added,Added | AddPending); - *End = Pkg; - End++; + if (IsFlag(Pkg,After) == true) + *AfterEnd++ = Pkg; + else + *End++ = Pkg; } Primary = Old; Depth--; - -/* for (int j = 0; j != Depth; j++) cout << ' '; - cout << "Leave " << Pkg.Name() << ' ' << IsFlag(Pkg,Added) << ',' << IsFlag(Pkg,AddPending) << endl;*/ + if (Debug == true) + { + for (int j = 0; j != Depth; j++) clog << ' '; + clog << "Leave " << Pkg.FullName() << ' ' << IsFlag(Pkg,Added) << ',' << IsFlag(Pkg,AddPending) << endl; + } + return true; } /*}}}*/ - // OrderList::DepUnPackCrit - Critical UnPacking ordering /*{{{*/ // --------------------------------------------------------------------- /* Critical unpacking ordering strives to satisfy Conflicts: and @@ -472,13 +651,14 @@ bool pkgOrderList::VisitNode(PkgIterator Pkg) Loops are preprocessed and logged. */ bool pkgOrderList::DepUnPackCrit(DepIterator D) { - for (; D.end() == false; D++) + for (; D.end() == false; ++D) { if (D.Reverse() == true) { /* Reverse depenanices are only interested in conflicts, predepend breakage is ignored here */ - if (D->Type != pkgCache::Dep::Conflicts) + if (D->Type != pkgCache::Dep::Conflicts && + D->Type != pkgCache::Dep::Obsoletes) continue; // Duplication elimination, consider only the current version @@ -492,14 +672,15 @@ bool pkgOrderList::DepUnPackCrit(DepIterator D) if (CheckDep(D) == true) continue; - if (VisitNode(D.ParentPkg()) == false) + if (VisitNode(D.ParentPkg(), "UnPackCrit") == false) return false; } else { /* Forward critical dependencies MUST be correct before the package can be unpacked. */ - if (D->Type != pkgCache::Dep::Conflicts && D->Type != pkgCache::Dep::PreDepends) + if (D.IsNegative() == false && + D->Type != pkgCache::Dep::PreDepends) continue; /* We wish to check if the dep is okay in the now state of the @@ -527,8 +708,8 @@ bool pkgOrderList::DepUnPackCrit(DepIterator D) DepFunc Old = Primary; bool Res = false; if (D->Type == pkgCache::Dep::PreDepends) - Primary = &DepUnPackPreD; - Res = VisitProvides(D); + Primary = &pkgOrderList::DepUnPackPreD; + Res = VisitProvides(D,true); Primary = Old; if (Res == false) return false; @@ -541,15 +722,14 @@ bool pkgOrderList::DepUnPackCrit(DepIterator D) // --------------------------------------------------------------------- /* Critical PreDepends (also configure immediate and essential) strives to ensure not only that all conflicts+predepends are met but that this - package will be immediately configurable when it is unpacked. - + package will be immediately configurable when it is unpacked. Loops are preprocessed and logged. */ bool pkgOrderList::DepUnPackPreD(DepIterator D) { if (D.Reverse() == true) return DepUnPackCrit(D); - for (; D.end() == false; D++) + for (; D.end() == false; ++D) { if (D.IsCritical() == false) continue; @@ -574,7 +754,7 @@ bool pkgOrderList::DepUnPackPreD(DepIterator D) continue; } - if (VisitProvides(D) == false) + if (VisitProvides(D,true) == false) return false; } return true; @@ -592,7 +772,7 @@ bool pkgOrderList::DepUnPackPre(DepIterator D) if (D.Reverse() == true) return true; - for (; D.end() == false; D++) + for (; D.end() == false; ++D) { /* Only consider the PreDepends or Depends. Depends are only considered at the lowest depth or in the case of immediate @@ -607,7 +787,7 @@ bool pkgOrderList::DepUnPackPre(DepIterator D) else continue; } - + /* We wish to check if the dep is okay in the now state of the target package against the install state of this package. */ if (CheckDep(D) == true) @@ -617,7 +797,7 @@ bool pkgOrderList::DepUnPackPre(DepIterator D) if (IsFlag(D.TargetPkg(),AddPending) == false) continue; } - + // This is the loop detection if (IsFlag(D.TargetPkg(),Added) == true || IsFlag(D.TargetPkg(),AddPending) == true) @@ -627,7 +807,7 @@ bool pkgOrderList::DepUnPackPre(DepIterator D) continue; } - if (VisitProvides(D) == false) + if (VisitProvides(D,true) == false) return false; } return true; @@ -643,11 +823,11 @@ bool pkgOrderList::DepUnPackPre(DepIterator D) The forwards depends loop is designed to bring the packages dependents close to the package. This helps reduce deconfigure time. - Loops are irrelevent to this. */ + Loops are irrelevant to this. */ bool pkgOrderList::DepUnPackDep(DepIterator D) { - for (; D.end() == false; D++) + for (; D.end() == false; ++D) if (D.IsCritical() == true) { if (D.Reverse() == true) @@ -659,17 +839,32 @@ bool pkgOrderList::DepUnPackDep(DepIterator D) D.ParentPkg().CurrentVer() != D.ParentVer()) continue; - // The dep will not break so it is irrelevent. + // The dep will not break so it is irrelevant. if (CheckDep(D) == true) continue; - if (VisitNode(D.ParentPkg()) == false) + // Skip over missing files + if (IsMissing(D.ParentPkg()) == true) + continue; + + if (VisitNode(D.ParentPkg(), "UnPackDep-Parent") == false) return false; } else + { if (D->Type == pkgCache::Dep::Depends) - if (VisitProvides(D) == false) + if (VisitProvides(D,false) == false) return false; + + if (D->Type == pkgCache::Dep::DpkgBreaks) + { + if (CheckDep(D) == true) + continue; + + if (VisitNode(D.TargetPkg(), "UnPackDep-Target") == false) + return false; + } + } } return true; } @@ -687,61 +882,148 @@ bool pkgOrderList::DepConfigure(DepIterator D) if (D.Reverse() == true) return true; - for (; D.end() == false; D++) + for (; D.end() == false; ++D) if (D->Type == pkgCache::Dep::Depends) - if (VisitProvides(D) == false) + if (VisitProvides(D,false) == false) return false; return true; } /*}}}*/ // OrderList::DepRemove - Removal ordering /*{{{*/ // --------------------------------------------------------------------- -/* Removal visits all reverse depends. It considers if the dependency - of the Now state version to see if it is okay with removing this - package. This check should always fail, but is provided for symetery - with the other critical handlers. - - Loops are preprocessed and logged. Removal loops can also be - detected in the critical handler. They are characterized by an - old version of A depending on B but the new version of A conflicting - with B, thus either A or B must break to install. */ -bool pkgOrderList::DepRemove(DepIterator D) +/* Checks all given dependencies if they are broken by the remove of a + package and if so fix it by visiting another provider or or-group + member to ensure that the dependee keeps working which is especially + important for Immediate packages like e.g. those depending on an + awk implementation. If the dependency can't be fixed with another + package this means an upgrade of the package will solve the problem. */ +bool pkgOrderList::DepRemove(DepIterator Broken) { - if (D.Reverse() == false) + if (Broken.Reverse() == false) return true; - for (; D.end() == false; D++) - if (D->Type == pkgCache::Dep::Depends || D->Type == pkgCache::Dep::PreDepends) + + for (; Broken.end() == false; ++Broken) + { + if (Broken->Type != pkgCache::Dep::Depends && + Broken->Type != pkgCache::Dep::PreDepends) + continue; + + PkgIterator BrokenPkg = Broken.ParentPkg(); + // uninstalled packages can't break via a remove + if (BrokenPkg->CurrentVer == 0) + continue; + + // if its already added, we can't do anything useful + if (IsFlag(BrokenPkg, AddPending) == true || IsFlag(BrokenPkg, Added) == true) + continue; + + // if the dependee is going to be removed, visit it now + if (Cache[BrokenPkg].Delete() == true) + return VisitNode(BrokenPkg, "Remove-Dependee"); + + // The package stays around, so find out how this is possible + for (DepIterator D = BrokenPkg.CurrentVer().DependsList(); D.end() == false;) { - // Duplication elimination, consider the current version only - if (D.ParentPkg().CurrentVer() != D.ParentVer()) + // only important or-groups need fixing + if (D->Type != pkgCache::Dep::Depends && + D->Type != pkgCache::Dep::PreDepends) + { + ++D; continue; + } - /* We wish to see if the dep on the parent package is okay - in the removed (install) state of the target pkg. */ - if (CheckDep(D) == true) + // Start is the beginning of the or-group, D is the first one after or + DepIterator Start = D; + bool foundBroken = false; + for (bool LastOR = true; D.end() == false && LastOR == true; ++D) { - // We want to catch loops with the code below. - if (IsFlag(D.ParentPkg(),AddPending) == false) - continue; + LastOR = (D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or; + if (D == Broken) + foundBroken = true; } - // This is the loop detection - if (IsFlag(D.ParentPkg(),Added) == true || - IsFlag(D.ParentPkg(),AddPending) == true) + // this or-group isn't the broken one: keep searching + if (foundBroken == false) + continue; + + // iterate over all members of the or-group searching for a ready replacement + bool readyReplacement = false; + for (DepIterator OrMember = Start; OrMember != D && readyReplacement == false; ++OrMember) { - if (IsFlag(D.ParentPkg(),AddPending) == true) - AddLoop(D); + Version ** Replacements = OrMember.AllTargets(); + for (Version **R = Replacements; *R != 0; ++R) + { + VerIterator Ver(Cache,*R); + // only currently installed packages can be a replacement + PkgIterator RPkg = Ver.ParentPkg(); + if (RPkg.CurrentVer() != Ver) + continue; + + // packages going to be removed can't be a replacement + if (Cache[RPkg].Delete() == true) + continue; + + readyReplacement = true; + break; + } + delete[] Replacements; + } + + // something else is ready to take over, do nothing + if (readyReplacement == true) continue; + + // see if we can visit a replacement + bool visitReplacement = false; + for (DepIterator OrMember = Start; OrMember != D && visitReplacement == false; ++OrMember) + { + Version ** Replacements = OrMember.AllTargets(); + for (Version **R = Replacements; *R != 0; ++R) + { + VerIterator Ver(Cache,*R); + // consider only versions we plan to install + PkgIterator RPkg = Ver.ParentPkg(); + if (Cache[RPkg].Install() == false || Cache[RPkg].InstallVer != Ver) + continue; + + // loops are not going to help us, so don't create them + if (IsFlag(RPkg, AddPending) == true) + continue; + + if (IsMissing(RPkg) == true) + continue; + + visitReplacement = true; + if (IsFlag(BrokenPkg, Immediate) == false) + { + if (VisitNode(RPkg, "Remove-Rep") == true) + break; + } + else + { + Flag(RPkg, Immediate); + if (VisitNode(RPkg, "Remove-ImmRep") == true) + break; + } + visitReplacement = false; + } + delete[] Replacements; } + if (visitReplacement == true) + continue; - if (VisitNode(D.ParentPkg()) == false) + // the broken package in current version can't be fixed, so install new version + if (IsMissing(BrokenPkg) == true) + break; + + if (VisitNode(BrokenPkg, "Remove-Upgrade") == false) return false; } - + } + return true; } /*}}}*/ - // OrderList::AddLoop - Add a loop to the loop list /*{{{*/ // --------------------------------------------------------------------- /* We record the loops. This is a relic since loop breaking is done @@ -762,8 +1044,10 @@ bool pkgOrderList::AddLoop(DepIterator D) Loops[LoopCount++] = D; // Mark the packages as being part of a loop. - Flag(D.TargetPkg(),Loop); - Flag(D.ParentPkg(),Loop); + //Flag(D.TargetPkg(),Loop); + //Flag(D.ParentPkg(),Loop); + /* This is currently disabled because the Loop flag is being used for + loop management in the package manager. Check the orderlist.h file for more info */ return true; } /*}}}*/ @@ -772,7 +1056,7 @@ bool pkgOrderList::AddLoop(DepIterator D) /* */ void pkgOrderList::WipeFlags(unsigned long F) { - unsigned long Size = Cache.HeaderP->PackageCount; + unsigned long Size = Cache.Head().PackageCount; for (unsigned long I = 0; I != Size; I++) Flags[I] &= ~F; } @@ -786,8 +1070,9 @@ void pkgOrderList::WipeFlags(unsigned long F) this fails to produce a suitable result. */ bool pkgOrderList::CheckDep(DepIterator D) { - Version **List = D.AllTargets(); - for (Version **I = List; *I != 0; I++) + std::unique_ptr List(D.AllTargets()); + bool Hit = false; + for (Version **I = List.get(); *I != 0; I++) { VerIterator Ver(Cache,*I); PkgIterator Pkg = Ver.ParentPkg(); @@ -797,8 +1082,8 @@ bool pkgOrderList::CheckDep(DepIterator D) way ordering works Added means the package will be unpacked before this one and AddPending means after. It is therefore correct to ignore AddPending in all cases, but that exposes - reverse-ordering loops which should be ignore. */ - if (IsFlag(Pkg,Added) == true || + reverse-ordering loops which should be ignored. */ + if (IsFlag(Pkg,Added) == true || (IsFlag(Pkg,AddPending) == true && D.Reverse() == true)) { if (Cache[Pkg].InstallVer != *I) @@ -809,20 +1094,46 @@ bool pkgOrderList::CheckDep(DepIterator D) Pkg.State() != PkgIterator::NeedsNothing) continue; - delete [] List; - /* Conflicts requires that all versions are not present, depends just needs one */ - if (D->Type != pkgCache::Dep::Conflicts) + if (D.IsNegative() == false) + { + // ignore provides by older versions of this package + if (((D.Reverse() == false && Pkg == D.ParentPkg()) || + (D.Reverse() == true && Pkg == D.TargetPkg())) && + Cache[Pkg].InstallVer != *I) + continue; + + /* Try to find something that does not have the after flag set + if at all possible */ + if (IsFlag(Pkg,After) == true) + { + Hit = true; + continue; + } + return true; + } else + { + if (IsFlag(Pkg,After) == true) + Flag(D.ParentPkg(),After); + return false; + } } - delete [] List; - + + // We found a hit, but it had the after flag set + if (Hit == true && D->Type == pkgCache::Dep::PreDepends) + { + Flag(D.ParentPkg(),After); + return true; + } + /* Conflicts requires that all versions are not present, depends just needs one */ - if (D->Type == pkgCache::Dep::Conflicts) + if (D->Type == pkgCache::Dep::Conflicts || + D->Type == pkgCache::Dep::Obsoletes) return true; return false; }