diff options
Diffstat (limited to 'apt-pkg/cachefilter.cc')
-rw-r--r-- | apt-pkg/cachefilter.cc | 49 |
1 files changed, 47 insertions, 2 deletions
diff --git a/apt-pkg/cachefilter.cc b/apt-pkg/cachefilter.cc index 9ec3fa699..58cc812bf 100644 --- a/apt-pkg/cachefilter.cc +++ b/apt-pkg/cachefilter.cc @@ -9,12 +9,14 @@ #include <apt-pkg/cachefilter.h> #include <apt-pkg/error.h> #include <apt-pkg/pkgcache.h> - -#include <apti18n.h> +#include <apt-pkg/strutl.h> #include <string> #include <regex.h> +#include <fnmatch.h> + +#include <apti18n.h> /*}}}*/ namespace APT { namespace CacheFilter { @@ -52,5 +54,48 @@ PackageNameMatchesRegEx::~PackageNameMatchesRegEx() { /*{{{*/ delete pattern; } /*}}}*/ + +// CompleteArch to <kernel>-<cpu> tuple /*{{{*/ +//---------------------------------------------------------------------- +/* The complete architecture, consisting of <kernel>-<cpu>. */ +static std::string CompleteArch(std::string const &arch) { + if (arch.find('-') != std::string::npos) { + // ensure that only -any- is replaced and not something like company- + std::string complete = std::string("-").append(arch).append("-"); + complete = SubstVar(complete, "-any-", "-*-"); + complete = complete.substr(1, complete.size()-2); + return complete; + } + else if (arch == "any") return "*-*"; + else return "linux-" + arch; +} + /*}}}*/ +PackageArchitectureMatchesSpecification::PackageArchitectureMatchesSpecification(std::string const &pattern, bool const isPattern) :/*{{{*/ + literal(pattern), isPattern(isPattern), d(NULL) { + complete = CompleteArch(pattern); +} + /*}}}*/ +bool PackageArchitectureMatchesSpecification::operator() (char const * const &arch) {/*{{{*/ + if (strcmp(literal.c_str(), arch) == 0 || + strcmp(complete.c_str(), arch) == 0) + return true; + std::string const pkgarch = CompleteArch(arch); + if (isPattern == true) + return fnmatch(complete.c_str(), pkgarch.c_str(), 0) == 0; + return fnmatch(pkgarch.c_str(), complete.c_str(), 0) == 0; +} + /*}}}*/ +bool PackageArchitectureMatchesSpecification::operator() (pkgCache::PkgIterator const &Pkg) {/*{{{*/ + return (*this)(Pkg.Arch()); +} + /*}}}*/ +bool PackageArchitectureMatchesSpecification::operator() (pkgCache::VerIterator const &Ver) {/*{{{*/ + return (*this)(Ver.ParentPkg()); +} + /*}}}*/ +PackageArchitectureMatchesSpecification::~PackageArchitectureMatchesSpecification() { /*{{{*/ +} + /*}}}*/ + } } |