diff options
author | David Kalnischkies <david@kalnischkies.de> | 2021-08-28 19:49:43 +0200 |
---|---|---|
committer | David Kalnischkies <david@kalnischkies.de> | 2021-08-28 22:21:35 +0200 |
commit | e4701219cf821d24f7f48ed6e4d8123c11d47c8b (patch) | |
tree | 9e7cec36bae3e7e885e12e2e15abac2d2906eea7 | |
parent | d7e9f0779043814d6e7a4141170fa7f18cd90803 (diff) |
Don't venture too deeply in AutoRemovers MarkPackage
MarkInstall has the same depth limit, so lets use this arbitrary limit
to avoid trying to hard as that usually means we will never stop – at
least not until we crash, which is not a very good error case.
-rw-r--r-- | apt-pkg/depcache.cc | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/apt-pkg/depcache.cc b/apt-pkg/depcache.cc index 8ab156220..76e8f5357 100644 --- a/apt-pkg/depcache.cc +++ b/apt-pkg/depcache.cc @@ -2226,12 +2226,13 @@ static bool IsPkgInBoringState(pkgCache::PkgIterator const &Pkg, pkgDepCache::St } /*}}}*/ // MarkPackage - mark a single package in Mark-and-Sweep /*{{{*/ -static void MarkPackage(pkgCache::PkgIterator const &Pkg, +static bool MarkPackage(pkgCache::PkgIterator const &Pkg, pkgCache::VerIterator const &Ver, bool const follow_recommends, bool const follow_suggests, bool const debug_autoremove, std::string_view const reason, + size_t const Depth, pkgCache &Cache, pkgDepCache &DepCache, pkgDepCache::StateCache *const PkgState, @@ -2240,14 +2241,18 @@ static void MarkPackage(pkgCache::PkgIterator const &Pkg, std::unique_ptr<APT::CacheFilter::Matcher> &IsProtectedKernelPackage) { if (Ver.end() || (fullyExplored[Pkg->ID] && PkgState[Pkg->ID].Marked)) - return; + return true; if (IsPkgInBoringState(Pkg, PkgState)) { fullyExplored[Pkg->ID] = true; - return; + return true; } + // we are not trying to hard… + if (unlikely(Depth > 100)) + return false; + PkgState[Pkg->ID].Marked = true; if(debug_autoremove) std::clog << "Marking: " << Pkg.FullName() << " " << Ver.VerStr() @@ -2348,12 +2353,14 @@ static void MarkPackage(pkgCache::PkgIterator const &Pkg, std::clog << "Following dep: " << APT::PrettyDep(&DepCache, D) << ", provided by " << PP.FullName() << " " << PV.VerStr() << " (" << providers_by_source.size() << "/" << providers.second.size() << ")\n"; - MarkPackage(PP, PV, follow_recommends, follow_suggests, debug_autoremove, - "Dependency", Cache, DepCache, PkgState, fullyExplored, - IsAVersionedKernelPackage, IsProtectedKernelPackage); + if (not MarkPackage(PP, PV, follow_recommends, follow_suggests, debug_autoremove, + "Dependency", Depth + 1, Cache, DepCache, PkgState, fullyExplored, + IsAVersionedKernelPackage, IsProtectedKernelPackage)) + return false; } } } + return true; } /*}}}*/ // pkgDepCache::MarkRequired - the main mark algorithm /*{{{*/ @@ -2403,9 +2410,9 @@ bool pkgDepCache::MarkRequired(InRootSetFunc &userFunc) continue; pkgCache::VerIterator const PV = (PkgState[P->ID].Install()) ? PkgState[P->ID].InstVerIter(*this) : P.CurrentVer(); - MarkPackage(P, PV, follow_recommends, follow_suggests, debug_autoremove, - reason, *Cache, *this, PkgState, fullyExplored, - d->IsAVersionedKernelPackage, d->IsProtectedKernelPackage); + if (not MarkPackage(P, PV, follow_recommends, follow_suggests, debug_autoremove, + reason, 0, *Cache, *this, PkgState, fullyExplored, + d->IsAVersionedKernelPackage, d->IsProtectedKernelPackage)) return false; } return true; |