diff options
author | Julian Andres Klode <julian.klode@canonical.com> | 2019-08-15 13:36:04 +0200 |
---|---|---|
committer | Julian Andres Klode <julian.klode@canonical.com> | 2019-08-15 20:21:34 +0200 |
commit | af674d82d5cd36e22223ec49675d32adad07e0a9 (patch) | |
tree | ec87d76fccf193bc56756e56b0275d2701685f09 | |
parent | 08762e0e4e2923360339eeb4d8ed26a00d7f1de5 (diff) |
Add the ?exact-name pattern
The ?exact-name pattern matches the name exactly, there is
no substring matching going on, or any regular expression
or fnmatch magic.
-rw-r--r-- | apt-pkg/cachefilter-patterns.cc | 2 | ||||
-rw-r--r-- | apt-pkg/cachefilter-patterns.h | 10 | ||||
-rw-r--r-- | doc/apt-patterns.7.xml | 3 | ||||
-rwxr-xr-x | test/integration/test-apt-patterns | 4 |
4 files changed, 19 insertions, 0 deletions
diff --git a/apt-pkg/cachefilter-patterns.cc b/apt-pkg/cachefilter-patterns.cc index ea35b9c46..f078924ff 100644 --- a/apt-pkg/cachefilter-patterns.cc +++ b/apt-pkg/cachefilter-patterns.cc @@ -218,6 +218,8 @@ std::unique_ptr<APT::CacheFilter::Matcher> PatternParser::aPattern(std::unique_p return std::make_unique<Patterns::PackageIsConfigFiles>(); if (node->matches("?essential", 0, 0)) return std::make_unique<Patterns::PackageIsEssential>(); + if (node->matches("?exact-name", 1, 1)) + return std::make_unique<Patterns::PackageHasExactName>(aWord(node->arguments[0])); if (node->matches("?false", 0, 0)) return std::make_unique<APT::CacheFilter::FalseMatcher>(); if (node->matches("?garbage", 0, 0)) diff --git a/apt-pkg/cachefilter-patterns.h b/apt-pkg/cachefilter-patterns.h index 17f1fc752..993839425 100644 --- a/apt-pkg/cachefilter-patterns.h +++ b/apt-pkg/cachefilter-patterns.h @@ -166,6 +166,16 @@ struct PackageIsEssential : public PackageMatcher } }; +struct PackageHasExactName : public PackageMatcher +{ + std::string name; + explicit PackageHasExactName(std::string name) : name(name) {} + bool operator()(pkgCache::PkgIterator const &Pkg) override + { + return Pkg.Name() == name; + } +}; + struct PackageIsInstalled : public PackageMatcher { pkgCacheFile *Cache; diff --git a/doc/apt-patterns.7.xml b/doc/apt-patterns.7.xml index 11031be95..2eda77b55 100644 --- a/doc/apt-patterns.7.xml +++ b/doc/apt-patterns.7.xml @@ -81,6 +81,9 @@ <varlistentry><term><code>?essential</code></term> <listitem><para>Selects packages that have Essential: yes set in their control file.</para></listitem> </varlistentry> + <varlistentry><term><code>?exact-name(NAME)</code></term> + <listitem><para>Selects packages with the exact specified name.</para></listitem> + </varlistentry> <varlistentry><term><code>?garbage</code></term> <listitem><para>Selects packages that can be removed automatically.</para></listitem> </varlistentry> diff --git a/test/integration/test-apt-patterns b/test/integration/test-apt-patterns index 1efb10d2d..c75793e55 100755 --- a/test/integration/test-apt-patterns +++ b/test/integration/test-apt-patterns @@ -125,6 +125,10 @@ conf-only/now 1.0 i386 [residual-config]" apt list '?config-files' testsuccessequal "Listing... essential/now 1.0 i386 [installed,local]" apt list '?essential' +testsuccessequal "Listing..." apt list '?exact-name(automatic)' +testsuccessequal "Listing... +automatic1/now 1.0 i386 [installed,local]" apt list '?exact-name(automatic1)' + testsuccessequal "Listing... automatic2/now 1.0 i386 [installed,local]" apt list '?garbage' |