summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Andres Klode <julian.klode@canonical.com>2019-08-15 13:35:01 +0200
committerJulian Andres Klode <julian.klode@canonical.com>2019-08-15 20:21:34 +0200
commit08762e0e4e2923360339eeb4d8ed26a00d7f1de5 (patch)
tree5e6aa36f27e8d8dee343c6aec57a120c5032bd5f
parent9282c9094ab3e77cebe90e97b2f9a5fc21463e2f (diff)
downloadapt-08762e0e4e2923360339eeb4d8ed26a00d7f1de5.tar.gz
Add ?essential pattern
This matches all packages where at least one of the versions is marked essential; or well, whenver apt considers a package essential.
-rw-r--r--apt-pkg/cachefilter-patterns.cc2
-rw-r--r--apt-pkg/cachefilter-patterns.h7
-rw-r--r--doc/apt-patterns.7.xml3
-rwxr-xr-xtest/integration/test-apt-patterns3
4 files changed, 15 insertions, 0 deletions
diff --git a/apt-pkg/cachefilter-patterns.cc b/apt-pkg/cachefilter-patterns.cc
index a180cf78e..ea35b9c46 100644
--- a/apt-pkg/cachefilter-patterns.cc
+++ b/apt-pkg/cachefilter-patterns.cc
@@ -216,6 +216,8 @@ std::unique_ptr<APT::CacheFilter::Matcher> PatternParser::aPattern(std::unique_p
return std::make_unique<Patterns::PackageIsBroken>(file);
if (node->matches("?config-files", 0, 0))
return std::make_unique<Patterns::PackageIsConfigFiles>();
+ if (node->matches("?essential", 0, 0))
+ return std::make_unique<Patterns::PackageIsEssential>();
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 c219e5bcd..17f1fc752 100644
--- a/apt-pkg/cachefilter-patterns.h
+++ b/apt-pkg/cachefilter-patterns.h
@@ -158,6 +158,13 @@ struct PackageIsGarbage : public PackageMatcher
return (*Cache)[Pkg].Garbage;
}
};
+struct PackageIsEssential : public PackageMatcher
+{
+ bool operator()(pkgCache::PkgIterator const &Pkg) override
+ {
+ return (Pkg->Flags & pkgCache::Flag::Essential) != 0;
+ }
+};
struct PackageIsInstalled : public PackageMatcher
{
diff --git a/doc/apt-patterns.7.xml b/doc/apt-patterns.7.xml
index e1c64de8e..11031be95 100644
--- a/doc/apt-patterns.7.xml
+++ b/doc/apt-patterns.7.xml
@@ -78,6 +78,9 @@
<varlistentry><term><code>?config-files</code></term>
<listitem><para>Selects packages that are not fully installed, but have solely residual configuration files left.</para></listitem>
</varlistentry>
+ <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>?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 e566c6bd2..1efb10d2d 100755
--- a/test/integration/test-apt-patterns
+++ b/test/integration/test-apt-patterns
@@ -123,6 +123,9 @@ testsuccessequal "Listing...
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...
automatic2/now 1.0 i386 [installed,local]" apt list '?garbage'
testsuccessequal "Listing...