diff options
author | David Kalnischkies <david@kalnischkies.de> | 2020-04-26 13:14:43 +0200 |
---|---|---|
committer | David Kalnischkies <david@kalnischkies.de> | 2020-04-27 13:47:08 +0200 |
commit | 76498d46855c88b90316e4369ac32050db9a9d23 (patch) | |
tree | effc77aff70172f33353885d31ab928cad5b132d | |
parent | 0de399391372450d0162b5a09bfca554b2d27c3d (diff) |
Split up MarkInstall into private helper methods
Should be easier to move the code bits around then and it helps in
documenting a bit what the blocks do and how they interact (or not).
-rw-r--r-- | apt-pkg/depcache.cc | 165 | ||||
-rw-r--r-- | apt-pkg/depcache.h | 12 |
2 files changed, 113 insertions, 64 deletions
diff --git a/apt-pkg/depcache.cc b/apt-pkg/depcache.cc index 425918b43..b88e9ceb8 100644 --- a/apt-pkg/depcache.cc +++ b/apt-pkg/depcache.cc @@ -980,10 +980,8 @@ bool pkgDepCache::IsModeChangeOk(ModeList const mode, PkgIterator const &Pkg, return true; } /*}}}*/ -// DepCache::MarkInstall - Put the package in the install state /*{{{*/ -// --------------------------------------------------------------------- -/* */ -struct CompareProviders { +struct CompareProviders /*{{{*/ +{ pkgCache::PkgIterator const Pkg; explicit CompareProviders(pkgCache::DepIterator const &Dep) : Pkg(Dep.TargetPkg()) {}; //bool operator() (APT::VersionList::iterator const &AV, APT::VersionList::iterator const &BV) @@ -1068,35 +1066,10 @@ struct CompareProviders { return A->ID < B->ID; } }; -bool pkgDepCache::MarkInstall(PkgIterator const &Pkg,bool AutoInst, - unsigned long Depth, bool FromUser, - bool ForceImportantDeps) + /*}}}*/ +bool pkgDepCache::MarkInstall_StateChange(PkgIterator const &Pkg, bool AutoInst, bool FromUser) /*{{{*/ { - if (IsModeChangeOk(ModeInstall, Pkg, Depth, FromUser) == false) - return false; - StateCache &P = PkgState[Pkg->ID]; - - // See if there is even any possible installation candidate - if (P.CandidateVer == 0) - return false; - - /* Check that it is not already marked for install and that it can be - installed */ - if ((not P.InstPolicyBroken() && not P.InstBroken()) && - (P.Mode == ModeInstall || - P.CandidateVer == (Version *)Pkg.CurrentVer())) - { - if (P.CandidateVer == (Version *)Pkg.CurrentVer() && P.InstallVer == 0) - return MarkKeep(Pkg, false, FromUser, Depth+1); - return true; - } - - // check if we are allowed to install the package - if (not IsInstallOk(Pkg, AutoInst, Depth, FromUser)) - return false; - - ActionGroup group(*this); P.iFlags &= ~AutoKept; /* Target the candidate version and remove the autoflag. We reset the @@ -1104,7 +1077,7 @@ bool pkgDepCache::MarkInstall(PkgIterator const &Pkg,bool AutoInst, should have the ability to de-auto a package by changing its state */ RemoveSizes(Pkg); RemoveStates(Pkg); - + P.Mode = ModeInstall; P.InstallVer = P.CandidateVer; @@ -1124,23 +1097,15 @@ bool pkgDepCache::MarkInstall(PkgIterator const &Pkg,bool AutoInst, } if (P.CandidateVer == (Version *)Pkg.CurrentVer()) P.Mode = ModeKeep; - + AddStates(Pkg); Update(Pkg); AddSizes(Pkg); - - if (not AutoInst || _config->Find("APT::Solver", "internal") != "internal") - return true; - - if (DebugMarker) - std::clog << OutputInDepth(Depth) << "MarkInstall " << APT::PrettyPkg(this, Pkg) << " FU=" << FromUser << std::endl; - - // collect dependencies we will have to resolve one way or the other - VerIterator const PV = P.InstVerIter(*this); - if (unlikely(PV.end())) - return false; - - std::vector<pkgCache::DepIterator> toRemove, toInstall; + return true; +} + /*}}}*/ +bool pkgDepCache::MarkInstall_CollectDependencies(pkgCache::VerIterator const &PV, std::vector<pkgCache::DepIterator> &toInstall, std::vector<pkgCache::DepIterator> &toRemove) /*{{{*/ +{ for (auto Dep = PV.DependsList(); not Dep.end();) { auto const Start = Dep; @@ -1169,11 +1134,14 @@ bool pkgDepCache::MarkInstall(PkgIterator const &Pkg,bool AutoInst, else toInstall.push_back(Start); } - + return true; +} + /*}}}*/ +bool pkgDepCache::MarkInstall_RemoveConflictsIfNotUpgradeable(unsigned long Depth, std::vector<pkgCache::DepIterator> &toRemove, APT::PackageVector &toUpgrade) /*{{{*/ +{ /* Negative dependencies have no or-group If the dependency isn't versioned, we try if an upgrade might solve the problem. Otherwise we remove the offender if needed */ - APT::PackageVector toUpgrade; for (auto const &D : toRemove) { std::unique_ptr<Version *[]> List(D.AllTargets()); @@ -1206,6 +1174,11 @@ bool pkgDepCache::MarkInstall(PkgIterator const &Pkg,bool AutoInst, } } toRemove.clear(); + return true; +} + /*}}}*/ +bool pkgDepCache::MarkInstall_UpgradeOrRemoveConflicts(unsigned long Depth, bool const ForceImportantDeps, APT::PackageVector &toUpgrade) /*{{{*/ +{ for (auto const &InstPkg : toUpgrade) if (not MarkInstall(InstPkg, true, Depth + 1, false, ForceImportantDeps)) { @@ -1215,20 +1188,11 @@ bool pkgDepCache::MarkInstall(PkgIterator const &Pkg,bool AutoInst, return false; } toUpgrade.clear(); - - bool MoveAutoBitToDependencies = false; - if (PV->Section != 0 && (P.Flags & Flag::Auto) != Flag::Auto) - { - VerIterator const CurVer = Pkg.CurrentVer(); - if (not CurVer.end() && CurVer->Section != 0 && strcmp(CurVer.Section(), PV.Section()) != 0) - { - bool const CurVerInMoveSection = ConfigValueInSubTree("APT::Move-Autobit-Sections", CurVer.Section()); - bool const InstVerInMoveSection = ConfigValueInSubTree("APT::Move-Autobit-Sections", PV.Section()); - MoveAutoBitToDependencies = (not CurVerInMoveSection && InstVerInMoveSection); - } - } - APT::PackageVector toMoveAuto; - + return true; +} + /*}}}*/ +bool pkgDepCache::MarkInstall_InstallDependencies(PkgIterator const &Pkg, unsigned long Depth, bool const ForceImportantDeps, std::vector<pkgCache::DepIterator> &toInstall, APT::PackageVector *const toMoveAuto) /*{{{*/ +{ auto const IsSatisfiedByInstalled = [&](auto const D) { return (DepState[D.ID] & DepInstall) == DepInstall; }; for (auto &&Dep : toInstall) { @@ -1314,8 +1278,8 @@ bool pkgDepCache::MarkInstall(PkgIterator const &Pkg,bool AutoInst, continue; } - if (MoveAutoBitToDependencies && InstPkg->CurrentVer == 0) - toMoveAuto.push_back(InstPkg); + if (toMoveAuto != nullptr && InstPkg->CurrentVer == 0) + toMoveAuto->push_back(InstPkg); foundSolution = true; break; @@ -1344,6 +1308,79 @@ bool pkgDepCache::MarkInstall(PkgIterator const &Pkg,bool AutoInst, } } toInstall.clear(); + return true; +} + /*}}}*/ +// DepCache::MarkInstall - Put the package in the install state /*{{{*/ +bool pkgDepCache::MarkInstall(PkgIterator const &Pkg, bool AutoInst, + unsigned long Depth, bool FromUser, + bool ForceImportantDeps) +{ + if (IsModeChangeOk(ModeInstall, Pkg, Depth, FromUser) == false) + return false; + + StateCache &P = PkgState[Pkg->ID]; + + // See if there is even any possible installation candidate + if (P.CandidateVer == 0) + return false; + + /* Check that it is not already marked for install and that it can be + installed */ + if ((not P.InstPolicyBroken() && not P.InstBroken()) && + (P.Mode == ModeInstall || + P.CandidateVer == (Version *)Pkg.CurrentVer())) + { + if (P.CandidateVer == (Version *)Pkg.CurrentVer() && P.InstallVer == 0) + return MarkKeep(Pkg, false, FromUser, Depth + 1); + return true; + } + + // check if we are allowed to install the package + if (not IsInstallOk(Pkg, AutoInst, Depth, FromUser)) + return false; + + ActionGroup group(*this); + if (not MarkInstall_StateChange(Pkg, AutoInst, FromUser)) + return false; + + if (not AutoInst || _config->Find("APT::Solver", "internal") != "internal") + return true; + + if (DebugMarker) + std::clog << OutputInDepth(Depth) << "MarkInstall " << APT::PrettyPkg(this, Pkg) << " FU=" << FromUser << std::endl; + + VerIterator const PV = P.InstVerIter(*this); + if (unlikely(PV.end())) + return false; + + std::vector<pkgCache::DepIterator> toInstall, toRemove; + if (not MarkInstall_CollectDependencies(PV, toInstall, toRemove)) + return false; + + APT::PackageVector toUpgrade; + if (not MarkInstall_RemoveConflictsIfNotUpgradeable(Depth, toRemove, toUpgrade)) + return false; + + if (not MarkInstall_UpgradeOrRemoveConflicts(Depth, ForceImportantDeps, toUpgrade)) + return false; + + bool const MoveAutoBitToDependencies = [&]() { + if (PV->Section == 0 || (P.Flags & Flag::Auto) == Flag::Auto) + return false; + VerIterator const CurVer = Pkg.CurrentVer(); + if (not CurVer.end() && CurVer->Section != 0 && strcmp(CurVer.Section(), PV.Section()) != 0) + { + bool const CurVerInMoveSection = ConfigValueInSubTree("APT::Move-Autobit-Sections", CurVer.Section()); + bool const InstVerInMoveSection = ConfigValueInSubTree("APT::Move-Autobit-Sections", PV.Section()); + return (not CurVerInMoveSection && InstVerInMoveSection); + } + return false; + }(); + + APT::PackageVector toMoveAuto; + if (not MarkInstall_InstallDependencies(Pkg, Depth, ForceImportantDeps, toInstall, MoveAutoBitToDependencies ? &toMoveAuto : nullptr)) + return false; if (MoveAutoBitToDependencies) { diff --git a/apt-pkg/depcache.h b/apt-pkg/depcache.h index 17d9a9c3c..9f2fc3477 100644 --- a/apt-pkg/depcache.h +++ b/apt-pkg/depcache.h @@ -51,6 +51,12 @@ class OpProgress; class pkgVersioningSystem; +namespace APT +{ +template <class Container> +class PackageContainer; +using PackageVector = PackageContainer<std::vector<pkgCache::PkgIterator>>; +} // namespace APT class APT_PUBLIC pkgDepCache : protected pkgCache::Namespace { @@ -511,6 +517,12 @@ class APT_PUBLIC pkgDepCache : protected pkgCache::Namespace APT_HIDDEN bool IsModeChangeOk(ModeList const mode, PkgIterator const &Pkg, unsigned long const Depth, bool const FromUser); + + APT_HIDDEN bool MarkInstall_StateChange(PkgIterator const &Pkg, bool AutoInst, bool FromUser); + APT_HIDDEN bool MarkInstall_CollectDependencies(pkgCache::VerIterator const &PV, std::vector<pkgCache::DepIterator> &toInstall, std::vector<pkgCache::DepIterator> &toRemove); + APT_HIDDEN bool MarkInstall_RemoveConflictsIfNotUpgradeable(unsigned long Depth, std::vector<pkgCache::DepIterator> &toRemove, APT::PackageVector &toUpgrade); + APT_HIDDEN bool MarkInstall_UpgradeOrRemoveConflicts(unsigned long Depth, bool const ForceImportantDeps, APT::PackageVector &toUpgrade); + APT_HIDDEN bool MarkInstall_InstallDependencies(PkgIterator const &Pkg, unsigned long Depth, bool const ForceImportantDeps, std::vector<pkgCache::DepIterator> &toInstall, APT::PackageVector *const toMoveAuto); }; #endif |