* added APT::NeverAutoRemove (a list of regexp for package names that should never...
authorMichael Vogt <michael.vogt@ubuntu.com>
Thu, 30 Jun 2005 08:53:45 +0000 (08:53 +0000)
committerMichael Vogt <michael.vogt@ubuntu.com>
Thu, 30 Jun 2005 08:53:45 +0000 (08:53 +0000)
apt-pkg/algorithms.cc
doc/examples/configure-index

index 11f5b56..8e55649 100644 (file)
@@ -26,7 +26,8 @@
 
     
 #include <apti18n.h>
-    
+#include <sys/types.h>
+#include <regex.h>
 #include <iostream>
                                                                        /*}}}*/
 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<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;
+}
+
+// the main mark algorithm
 bool pkgMarkUsed(pkgDepCache &Cache, InRootSetFunc func)
 {
    bool follow_recommends;
@@ -1346,10 +1360,37 @@ bool pkgMarkUsed(pkgDepCache &Cache, InRootSetFunc func)
    follow_suggests=_config->FindB("APT::AutoRemove::SuggestsImportant", false);
 
 
+   // init the "NeverAutoRemove" variable
+   vector<regex_t *> 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;i<neverAutoRemoveRegexp.size();i++)
+              regfree(neverAutoRemoveRegexp[i]);
+           return _error->Error("Regex compilation error for APT::NeverAutoRemove");
+        }
+        neverAutoRemoveRegexp.push_back(p);
+      }
+   }
+
+
    // do the mark part
    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))
           
@@ -1434,5 +1475,11 @@ bool pkgMarkUsed(pkgDepCache &Cache, InRootSetFunc func)
 #endif
      }
   }
+
+   // cleanup
+   for(unsigned int i=0;i<neverAutoRemoveRegexp.size();i++)
+      regfree(neverAutoRemoveRegexp[i]);
+   
+
    return true;
 }
index 31bc134..b4ac0ed 100644 (file)
@@ -24,7 +24,10 @@ APT
 {
   Architecture "i386";
   Build-Essential "build-essential";
-  
+
+  NeverAutoRemove  { "linux-kernel.*";  };  // packages that should never
+                                            // considered for autoRemove
+
   // Options for apt-get
   Get 
   {