From 08762e0e4e2923360339eeb4d8ed26a00d7f1de5 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Thu, 15 Aug 2019 13:35:01 +0200 Subject: 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. --- apt-pkg/cachefilter-patterns.cc | 2 ++ apt-pkg/cachefilter-patterns.h | 7 +++++++ doc/apt-patterns.7.xml | 3 +++ test/integration/test-apt-patterns | 3 +++ 4 files changed, 15 insertions(+) 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 PatternParser::aPattern(std::unique_p return std::make_unique(file); if (node->matches("?config-files", 0, 0)) return std::make_unique(); + if (node->matches("?essential", 0, 0)) + return std::make_unique(); if (node->matches("?false", 0, 0)) return std::make_unique(); 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 @@ ?config-files Selects packages that are not fully installed, but have solely residual configuration files left. + ?essential + Selects packages that have Essential: yes set in their control file. + ?garbage Selects packages that can be removed automatically. 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 @@ -122,6 +122,9 @@ broken/now 1.0 i386 [installed,local]" apt list '?broken' 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' -- cgit v1.2.3