X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/0a57c0f0e4d0bc3474ce4d2101f36a997891d30d..899d08fea9e10d617afaa42f51f4abda76fc508f:/apt-pkg/algorithms.cc diff --git a/apt-pkg/algorithms.cc b/apt-pkg/algorithms.cc index bed90f5d0..8626d33dc 100644 --- a/apt-pkg/algorithms.cc +++ b/apt-pkg/algorithms.cc @@ -26,7 +26,8 @@ #include - +#include +#include #include /*}}}*/ using namespace std; @@ -1329,7 +1330,20 @@ void pkgMarkPackage(pkgDepCache &Cache, } -bool pkgMarkUsed(pkgDepCache &Cache) +// Helper for APT::NeverAutoRemove, always include the packages matching +// this regexp into the root-set +inline bool +pkgMarkAlwaysInclude(pkgCache::PkgIterator p, vector alwaysMark) +{ + for(unsigned int i=0;iFindB("APT::AutoRemove::RecommendsImportant",false); - follow_suggests=_config->FindB("APT::AutoRemove::SuggestsImportend", false); + follow_suggests=_config->FindB("APT::AutoRemove::SuggestsImportant", false); + + + // init the "NeverAutoRemove" variable + vector neverAutoRemoveRegexp; + Configuration::Item const *Opts; + Opts = _config->Tree("APT::NeverAutoRemove"); + if (Opts != 0 && Opts->Child != 0) + { + Opts = Opts->Child; + for (; Opts != 0; Opts = Opts->Next) + { + if (Opts->Value.empty() == true) + continue; + regex_t *p = new regex_t; + if(regcomp(p,Opts->Value.c_str(), + REG_EXTENDED | REG_ICASE | REG_NOSUB) != 0) + { + regfree(p); + for(unsigned int i=0;iError("Regex compilation error for APT::NeverAutoRemove"); + } + neverAutoRemoveRegexp.push_back(p); + } + } - // do the mark part + + // do the mark part, this is the core bit of the algorithm for(pkgCache::PkgIterator p=Cache.PkgBegin(); !p.end(); ++p) { - if(Cache[p].InstallReason==pkgDepCache::Manual || - (p->Flags & pkgCache::Flag::Essential)) + if( (func != NULL ? (*func)(p) : false) || + pkgMarkAlwaysInclude(p, neverAutoRemoveRegexp) || + !(Cache[p].Flags & pkgCache::Flag::Auto) || + (p->Flags & pkgCache::Flag::Essential)) + { + // the package is installed (and set to keep) if(Cache[p].Keep() && !p.CurrentVer().end()) pkgMarkPackage(Cache, p, p.CurrentVer(), follow_recommends, follow_suggests); + // the package is to be installed else if(Cache[p].Install()) pkgMarkPackage(Cache, p, Cache[p].InstVerIter(Cache), follow_recommends, follow_suggests); @@ -1432,5 +1477,11 @@ bool pkgMarkUsed(pkgDepCache &Cache) #endif } } + + // cleanup + for(unsigned int i=0;i