summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Andres Klode <julian.klode@canonical.com>2019-08-15 13:31:30 +0200
committerJulian Andres Klode <julian.klode@canonical.com>2019-08-15 20:21:34 +0200
commita3e9ab661b2d670f7d0da53a5f56c52af0763c5b (patch)
treebf064b629923e5d9598ea42114521376b8e3385b
parent89790c11799c4144e37a6a1f0dbe0f6fff89ea89 (diff)
downloadapt-a3e9ab661b2d670f7d0da53a5f56c52af0763c5b.tar.gz
Add ?config-files and ?installed patterns
These two are mutually exclusive states of installed-ness. And ?installed package is fully unpacked and configured; a ?config-files package only has config files left.
-rw-r--r--apt-pkg/cachefilter-patterns.cc4
-rw-r--r--apt-pkg/cachefilter-patterns.h19
-rw-r--r--doc/apt-patterns.7.xml9
-rwxr-xr-xtest/integration/test-apt-patterns18
4 files changed, 50 insertions, 0 deletions
diff --git a/apt-pkg/cachefilter-patterns.cc b/apt-pkg/cachefilter-patterns.cc
index b97d65a03..0f23890b4 100644
--- a/apt-pkg/cachefilter-patterns.cc
+++ b/apt-pkg/cachefilter-patterns.cc
@@ -212,10 +212,14 @@ std::unique_ptr<APT::CacheFilter::Matcher> PatternParser::aPattern(std::unique_p
return std::make_unique<APT::CacheFilter::PackageArchitectureMatchesSpecification>(aWord(node->arguments[0]));
if (node->matches("?automatic", 0, 0))
return std::make_unique<Patterns::PackageIsAutomatic>(file);
+ if (node->matches("?config-files", 0, 0))
+ return std::make_unique<Patterns::PackageIsConfigFiles>();
if (node->matches("?false", 0, 0))
return std::make_unique<APT::CacheFilter::FalseMatcher>();
if (node->matches("?garbage", 0, 0))
return std::make_unique<Patterns::PackageIsGarbage>(file);
+ if (node->matches("?installed", 0, 0))
+ return std::make_unique<Patterns::PackageIsInstalled>(file);
if (node->matches("?name", 1, 1))
return std::make_unique<APT::CacheFilter::PackageNameMatchesRegEx>(aWord(node->arguments[0]));
if (node->matches("?not", 1, 1))
diff --git a/apt-pkg/cachefilter-patterns.h b/apt-pkg/cachefilter-patterns.h
index 68ad32f9a..7770385c9 100644
--- a/apt-pkg/cachefilter-patterns.h
+++ b/apt-pkg/cachefilter-patterns.h
@@ -128,6 +128,14 @@ struct PackageIsAutomatic : public PackageMatcher
}
};
+struct PackageIsConfigFiles : public PackageMatcher
+{
+ bool operator()(pkgCache::PkgIterator const &Pkg) override
+ {
+ return Pkg->CurrentState == pkgCache::State::ConfigFiles;
+ }
+};
+
struct PackageIsGarbage : public PackageMatcher
{
pkgCacheFile *Cache;
@@ -139,6 +147,17 @@ struct PackageIsGarbage : public PackageMatcher
}
};
+struct PackageIsInstalled : public PackageMatcher
+{
+ pkgCacheFile *Cache;
+ explicit PackageIsInstalled(pkgCacheFile *Cache) : Cache(Cache) {}
+ bool operator()(pkgCache::PkgIterator const &Pkg) override
+ {
+ assert(Cache != nullptr);
+ return Pkg->CurrentVer != 0;
+ }
+};
+
struct PackageIsObsolete : public PackageMatcher
{
bool operator()(pkgCache::PkgIterator const &pkg) override
diff --git a/doc/apt-patterns.7.xml b/doc/apt-patterns.7.xml
index 6058d7a74..64dad4dd4 100644
--- a/doc/apt-patterns.7.xml
+++ b/doc/apt-patterns.7.xml
@@ -72,9 +72,15 @@
<varlistentry><term><code>?automatic</code></term>
<listitem><para>Selects packages that were installed automatically.</para></listitem>
</varlistentry>
+ <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>?garbage</code></term>
<listitem><para>Selects packages that can be removed automatically.</para></listitem>
</varlistentry>
+ <varlistentry><term><code>?installed</code></term>
+ <listitem><para>Selects packages that are currently installed.</para></listitem>
+ </varlistentry>
<varlistentry><term><code>?name(REGEX)</code></term>
<listitem><para>Selects packages where the name matches the given regular expression.</para></listitem>
</varlistentry>
@@ -93,6 +99,9 @@
<varlistentry><term><code>apt remove ?garbage</code></term>
<listitem><para>Remove all packages that are automatically installed and no longer needed - same as apt autoremove</para></listitem>
</varlistentry>
+ <varlistentry><term><code>apt purge ?config-files</code></term>
+ <listitem><para>Purge all packages that only have configuration files left</para></listitem>
+ </varlistentry>
</variablelist>
</refsect1>
diff --git a/test/integration/test-apt-patterns b/test/integration/test-apt-patterns
index 549089d8a..b84605256 100755
--- a/test/integration/test-apt-patterns
+++ b/test/integration/test-apt-patterns
@@ -117,10 +117,28 @@ automatic1/now 1.0 i386 [installed,local]
automatic2/now 1.0 i386 [installed,local]" apt list '?automatic'
testsuccessequal "Listing...
+conf-only/now 1.0 i386 [residual-config]" apt list '?config-files'
+
+testsuccessequal "Listing...
automatic2/now 1.0 i386 [installed,local]" apt list '?garbage'
testsuccessequal "Listing...
automatic1/now 1.0 i386 [installed,local]
+automatic2/now 1.0 i386 [installed,local]
+broken/now 1.0 i386 [installed,local]
+dpkg/now 1.16.2+fake all [installed,local]
+essential/now 1.0 i386 [installed,local]
+manual1/now 1.0 i386 [installed,local]
+manual2/now 1.0 i386 [installed,local]
+not-obsolete/unstable 2.0 i386 [upgradable from: 1.0]" apt list '?installed'
+
+testsuccessequal "Listing...
+available/unstable 1.0 all
+conf-only/now 1.0 i386 [residual-config]
+foreign/unstable 2.0 amd64" apt list '?not(?installed)'
+
+testsuccessequal "Listing...
+automatic1/now 1.0 i386 [installed,local]
automatic2/now 1.0 i386 [installed,local]" apt list '?name(^automatic)'
testsuccessequal "Listing...