summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Andres Klode <julian.klode@canonical.com>2019-11-26 12:01:42 +0100
committerJulian Andres Klode <julian.klode@canonical.com>2019-11-26 12:01:42 +0100
commita93b4443c18ee211691f7b336b161fea7d1df699 (patch)
treeedfa02e104ff9f55948de510f2caf6f7f1665bfe
parent96f795bce665a1907b885bd2d57d6ab22b0a4199 (diff)
patterns: Add ?section
-rw-r--r--apt-pkg/cachefilter-patterns.cc2
-rw-r--r--apt-pkg/cachefilter-patterns.h10
-rw-r--r--doc/apt-patterns.7.xml3
-rwxr-xr-xtest/integration/test-apt-patterns9
4 files changed, 22 insertions, 2 deletions
diff --git a/apt-pkg/cachefilter-patterns.cc b/apt-pkg/cachefilter-patterns.cc
index 8214c388a..a9f76ff1d 100644
--- a/apt-pkg/cachefilter-patterns.cc
+++ b/apt-pkg/cachefilter-patterns.cc
@@ -244,6 +244,8 @@ std::unique_ptr<APT::CacheFilter::Matcher> PatternParser::aPattern(std::unique_p
return std::make_unique<Patterns::PackageIsObsolete>();
if (node->matches("?origin", 1, 1))
return std::make_unique<Patterns::VersionIsOrigin>(aWord(node->arguments[0]));
+ if (node->matches("?section", 1, 1))
+ return std::make_unique<Patterns::VersionIsSection>(aWord(node->arguments[0]));
if (node->matches("?source-package", 1, 1))
return std::make_unique<Patterns::VersionIsSourcePackage>(aWord(node->arguments[0]));
if (node->matches("?source-version", 1, 1))
diff --git a/apt-pkg/cachefilter-patterns.h b/apt-pkg/cachefilter-patterns.h
index 8c5561c82..bd8ce7e7e 100644
--- a/apt-pkg/cachefilter-patterns.h
+++ b/apt-pkg/cachefilter-patterns.h
@@ -320,6 +320,16 @@ struct VersionIsOrigin : public VersionAnyMatcher
}
};
+struct VersionIsSection : public VersionAnyMatcher
+{
+ BaseRegexMatcher matcher;
+ VersionIsSection(std::string const &pattern) : matcher(pattern) {}
+ bool operator()(pkgCache::VerIterator const &Ver) override
+ {
+ return matcher(Ver.Section());
+ }
+};
+
struct VersionIsSourcePackage : public VersionAnyMatcher
{
BaseRegexMatcher matcher;
diff --git a/doc/apt-patterns.7.xml b/doc/apt-patterns.7.xml
index 04f97e878..219d2c209 100644
--- a/doc/apt-patterns.7.xml
+++ b/doc/apt-patterns.7.xml
@@ -135,6 +135,9 @@
<varlistentry><term><code>?origin(REGEX)</code></term>
<listitem><para>Selects versions that come from the origin that matches the specified regular expression. Origin, here, means the values after <code>o=</code> in <command>apt-cache policy</command>.</para></listitem>
</varlistentry>
+ <varlistentry><term><code>?section(REGEX)</code></term>
+ <listitem><para>Selects versions where the section matches the specified regular expression.</para></listitem>
+ </varlistentry>
<varlistentry><term><code>?source-package(REGEX)</code></term>
<listitem><para>Selects versions where the source package name matches the specified regular expression.</para></listitem>
</varlistentry>
diff --git a/test/integration/test-apt-patterns b/test/integration/test-apt-patterns
index f726d0576..06c552479 100755
--- a/test/integration/test-apt-patterns
+++ b/test/integration/test-apt-patterns
@@ -5,7 +5,7 @@ TESTDIR="$(readlink -f "$(dirname "$0")")"
setupenvironment
configarchitecture 'i386' 'amd64'
-insertpackage 'unstable' 'available' 'all' '1.0'
+insertpackage 'unstable' 'available' 'all' '1.0' 'Section: asection'
insertinstalledpackage 'manual1' 'i386' '1.0' 'Depends: automatic1'
insertinstalledpackage 'manual2' 'i386' '1.0'
@@ -13,7 +13,8 @@ insertinstalledpackage 'manual2' 'i386' '1.0'
insertinstalledpackage 'automatic1' 'i386' '1.0' 'Source: automatic (0)'
insertinstalledpackage 'automatic2' 'i386' '1.0' 'Source: automatic (1)'
-insertinstalledpackage 'essential' 'i386' '1.0' 'Essential: yes'
+insertinstalledpackage 'essential' 'i386' '1.0' 'Essential: yes
+Section: asection'
insertinstalledpackage 'conf-only' 'i386' '1.0' '' '' 'deinstall ok config-files'
insertinstalledpackage 'broken' 'i386' '1.0' 'Depends: does-not-exist'
@@ -190,6 +191,10 @@ foreign/unstable 2.0 amd64
not-obsolete/unstable 2.0 i386 [upgradable from: 1.0]" apt list '?origin(^meow$)'
testsuccessequal "Listing...
+available/unstable 1.0 all
+essential/now 1.0 i386 [installed,local]" apt list '?section(asection)'
+
+testsuccessequal "Listing...
automatic1/now 1.0 i386 [installed,local]
automatic2/now 1.0 i386 [installed,local]" apt list '?source-package(^automatic$)'