X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/2ac6ce927cda2847baf8e71a74e595e6b82c6d98..f8ac1720a94468d1384e88a57729e6d9801b56fd:/apt-pkg/algorithms.cc?ds=sidebyside diff --git a/apt-pkg/algorithms.cc b/apt-pkg/algorithms.cc index 11f5b5671..3978e7561 100644 --- a/apt-pkg/algorithms.cc +++ b/apt-pkg/algorithms.cc @@ -26,7 +26,8 @@ #include - +#include +#include #include /*}}}*/ using namespace std; @@ -1329,6 +1330,19 @@ void pkgMarkPackage(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("Debug::pkgAutoRemove",false) + && Cache[p].Flags & pkgCache::Flag::Auto) + std::clog << "AutoDep: " << p.Name() << std::endl; } // init vars @@ -1346,17 +1365,46 @@ bool pkgMarkUsed(pkgDepCache &Cache, InRootSetFunc func) follow_suggests=_config->FindB("APT::AutoRemove::SuggestsImportant", false); - // do the mark part + // 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, this is the core bit of the algorithm for(pkgCache::PkgIterator p=Cache.PkgBegin(); !p.end(); ++p) { 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); @@ -1369,14 +1417,13 @@ bool pkgMarkUsed(pkgDepCache &Cache, InRootSetFunc func) { pkgDepCache::StateCache &state=Cache[p]; - if(!state.Marked) + // if it is not marked and it is installed, it's garbage + if(!state.Marked && !p.CurrentVer().end()) { - // mark installed but not yet marked stuff as garbage - if(p->CurrentVer != 0) { - state.Garbage=true; + state.Garbage=true; + if(_config->FindB("Debug::pkgAutoRemove",false)) std::cout << "Garbage: " << p.Name() << std::endl; - } - + #if 0 // mvo: the below bits still needs to be ported // Be sure not to re-delete already deleted packages. @@ -1434,5 +1481,11 @@ bool pkgMarkUsed(pkgDepCache &Cache, InRootSetFunc func) #endif } } + + // cleanup + for(unsigned int i=0;i