summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apt-pkg/contrib/configuration.cc43
-rw-r--r--apt-pkg/contrib/configuration.h19
-rw-r--r--apt-pkg/depcache.cc48
-rw-r--r--apt-pkg/depcache.h22
-rw-r--r--debian/changelog5
5 files changed, 71 insertions, 66 deletions
diff --git a/apt-pkg/contrib/configuration.cc b/apt-pkg/contrib/configuration.cc
index 9129d92f0..81cc87d15 100644
--- a/apt-pkg/contrib/configuration.cc
+++ b/apt-pkg/contrib/configuration.cc
@@ -843,3 +843,46 @@ bool ReadConfigDir(Configuration &Conf,const string &Dir,
return true;
}
/*}}}*/
+// MatchAgainstConfig Constructor /*{{{*/
+Configuration::MatchAgainstConfig::MatchAgainstConfig(char const * Config)
+{
+ std::vector<std::string> const strings = _config->FindVector(Config);
+ for (std::vector<std::string>::const_iterator s = strings.begin();
+ s != strings.end(); ++s)
+ {
+ regex_t *p = new regex_t;
+ if (regcomp(p, s->c_str(), REG_EXTENDED | REG_ICASE | REG_NOSUB) == 0)
+ patterns.push_back(p);
+ else
+ {
+ regfree(p);
+ delete p;
+ _error->Warning("Regex compilation error for '%s' in configuration option '%s'",
+ s->c_str(), Config);
+ }
+ }
+
+}
+ /*}}}*/
+// MatchAgainstConfig Destructor /*{{{*/
+Configuration::MatchAgainstConfig::~MatchAgainstConfig()
+{
+ for(std::vector<regex_t *>::const_iterator p = patterns.begin();
+ p != patterns.end(); ++p)
+ {
+ regfree(*p);
+ delete *p;
+ }
+}
+ /*}}}*/
+// MatchAgainstConfig::Match - returns true if a pattern matches /*{{{*/
+bool Configuration::MatchAgainstConfig::Match(char const * str) const
+{
+ for(std::vector<regex_t *>::const_iterator p = patterns.begin();
+ p != patterns.end(); ++p)
+ if (regexec(*p, str, 0, 0, 0) == 0)
+ return true;
+
+ return false;
+}
+ /*}}}*/
diff --git a/apt-pkg/contrib/configuration.h b/apt-pkg/contrib/configuration.h
index 2494c1d7c..cbe18e4e5 100644
--- a/apt-pkg/contrib/configuration.h
+++ b/apt-pkg/contrib/configuration.h
@@ -28,7 +28,7 @@
#ifndef PKGLIB_CONFIGURATION_H
#define PKGLIB_CONFIGURATION_H
-
+#include <regex.h>
#include <string>
#include <vector>
@@ -104,6 +104,23 @@ class Configuration
Configuration(const Item *Root);
Configuration();
~Configuration();
+
+ /** \brief match a string against a configurable list of patterns */
+ class MatchAgainstConfig
+ {
+ std::vector<regex_t *> patterns;
+
+ public:
+ MatchAgainstConfig(char const * Config);
+ virtual ~MatchAgainstConfig();
+
+ /** \brief Returns \b true for a string matching one of the patterns */
+ bool Match(char const * str) const;
+ bool Match(std::string const &str) const { return Match(str.c_str()); };
+
+ /** \brief returns if the matcher setup was successful */
+ bool wasConstructedSuccessfully() const { return patterns.empty() == false; }
+ };
};
extern Configuration *_config;
diff --git a/apt-pkg/depcache.cc b/apt-pkg/depcache.cc
index d082b8404..8bca3e36e 100644
--- a/apt-pkg/depcache.cc
+++ b/apt-pkg/depcache.cc
@@ -1638,54 +1638,6 @@ bool pkgDepCache::Policy::IsImportantDep(DepIterator Dep)
return false;
}
/*}}}*/
-pkgDepCache::DefaultRootSetFunc::DefaultRootSetFunc() /*{{{*/
- : constructedSuccessfully(false)
-{
- 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);
- delete p;
- _error->Error("Regex compilation error for APT::NeverAutoRemove");
- return;
- }
-
- rootSetRegexp.push_back(p);
- }
- }
-
- constructedSuccessfully = true;
-}
- /*}}}*/
-pkgDepCache::DefaultRootSetFunc::~DefaultRootSetFunc() /*{{{*/
-{
- for(unsigned int i = 0; i < rootSetRegexp.size(); i++)
- {
- regfree(rootSetRegexp[i]);
- delete rootSetRegexp[i];
- }
-}
- /*}}}*/
-bool pkgDepCache::DefaultRootSetFunc::InRootSet(const pkgCache::PkgIterator &pkg) /*{{{*/
-{
- for(unsigned int i = 0; i < rootSetRegexp.size(); i++)
- if (regexec(rootSetRegexp[i], pkg.Name(), 0, 0, 0) == 0)
- return true;
-
- return false;
-}
- /*}}}*/
pkgDepCache::InRootSetFunc *pkgDepCache::GetRootSetFunc() /*{{{*/
{
DefaultRootSetFunc *f = new DefaultRootSetFunc;
diff --git a/apt-pkg/depcache.h b/apt-pkg/depcache.h
index 72d7cce5d..66c099b80 100644
--- a/apt-pkg/depcache.h
+++ b/apt-pkg/depcache.h
@@ -38,11 +38,10 @@
#ifndef PKGLIB_DEPCACHE_H
#define PKGLIB_DEPCACHE_H
-
+#include <apt-pkg/configuration.h>
#include <apt-pkg/pkgcache.h>
#include <apt-pkg/progress.h>
-
-#include <regex.h>
+#include <apt-pkg/error.h>
#include <vector>
#include <memory>
@@ -184,22 +183,13 @@ class pkgDepCache : protected pkgCache::Namespace
/** \brief Returns \b true for packages matching a regular
* expression in APT::NeverAutoRemove.
*/
- class DefaultRootSetFunc : public InRootSetFunc
+ class DefaultRootSetFunc : public InRootSetFunc, public Configuration::MatchAgainstConfig
{
- std::vector<regex_t *> rootSetRegexp;
- bool constructedSuccessfully;
-
public:
- DefaultRootSetFunc();
- ~DefaultRootSetFunc();
-
- /** \return \b true if the class initialized successfully, \b
- * false otherwise. Used to avoid throwing an exception, since
- * APT classes generally don't.
- */
- bool wasConstructedSuccessfully() const { return constructedSuccessfully; }
+ DefaultRootSetFunc() : Configuration::MatchAgainstConfig("APT::NeverRemove") {};
+ virtual ~DefaultRootSetFunc() {};
- bool InRootSet(const pkgCache::PkgIterator &pkg);
+ bool InRootSet(const pkgCache::PkgIterator &pkg) { return pkg.end() == true && Match(pkg.Name()); };
};
struct StateCache
diff --git a/debian/changelog b/debian/changelog
index 06bde48fc..4500614a0 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -16,14 +16,17 @@ apt (0.7.26~exp8) UNRELEASED; urgency=low
* apt-pkg/depcache.cc:
- SetCandidateVer for all pseudo packages
- SetReInstall for the "all" package of a pseudo package
+ - use the new MatchAgainstConfig for the DefaultRootSetFunc
* apt-pkg/contrib/error.{cc,h}:
- complete rewrite but use the same API
- add NOTICE and DEBUG as new types of a message
- add a simple stack handling to be able to delay error handling
* apt-pkg/aptconfiguration.cc:
- show a deprecation notice for APT::Acquire::Translation
+ * apt-pkg/contrib/configuration.{cc,h}:
+ - add a wrapper to match strings against configurable regex patterns
- -- David Kalnischkies <kalnischkies@gmail.com> Sat, 26 Jun 2010 09:01:40 +0200
+ -- David Kalnischkies <kalnischkies@gmail.com> Sat, 26 Jun 2010 13:28:48 +0200
apt (0.7.26~exp7) experimental; urgency=low