X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/f408836a80f20359c87d8815608af651199e3d73..ea50fdfe2fc21757412baf448b2d41b3ce34b626:/apt-pkg/algorithms.cc diff --git a/apt-pkg/algorithms.cc b/apt-pkg/algorithms.cc index a3963d546..5fbcb47be 100644 --- a/apt-pkg/algorithms.cc +++ b/apt-pkg/algorithms.cc @@ -58,7 +58,7 @@ void pkgSimulate::Describe(PkgIterator Pkg,ostream &out,bool Current,bool Candid { VerIterator Ver(Sim); - out << Pkg.Name(); + out << Pkg.FullName(true); if (Current == true) { @@ -83,15 +83,15 @@ void pkgSimulate::Describe(PkgIterator Pkg,ostream &out,bool Current,bool Candid bool pkgSimulate::Install(PkgIterator iPkg,string /*File*/) { // Adapt the iterator - PkgIterator Pkg = Sim.FindPkg(iPkg.Name()); + PkgIterator Pkg = Sim.FindPkg(iPkg.Name(), iPkg.Arch()); Flags[Pkg->ID] = 1; cout << "Inst "; Describe(Pkg,cout,true,true); Sim.MarkInstall(Pkg,false); - + // Look for broken conflicts+predepends. - for (PkgIterator I = Sim.PkgBegin(); I.end() == false; I++) + for (PkgIterator I = Sim.PkgBegin(); I.end() == false; ++I) { if (Sim[I].InstallVer == 0) continue; @@ -101,16 +101,14 @@ bool pkgSimulate::Install(PkgIterator iPkg,string /*File*/) DepIterator Start; DepIterator End; D.GlobOr(Start,End); - if (Start->Type == pkgCache::Dep::Conflicts || - Start->Type == pkgCache::Dep::DpkgBreaks || - Start->Type == pkgCache::Dep::Obsoletes || + if (Start.IsNegative() == true || End->Type == pkgCache::Dep::PreDepends) { if ((Sim[End] & pkgDepCache::DepGInstall) == 0) { - cout << " [" << I.Name() << " on " << Start.TargetPkg().Name() << ']'; + cout << " [" << I.FullName(false) << " on " << Start.TargetPkg().FullName(false) << ']'; if (Start->Type == pkgCache::Dep::Conflicts) - _error->Error("Fatal, conflicts violated %s",I.Name()); + _error->Error("Fatal, conflicts violated %s",I.FullName(false).c_str()); } } } @@ -131,35 +129,35 @@ bool pkgSimulate::Install(PkgIterator iPkg,string /*File*/) bool pkgSimulate::Configure(PkgIterator iPkg) { // Adapt the iterator - PkgIterator Pkg = Sim.FindPkg(iPkg.Name()); + PkgIterator Pkg = Sim.FindPkg(iPkg.Name(), iPkg.Arch()); Flags[Pkg->ID] = 2; -// Sim.MarkInstall(Pkg,false); + if (Sim[Pkg].InstBroken() == true) { - cout << "Conf " << Pkg.Name() << " broken" << endl; + cout << "Conf " << Pkg.FullName(false) << " broken" << endl; Sim.Update(); // Print out each package and the failed dependencies - for (pkgCache::DepIterator D = Sim[Pkg].InstVerIter(Sim).DependsList(); D.end() == false; D++) + for (pkgCache::DepIterator D = Sim[Pkg].InstVerIter(Sim).DependsList(); D.end() == false; ++D) { if (Sim.IsImportantDep(D) == false || (Sim[D] & pkgDepCache::DepInstall) != 0) continue; if (D->Type == pkgCache::Dep::Obsoletes) - cout << " Obsoletes:" << D.TargetPkg().Name(); + cout << " Obsoletes:" << D.TargetPkg().FullName(false); else if (D->Type == pkgCache::Dep::Conflicts) - cout << " Conflicts:" << D.TargetPkg().Name(); + cout << " Conflicts:" << D.TargetPkg().FullName(false); else if (D->Type == pkgCache::Dep::DpkgBreaks) - cout << " Breaks:" << D.TargetPkg().Name(); + cout << " Breaks:" << D.TargetPkg().FullName(false); else - cout << " Depends:" << D.TargetPkg().Name(); + cout << " Depends:" << D.TargetPkg().FullName(false); } cout << endl; - _error->Error("Conf Broken %s",Pkg.Name()); + _error->Error("Conf Broken %s",Pkg.FullName(false).c_str()); } else { @@ -181,10 +179,11 @@ bool pkgSimulate::Configure(PkgIterator iPkg) bool pkgSimulate::Remove(PkgIterator iPkg,bool Purge) { // Adapt the iterator - PkgIterator Pkg = Sim.FindPkg(iPkg.Name()); + PkgIterator Pkg = Sim.FindPkg(iPkg.Name(), iPkg.Arch()); Flags[Pkg->ID] = 3; Sim.MarkDelete(Pkg); + if (Purge == true) cout << "Purg "; else @@ -205,12 +204,12 @@ bool pkgSimulate::Remove(PkgIterator iPkg,bool Purge) void pkgSimulate::ShortBreaks() { cout << " ["; - for (PkgIterator I = Sim.PkgBegin(); I.end() == false; I++) + for (PkgIterator I = Sim.PkgBegin(); I.end() == false; ++I) { if (Sim[I].InstBroken() == true) { if (Flags[I->ID] == 0) - cout << I.Name() << ' '; + cout << I.FullName(false) << ' '; /* else cout << I.Name() << "! ";*/ } @@ -227,7 +226,7 @@ bool pkgApplyStatus(pkgDepCache &Cache) { pkgDepCache::ActionGroup group(Cache); - for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++) + for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I) { if (I->VersionList == 0) continue; @@ -246,7 +245,7 @@ bool pkgApplyStatus(pkgDepCache &Cache) Cache.MarkInstall(I, false, 0, false); else return _error->Error(_("The package %s needs to be reinstalled, " - "but I can't find an archive for it."),I.Name()); + "but I can't find an archive for it."),I.FullName(true).c_str()); } continue; @@ -281,7 +280,7 @@ bool pkgApplyStatus(pkgDepCache &Cache) default: if (I->InstState != pkgCache::State::Ok) return _error->Error("The package %s is not ok and I " - "don't know how to fix it!",I.Name()); + "don't know how to fix it!",I.FullName(false).c_str()); } } return true; @@ -296,13 +295,13 @@ bool pkgFixBroken(pkgDepCache &Cache) pkgDepCache::ActionGroup group(Cache); // Auto upgrade all broken packages - for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++) + for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I) if (Cache[I].NowBroken() == true) Cache.MarkInstall(I, true, 0, false); /* Fix packages that are in a NeedArchive state but don't have a downloadable install version */ - for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++) + for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I) { if (I.State() != pkgCache::PkgIterator::NeedsUnpack || Cache[I].Delete() == true) @@ -330,21 +329,28 @@ bool pkgDistUpgrade(pkgDepCache &Cache) { pkgDepCache::ActionGroup group(Cache); + /* Upgrade all installed packages first without autoinst to help the resolver + in versioned or-groups to upgrade the old solver instead of installing + a new one (if the old solver is not the first one [anymore]) */ + for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I) + if (I->CurrentVer != 0) + Cache.MarkInstall(I, false, 0, false); + /* Auto upgrade all installed packages, this provides the basis for the installation */ - for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++) + for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I) if (I->CurrentVer != 0) Cache.MarkInstall(I, true, 0, false); /* Now, auto upgrade all essential packages - this ensures that the essential packages are present and working */ - for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++) + for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I) if ((I->Flags & pkgCache::Flag::Essential) == pkgCache::Flag::Essential) Cache.MarkInstall(I, true, 0, false); /* We do it again over all previously installed packages to force conflict resolution on them all. */ - for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++) + for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I) if (I->CurrentVer != 0) Cache.MarkInstall(I, false, 0, false); @@ -353,7 +359,7 @@ bool pkgDistUpgrade(pkgDepCache &Cache) // Hold back held packages. if (_config->FindB("APT::Ignore-Hold",false) == false) { - for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++) + for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I) { if (I->SelectedState == pkgCache::State::Hold) { @@ -381,7 +387,7 @@ bool pkgAllUpgrade(pkgDepCache &Cache) return false; // Upgrade all installed packages - for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++) + for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I) { if (Cache[I].Install() == true) Fix.Protect(I); @@ -415,7 +421,7 @@ bool pkgMinimizeUpgrade(pkgDepCache &Cache) do { Change = false; - for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++) + for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I) { // Not interesting if (Cache[I].Upgrade() == false || Cache[I].NewInstall() == true) @@ -432,7 +438,7 @@ bool pkgMinimizeUpgrade(pkgDepCache &Cache) Change = true; } } - Count++; + ++Count; } while (Change == true && Count < 10); @@ -491,11 +497,11 @@ void pkgProblemResolver::MakeScores() // Important Required Standard Optional Extra signed short PrioMap[] = { 0, - _config->FindI("pkgProblemResolver::Scores::Important",3), - _config->FindI("pkgProblemResolver::Scores::Required",2), - _config->FindI("pkgProblemResolver::Scores::Standard",1), - _config->FindI("pkgProblemResolver::Scores::Optional",-1), - _config->FindI("pkgProblemResolver::Scores::Extra",-2) + (signed short) _config->FindI("pkgProblemResolver::Scores::Important",3), + (signed short) _config->FindI("pkgProblemResolver::Scores::Required",2), + (signed short) _config->FindI("pkgProblemResolver::Scores::Standard",1), + (signed short) _config->FindI("pkgProblemResolver::Scores::Optional",-1), + (signed short) _config->FindI("pkgProblemResolver::Scores::Extra",-2) }; signed short PrioEssentials = _config->FindI("pkgProblemResolver::Scores::Essentials",100); signed short PrioInstalledAndNotObsolete = _config->FindI("pkgProblemResolver::Scores::NotObsolete",1); @@ -519,7 +525,7 @@ void pkgProblemResolver::MakeScores() << " AddEssential => " << AddEssential << endl; // Generate the base scores for a package based on its properties - for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++) + for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I) { if (Cache[I].InstallVer == 0) continue; @@ -546,12 +552,12 @@ void pkgProblemResolver::MakeScores() } // Now that we have the base scores we go and propogate dependencies - for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++) + for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I) { if (Cache[I].InstallVer == 0) continue; - for (pkgCache::DepIterator D = Cache[I].InstVerIter(Cache).DependsList(); D.end() == false; D++) + for (pkgCache::DepIterator D = Cache[I].InstVerIter(Cache).DependsList(); D.end() == false; ++D) { if (D->Type == pkgCache::Dep::Depends || D->Type == pkgCache::Dep::PreDepends) @@ -568,12 +574,12 @@ void pkgProblemResolver::MakeScores() /* Now we cause 1 level of dependency inheritance, that is we add the score of the packages that depend on the target Package. This fortifies high scoring packages */ - for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++) + for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I) { if (Cache[I].InstallVer == 0) continue; - for (pkgCache::DepIterator D = I.RevDependsList(); D.end() == false; D++) + for (pkgCache::DepIterator D = I.RevDependsList(); D.end() == false; ++D) { // Only do it for the install version if ((pkgCache::Version *)D.ParentVer() != Cache[D.ParentPkg()].InstallVer || @@ -588,9 +594,9 @@ void pkgProblemResolver::MakeScores() /* Now we propogate along provides. This makes the packages that provide important packages extremely important */ - for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++) + for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I) { - for (pkgCache::PrvIterator P = I.ProvidesList(); P.end() == false; P++) + for (pkgCache::PrvIterator P = I.ProvidesList(); P.end() == false; ++P) { // Only do it once per package if ((pkgCache::Version *)P.OwnerVer() != Cache[P.OwnerPkg()].InstallVer) @@ -601,7 +607,7 @@ void pkgProblemResolver::MakeScores() /* Protected things are pushed really high up. This number should put them ahead of everything */ - for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++) + for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I) { if ((Flags[I->ID] & Protected) != 0) Scores[I->ID] += AddProtected; @@ -639,12 +645,10 @@ bool pkgProblemResolver::DoUpgrade(pkgCache::PkgIterator Pkg) // Compute a single dependency element (glob or) pkgCache::DepIterator Start = D; pkgCache::DepIterator End = D; - unsigned char State = 0; for (bool LastOR = true; D.end() == false && LastOR == true;) { - State |= Cache[D]; LastOR = (D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or; - D++; + ++D; if (LastOR == true) End = D; } @@ -665,7 +669,7 @@ bool pkgProblemResolver::DoUpgrade(pkgCache::PkgIterator Pkg) if ((Flags[P->ID] & Protected) == Protected) { if (Debug == true) - clog << " Reinst Failed because of protected " << P.Name() << endl; + clog << " Reinst Failed because of protected " << P.FullName(false) << endl; Fail = true; } else @@ -676,7 +680,7 @@ bool pkgProblemResolver::DoUpgrade(pkgCache::PkgIterator Pkg) if (DoUpgrade(P) == false) { if (Debug == true) - clog << " Reinst Failed because of " << P.Name() << endl; + clog << " Reinst Failed because of " << P.FullName(false) << endl; Fail = true; } else @@ -689,20 +693,18 @@ bool pkgProblemResolver::DoUpgrade(pkgCache::PkgIterator Pkg) { /* We let the algorithm deal with conflicts on its next iteration, it is much smarter than us */ - if (Start->Type == pkgCache::Dep::Conflicts || - Start->Type == pkgCache::Dep::DpkgBreaks || - Start->Type == pkgCache::Dep::Obsoletes) + if (Start.IsNegative() == true) break; if (Debug == true) - clog << " Reinst Failed early because of " << Start.TargetPkg().Name() << endl; + clog << " Reinst Failed early because of " << Start.TargetPkg().FullName(false) << endl; Fail = true; } } if (Start == End) break; - Start++; + ++Start; } if (Fail == true) break; @@ -719,7 +721,7 @@ bool pkgProblemResolver::DoUpgrade(pkgCache::PkgIterator Pkg) } if (Debug == true) - clog << " Re-Instated " << Pkg.Name() << endl; + clog << " Re-Instated " << Pkg.FullName(false) << endl; return true; } /*}}}*/ @@ -748,7 +750,7 @@ bool pkgProblemResolver::Resolve(bool BrokenFix) do { Again = false; - for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++) + for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I) { if (Cache[I].Install() == true) Flags[I->ID] |= PreInstalled; @@ -779,7 +781,7 @@ bool pkgProblemResolver::Resolve(bool BrokenFix) would cause the removal of even lower score packages. */ SPtrArray PList = new pkgCache::Package *[Size]; pkgCache::Package **PEnd = PList; - for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++) + for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I) *PEnd++ = I; This = this; qsort(PList,PEnd - PList,sizeof(*PList),&ScoreSort); @@ -803,6 +805,7 @@ bool pkgProblemResolver::Resolve(bool BrokenFix) not be possible for a loop to form (that is a < b < c and fixing b by changing a breaks c) */ bool Change = true; + bool const TryFixByInstall = _config->FindB("pkgProblemResolver::FixByInstall", true); for (int Counter = 0; Counter != 10 && Change == true; Counter++) { Change = false; @@ -819,7 +822,7 @@ bool pkgProblemResolver::Resolve(bool BrokenFix) (Flags[I->ID] & ReInstateTried) == 0) { if (Debug == true) - clog << " Try to Re-Instate " << I.Name() << endl; + clog << " Try to Re-Instate (" << Counter << ") " << I.FullName(false) << endl; unsigned long OldBreaks = Cache.BrokenCount(); pkgCache::Version *OldVer = Cache[I].InstallVer; Flags[I->ID] &= ReInstateTried; @@ -835,14 +838,14 @@ bool pkgProblemResolver::Resolve(bool BrokenFix) } else if (Debug == true) - clog << "Re-Instated " << I.Name() << " (" << OldBreaks << " vs " << Cache.BrokenCount() << ')' << endl; + clog << "Re-Instated " << I.FullName(false) << " (" << OldBreaks << " vs " << Cache.BrokenCount() << ')' << endl; } if (Cache[I].InstallVer == 0 || Cache[I].InstBroken() == false) continue; if (Debug == true) - clog << "Investigating " << I.Name() << endl; + clog << "Investigating (" << Counter << ") " << I << endl; // Isolate the problem dependency PackageKill KillList[100]; @@ -860,22 +863,22 @@ bool pkgProblemResolver::Resolve(bool BrokenFix) if (Start == End) { // Decide what to do - if (InOr == true) + if (InOr == true && OldEnd == LEnd) { - if (OldEnd == LEnd && OrOp == OrRemove) + if (OrOp == OrRemove) { if ((Flags[I->ID] & Protected) != Protected) { if (Debug == true) - clog << " Or group remove for " << I.Name() << endl; + clog << " Or group remove for " << I.FullName(false) << endl; Cache.MarkDelete(I); Change = true; - } - } - if (OldEnd == LEnd && OrOp == OrKeep) + } + } + else if (OrOp == OrKeep) { if (Debug == true) - clog << " Or group keep for " << I.Name() << endl; + clog << " Or group keep for " << I.FullName(false) << endl; Cache.MarkKeep(I, false, false); Change = true; } @@ -898,7 +901,7 @@ bool pkgProblemResolver::Resolve(bool BrokenFix) } else { - Start++; + ++Start; // We only worry about critical deps. if (Start.IsCritical() != true) continue; @@ -912,16 +915,14 @@ bool pkgProblemResolver::Resolve(bool BrokenFix) } if (Debug == true) - clog << "Package " << I.Name() << " has broken " << Start.DepType() << " on " << Start.TargetPkg().Name() << endl; + clog << "Broken " << Start << endl; /* Look across the version list. If there are no possible targets then we keep the package and bail. This is necessary if a package has a dep on another package that cant be found */ SPtrArray VList = Start.AllTargets(); if (*VList == 0 && (Flags[I->ID] & Protected) != Protected && - Start->Type != pkgCache::Dep::Conflicts && - Start->Type != pkgCache::Dep::DpkgBreaks && - Start->Type != pkgCache::Dep::Obsoletes && + Start.IsNegative() == false && Cache[I].NowBroken() == false) { if (InOr == true) @@ -942,17 +943,29 @@ bool pkgProblemResolver::Resolve(bool BrokenFix) pkgCache::VerIterator Ver(Cache,*V); pkgCache::PkgIterator Pkg = Ver.ParentPkg(); + /* This is a conflicts, and the version we are looking + at is not the currently selected version of the + package, which means it is not necessary to + remove/keep */ + if (Cache[Pkg].InstallVer != Ver && Start.IsNegative() == true) + { + if (Debug) + clog << " Conflicts//Breaks against version " + << Ver.VerStr() << " for " << Pkg.Name() + << " but that is not InstVer, ignoring" + << endl; + continue; + } + if (Debug == true) - clog << " Considering " << Pkg.Name() << ' ' << (int)Scores[Pkg->ID] << - " as a solution to " << I.Name() << ' ' << (int)Scores[I->ID] << endl; + clog << " Considering " << Pkg.FullName(false) << ' ' << (int)Scores[Pkg->ID] << + " as a solution to " << I.FullName(false) << ' ' << (int)Scores[I->ID] << endl; /* Try to fix the package under consideration rather than fiddle with the VList package */ if (Scores[I->ID] <= Scores[Pkg->ID] || ((Cache[Start] & pkgDepCache::DepNow) == 0 && - End->Type != pkgCache::Dep::Conflicts && - End->Type != pkgCache::Dep::DpkgBreaks && - End->Type != pkgCache::Dep::Obsoletes)) + End.IsNegative() == false)) { // Try a little harder to fix protected packages.. if ((Flags[I->ID] & Protected) == Protected) @@ -982,7 +995,7 @@ bool pkgProblemResolver::Resolve(bool BrokenFix) Cache.MarkInstall(I, false, 0, false); if (Debug == true) - clog << " Holding Back " << I.Name() << " rather than change " << Start.TargetPkg().Name() << endl; + clog << " Holding Back " << I.FullName(false) << " rather than change " << Start.TargetPkg().FullName(false) << endl; } else { @@ -992,11 +1005,30 @@ bool pkgProblemResolver::Resolve(bool BrokenFix) if (InOr == false) { if (Debug == true) - clog << " Removing " << I.Name() << " rather than change " << Start.TargetPkg().Name() << endl; + clog << " Removing " << I.FullName(false) << " rather than change " << Start.TargetPkg().FullName(false) << endl; Cache.MarkDelete(I); if (Counter > 1 && Scores[Pkg->ID] > Scores[I->ID]) Scores[I->ID] = Scores[Pkg->ID]; } + else if (TryFixByInstall == true && + Start.TargetPkg()->CurrentVer == 0 && + Cache[Start.TargetPkg()].Delete() == false && + (Flags[Start.TargetPkg()->ID] & ToRemove) != ToRemove && + Cache.GetCandidateVer(Start.TargetPkg()).end() == false) + { + /* Before removing or keeping the package with the broken dependency + try instead to install the first not previously installed package + solving this dependency. This helps every time a previous solver + is removed by the resolver because of a conflict or alike but it is + dangerous as it could trigger new breaks/conflicts… */ + if (Debug == true) + clog << " Try Installing " << Start.TargetPkg() << " before changing " << I.FullName(false) << std::endl; + unsigned long const OldBroken = Cache.BrokenCount(); + Cache.MarkInstall(Start.TargetPkg(), true, 1, false); + // FIXME: we should undo the complete MarkInstall process here + if (Cache[Start.TargetPkg()].InstBroken() == true || Cache.BrokenCount() > OldBroken) + Cache.MarkDelete(Start.TargetPkg(), false, 1, false); + } } } @@ -1006,25 +1038,17 @@ bool pkgProblemResolver::Resolve(bool BrokenFix) } else { - /* This is a conflicts, and the version we are looking - at is not the currently selected version of the - package, which means it is not necessary to - remove/keep */ - if (Cache[Pkg].InstallVer != Ver && - (Start->Type == pkgCache::Dep::Conflicts || - Start->Type == pkgCache::Dep::Obsoletes)) - continue; - if (Start->Type == pkgCache::Dep::DpkgBreaks) { // first, try upgradring the package, if that // does not help, the breaks goes onto the // kill list + // // FIXME: use DoUpgrade(Pkg) instead? - if (Cache[End] & pkgDepCache::DepGCVer) + if (Cache[End] & pkgDepCache::DepGCVer) { if (Debug) - clog << " Upgrading " << Pkg.Name() << " due to Breaks field in " << I.Name() << endl; + clog << " Upgrading " << Pkg.FullName(false) << " due to Breaks field in " << I.FullName(false) << endl; Cache.MarkInstall(Pkg, false, 0, false); continue; } @@ -1035,7 +1059,7 @@ bool pkgProblemResolver::Resolve(bool BrokenFix) continue; if (Debug == true) - clog << " Added " << Pkg.Name() << " to the remove list" << endl; + clog << " Added " << Pkg.FullName(false) << " to the remove list" << endl; LEnd->Pkg = Pkg; LEnd->Dep = End; @@ -1048,10 +1072,8 @@ bool pkgProblemResolver::Resolve(bool BrokenFix) } // Hm, nothing can possibly satisify this dep. Nuke it. - if (VList[0] == 0 && - Start->Type != pkgCache::Dep::Conflicts && - Start->Type != pkgCache::Dep::DpkgBreaks && - Start->Type != pkgCache::Dep::Obsoletes && + if (VList[0] == 0 && + Start.IsNegative() == false && (Flags[I->ID] & Protected) != Protected) { bool Installed = Cache[I].Install(); @@ -1067,12 +1089,12 @@ bool pkgProblemResolver::Resolve(bool BrokenFix) Cache.MarkInstall(I, false, 0, false); if (Debug == true) - clog << " Holding Back " << I.Name() << " because I can't find " << Start.TargetPkg().Name() << endl; + clog << " Holding Back " << I.FullName(false) << " because I can't find " << Start.TargetPkg().FullName(false) << endl; } else { if (Debug == true) - clog << " Removing " << I.Name() << " because I can't find " << Start.TargetPkg().Name() << endl; + clog << " Removing " << I.FullName(false) << " because I can't find " << Start.TargetPkg().FullName(false) << endl; if (InOr == false) Cache.MarkDelete(I); } @@ -1097,19 +1119,17 @@ bool pkgProblemResolver::Resolve(bool BrokenFix) Change = true; if ((Cache[J->Dep] & pkgDepCache::DepGNow) == 0) { - if (J->Dep->Type == pkgCache::Dep::Conflicts || - J->Dep->Type == pkgCache::Dep::DpkgBreaks || - J->Dep->Type == pkgCache::Dep::Obsoletes) + if (J->Dep.IsNegative() == true) { if (Debug == true) - clog << " Fixing " << I.Name() << " via remove of " << J->Pkg.Name() << endl; + clog << " Fixing " << I.FullName(false) << " via remove of " << J->Pkg.FullName(false) << endl; Cache.MarkDelete(J->Pkg); } } else { if (Debug == true) - clog << " Fixing " << I.Name() << " via keep of " << J->Pkg.Name() << endl; + clog << " Fixing " << I.FullName(false) << " via keep of " << J->Pkg.FullName(false) << endl; Cache.MarkKeep(J->Pkg, false, false); } @@ -1130,7 +1150,7 @@ bool pkgProblemResolver::Resolve(bool BrokenFix) { // See if this is the result of a hold pkgCache::PkgIterator I = Cache.PkgBegin(); - for (;I.end() != true; I++) + for (;I.end() != true; ++I) { if (Cache[I].InstBroken() == false) continue; @@ -1142,10 +1162,10 @@ bool pkgProblemResolver::Resolve(bool BrokenFix) // set the auto-flags (mvo: I'm not sure if we _really_ need this) pkgCache::PkgIterator I = Cache.PkgBegin(); - for (;I.end() != true; I++) { + for (;I.end() != true; ++I) { if (Cache[I].NewInstall() && !(Flags[I->ID] & PreInstalled)) { if(_config->FindI("Debug::pkgAutoRemove",false)) { - std::clog << "Resolve installed new pkg: " << I.Name() + std::clog << "Resolve installed new pkg: " << I.FullName(false) << " (now marking it as auto)" << std::endl; } Cache[I].Flags |= pkgCache::Flag::Auto; @@ -1156,6 +1176,31 @@ bool pkgProblemResolver::Resolve(bool BrokenFix) return true; } /*}}}*/ + +// ProblemResolver::BreaksInstOrPolicy - Check if the given pkg is broken/*{{{*/ +// --------------------------------------------------------------------- +/* This checks if the given package is broken either by a hard dependency + (InstBroken()) or by introducing a new policy breakage e.g. new + unsatisfied recommends for a package that was in "policy-good" state + + Note that this is not perfect as it will ignore further breakage + for already broken policy (recommends) +*/ +bool pkgProblemResolver::InstOrNewPolicyBroken(pkgCache::PkgIterator I) +{ + + // a broken install is always a problem + if (Cache[I].InstBroken() == true) + return true; + + // a newly broken policy (recommends/suggests) is a problem + if (Cache[I].NowPolicyBroken() == false && + Cache[I].InstPolicyBroken() == true) + return true; + + return false; +} + // ProblemResolver::ResolveByKeep - Resolve problems using keep /*{{{*/ // --------------------------------------------------------------------- /* This is the work horse of the soft upgrade routine. It is very gental @@ -1175,7 +1220,7 @@ bool pkgProblemResolver::ResolveByKeep() would cause the removal of even lower score packages. */ pkgCache::Package **PList = new pkgCache::Package *[Size]; pkgCache::Package **PEnd = PList; - for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++) + for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I) *PEnd++ = I; This = this; qsort(PList,PEnd - PList,sizeof(*PList),&ScoreSort); @@ -1200,17 +1245,20 @@ bool pkgProblemResolver::ResolveByKeep() { pkgCache::PkgIterator I(Cache,*K); - if (Cache[I].InstallVer == 0 || Cache[I].InstBroken() == false) + if (Cache[I].InstallVer == 0) continue; + if (InstOrNewPolicyBroken(I) == false) + continue; + /* Keep the package. If this works then great, otherwise we have to be significantly more agressive and manipulate its dependencies */ if ((Flags[I->ID] & Protected) == 0) { if (Debug == true) - clog << "Keeping package " << I.Name() << endl; + clog << "Keeping package " << I.FullName(false) << endl; Cache.MarkKeep(I, false, false); - if (Cache[I].InstBroken() == false) + if (InstOrNewPolicyBroken(I) == false) { K = PList - 1; continue; @@ -1239,7 +1287,7 @@ bool pkgProblemResolver::ResolveByKeep() while (true) { if (Debug == true) - clog << "Package " << I.Name() << " has broken " << Start.DepType() << " on " << Start.TargetPkg().Name() << endl; + clog << "Package " << I.FullName(false) << " " << Start << endl; // Look at all the possible provides on this package SPtrArray VList = Start.AllTargets(); @@ -1256,32 +1304,32 @@ bool pkgProblemResolver::ResolveByKeep() if ((Flags[I->ID] & Protected) == 0) { if (Debug == true) - clog << " Keeping Package " << Pkg.Name() << " due to " << Start.DepType() << endl; + clog << " Keeping Package " << Pkg.FullName(false) << " due to " << Start.DepType() << endl; Cache.MarkKeep(Pkg, false, false); } - if (Cache[I].InstBroken() == false) + if (InstOrNewPolicyBroken(I) == false) break; } - if (Cache[I].InstBroken() == false) + if (InstOrNewPolicyBroken(I) == false) break; if (Start == End) break; - Start++; + ++Start; } - if (Cache[I].InstBroken() == false) + if (InstOrNewPolicyBroken(I) == false) break; } - if (Cache[I].InstBroken() == true) + if (InstOrNewPolicyBroken(I) == true) continue; // Restart again. if (K == LastStop) - return _error->Error("Internal Error, pkgProblemResolver::ResolveByKeep is looping on package %s.",I.Name()); + return _error->Error("Internal Error, pkgProblemResolver::ResolveByKeep is looping on package %s.",I.FullName(false).c_str()); LastStop = K; K = PList - 1; } @@ -1296,7 +1344,7 @@ void pkgProblemResolver::InstallProtect() { pkgDepCache::ActionGroup group(Cache); - for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; I++) + for (pkgCache::PkgIterator I = Cache.PkgBegin(); I.end() == false; ++I) { if ((Flags[I->ID] & Protected) == Protected) { @@ -1353,7 +1401,9 @@ bool ListUpdate(pkgAcquireStatus &Stat, int PulseInterval) { pkgAcquire::RunResult res; - pkgAcquire Fetcher(&Stat); + pkgAcquire Fetcher; + if (Fetcher.Setup(&Stat, _config->FindDir("Dir::State::Lists")) == false) + return false; // Populate it with the source selection if (List.GetIndexes(&Fetcher) == false) @@ -1374,7 +1424,7 @@ bool ListUpdate(pkgAcquireStatus &Stat, bool Failed = false; bool TransientNetworkFailure = false; for (pkgAcquire::ItemIterator I = Fetcher.ItemsBegin(); - I != Fetcher.ItemsEnd(); I++) + I != Fetcher.ItemsEnd(); ++I) { if ((*I)->Status == pkgAcquire::Item::StatDone) continue; @@ -1411,9 +1461,9 @@ bool ListUpdate(pkgAcquireStatus &Stat, } if (TransientNetworkFailure == true) - _error->Warning(_("Some index files failed to download, they have been ignored, or old ones used instead.")); + _error->Warning(_("Some index files failed to download. They have been ignored, or old ones used instead.")); else if (Failed == true) - return _error->Error(_("Some index files failed to download, they have been ignored, or old ones used instead.")); + return _error->Error(_("Some index files failed to download. They have been ignored, or old ones used instead.")); // Run the success scripts if all was fine