summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apt-pkg/cachefilter-patterns.cc2
-rw-r--r--apt-pkg/cachefilter-patterns.h8
-rw-r--r--doc/apt-patterns.7.xml5
-rwxr-xr-xtest/integration/test-apt-patterns6
4 files changed, 21 insertions, 0 deletions
diff --git a/apt-pkg/cachefilter-patterns.cc b/apt-pkg/cachefilter-patterns.cc
index f078924ff..986faaf52 100644
--- a/apt-pkg/cachefilter-patterns.cc
+++ b/apt-pkg/cachefilter-patterns.cc
@@ -236,6 +236,8 @@ std::unique_ptr<APT::CacheFilter::Matcher> PatternParser::aPattern(std::unique_p
return std::make_unique<APT::CacheFilter::TrueMatcher>();
if (node->matches("?upgradable", 0, 0))
return std::make_unique<Patterns::PackageIsUpgradable>(file);
+ if (node->matches("?virtual", 0, 0))
+ return std::make_unique<Patterns::PackageIsVirtual>();
if (node->matches("?x-name-fnmatch", 1, 1))
return std::make_unique<APT::CacheFilter::PackageNameMatchesFnmatch>(aWord(node->arguments[0]));
diff --git a/apt-pkg/cachefilter-patterns.h b/apt-pkg/cachefilter-patterns.h
index 993839425..d37da815f 100644
--- a/apt-pkg/cachefilter-patterns.h
+++ b/apt-pkg/cachefilter-patterns.h
@@ -221,6 +221,14 @@ struct PackageIsUpgradable : public PackageMatcher
return Pkg->CurrentVer != 0 && (*Cache)[Pkg].Upgradable();
}
};
+
+struct PackageIsVirtual : public PackageMatcher
+{
+ bool operator()(pkgCache::PkgIterator const &Pkg) override
+ {
+ return Pkg->VersionList == 0;
+ }
+};
} // namespace Patterns
} // namespace Internal
} // namespace APT
diff --git a/doc/apt-patterns.7.xml b/doc/apt-patterns.7.xml
index 2eda77b55..efd4293dc 100644
--- a/doc/apt-patterns.7.xml
+++ b/doc/apt-patterns.7.xml
@@ -99,6 +99,11 @@
<varlistentry><term><code>?upgradable</code></term>
<listitem><para>Selects packages that can be upgraded (have a newer candidate).</para></listitem>
</varlistentry>
+ <varlistentry><term><code>?virtual</code></term>
+ <listitem><para>Selects all virtual packages; that is packages without a version.
+ These exist when they are referenced somewhere in the archive,
+ for example because something depends on that name.</para></listitem>
+ </varlistentry>
</variablelist>
</refsect1>
diff --git a/test/integration/test-apt-patterns b/test/integration/test-apt-patterns
index c75793e55..92c76edd1 100755
--- a/test/integration/test-apt-patterns
+++ b/test/integration/test-apt-patterns
@@ -161,6 +161,12 @@ testsuccessequal "Listing...
not-obsolete/unstable 2.0 i386 [upgradable from: 1.0]
N: There is 1 additional version. Please use the '-a' switch to see it" apt list '?upgradable'
+testsuccessequal "Package: does-not-exist
+State: not a real package (virtual)
+N: Can't select candidate version from package does-not-exist as it has no candidate
+N: Can't select versions from package 'does-not-exist' as it is purely virtual
+N: No packages found" apt show '?virtual'
+
testsuccessequal "Listing..." apt list '?x-name-fnmatch(1)'
testsuccessequal "Listing...
automatic1/now 1.0 i386 [installed,local]