-static pkgCache *PrioCache;
-static int PrioComp(const void *A,const void *B)
-{
- pkgCache::VerIterator L(*PrioCache,*(pkgCache::Version **)A);
- pkgCache::VerIterator R(*PrioCache,*(pkgCache::Version **)B);
-
- if ((L.ParentPkg()->Flags & pkgCache::Flag::Essential) == pkgCache::Flag::Essential &&
- (R.ParentPkg()->Flags & pkgCache::Flag::Essential) != pkgCache::Flag::Essential)
- return 1;
- if ((L.ParentPkg()->Flags & pkgCache::Flag::Essential) != pkgCache::Flag::Essential &&
- (R.ParentPkg()->Flags & pkgCache::Flag::Essential) == pkgCache::Flag::Essential)
- return -1;
-
- if (L->Priority != R->Priority)
- return R->Priority - L->Priority;
- return strcmp(L.ParentPkg().Name(),R.ParentPkg().Name());
-}
-void pkgPrioSortList(pkgCache &Cache,pkgCache::Version **List)
-{
- unsigned long Count = 0;
- PrioCache = &Cache;
- for (pkgCache::Version **I = List; *I != 0; I++)
- Count++;
- qsort(List,Count,sizeof(*List),PrioComp);
-}
- /*}}}*/
-
-
-// mark a single package in Mark-and-Sweep
-void pkgMarkPackage(pkgDepCache &Cache,
- const pkgCache::PkgIterator &pkg,
- const pkgCache::VerIterator &ver,
- bool follow_recommends,
- bool follow_suggests)
-{
- pkgDepCache::StateCache &state=Cache[pkg];
- pkgCache::VerIterator candver=state.CandidateVerIter(Cache);
- pkgCache::VerIterator instver=state.InstVerIter(Cache);
-
-#if 0
- // If a package was garbage-collected but is now being marked, we
- // should re-select it
- // For cases when a pkg is set to upgrade and this trigger the
- // removal of a no-longer used dependency. if the pkg is set to
- // keep again later it will result in broken deps
- if(state.Delete() && state.RemoveReason=pkgDepCache::Unused)
- {
- if(ver==candver)
- mark_install(pkg, false, false, NULL);
- else if(ver==pkg.CurrentVer())
- MarkKeep(pkg);
-
- instver=state.InstVerIter(*this);
- }
-#endif
-
- // Ignore versions other than the InstVer, and ignore packages
- // that are already going to be removed or just left uninstalled.
- if(!(ver==instver && !instver.end()))
- return;
-
- // if we are marked already we are done
- if(state.Marked)
- return;
-
- //std::cout << "Setting Marked for: " << pkg.Name() << std::endl;
- state.Marked=true;
-
- if(!ver.end())
- {
- for(pkgCache::DepIterator d=ver.DependsList(); !d.end(); ++d)
- {
- if(d->Type==pkgCache::Dep::Depends ||
- d->Type==pkgCache::Dep::PreDepends ||
- (follow_recommends &&
- d->Type==pkgCache::Dep::Recommends) ||
- (follow_suggests &&
- d->Type==pkgCache::Dep::Suggests))
- {
- // Try all versions of this package.
- for(pkgCache::VerIterator V=d.TargetPkg().VersionList();
- !V.end(); ++V)
- {
- if(_system->VS->CheckDep(V.VerStr(),d->CompareOp, d.TargetVer()))
- {
- pkgMarkPackage(Cache, V.ParentPkg(), V,
- follow_recommends, follow_suggests);
- }
- }
- // Now try virtual packages
- for(pkgCache::PrvIterator prv=d.TargetPkg().ProvidesList();
- !prv.end(); ++prv)
- {
- if(_system->VS->CheckDep(prv.ProvideVersion(), d->CompareOp,
- d.TargetVer()))
- {
- pkgMarkPackage(Cache, prv.OwnerPkg(), prv.OwnerVer(),
- follow_recommends, follow_suggests);
- }
- }
- }
- }
- }
-}
-
-
-// Helper for APT::NeverAutoRemove, always include the packages matching
-// this regexp into the root-set
-inline bool
-pkgMarkAlwaysInclude(pkgCache::PkgIterator p, vector<regex_t*> alwaysMark)
-{
- for(unsigned int i=0;i<alwaysMark.size();i++)
- if (regexec(alwaysMark[i],p.Name(),0,0,0) == 0)
- return true;
-
- return false;
-}
-
-bool pkgMarkUsed(pkgDepCache &Cache)
-{
- InRootSetFunc f;
- return pkgMarkUsed(Cache, f);
-}
-
-// the main mark algorithm
-bool pkgMarkUsed(pkgDepCache &Cache, InRootSetFunc &userFunc)
-{
- bool follow_recommends;
- bool follow_suggests;