From c94b507b92b3d833761f3e416d4d5bba709bf87f Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Thu, 15 Aug 2019 13:40:31 +0200 Subject: Add ?virtual pattern This matches any package that does not have versions. --- apt-pkg/cachefilter-patterns.cc | 2 ++ apt-pkg/cachefilter-patterns.h | 8 ++++++++ doc/apt-patterns.7.xml | 5 +++++ test/integration/test-apt-patterns | 6 ++++++ 4 files changed, 21 insertions(+) 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 PatternParser::aPattern(std::unique_p return std::make_unique(); if (node->matches("?upgradable", 0, 0)) return std::make_unique(file); + if (node->matches("?virtual", 0, 0)) + return std::make_unique(); if (node->matches("?x-name-fnmatch", 1, 1)) return std::make_unique(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 @@ ?upgradable Selects packages that can be upgraded (have a newer candidate). + ?virtual + 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. + 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] -- cgit v1.2.3