From 73f7408f6d164e595fb2e3a3df856a8f8168fcb9 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Fri, 13 Jan 2023 12:23:43 +0100 Subject: make ?installed pattern match installed version only when narrowed This is the correct behavior, but it was overlooked when aptitude patterns where ported. I remember wondering about this, but I checked the aptitude code and saw a check that CurrentVer != 0 or something and then apparently did not notice another implementation for version matching. --- apt-pkg/cachefilter-patterns.h | 5 +++++ doc/apt-patterns.7.xml | 5 ++++- test/integration/test-apt-patterns | 6 ++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/apt-pkg/cachefilter-patterns.h b/apt-pkg/cachefilter-patterns.h index 284fcc1cf..2d48a1cc9 100644 --- a/apt-pkg/cachefilter-patterns.h +++ b/apt-pkg/cachefilter-patterns.h @@ -212,6 +212,11 @@ struct APT_HIDDEN PackageIsInstalled : public PackageMatcher assert(Cache != nullptr); return Pkg->CurrentVer != 0; } + bool operator()(pkgCache::VerIterator const &Ver) override + { + assert(Cache != nullptr); + return Ver == Ver.ParentPkg().CurrentVer(); + } }; struct APT_HIDDEN PackageIsObsolete : public PackageMatcher diff --git a/doc/apt-patterns.7.xml b/doc/apt-patterns.7.xml index 45f2f9fd7..9ed8aa835 100644 --- a/doc/apt-patterns.7.xml +++ b/doc/apt-patterns.7.xml @@ -108,7 +108,7 @@ Selects packages that can be removed automatically. ?installed~i - Selects packages that are currently installed. + Selects packages that are currently installed. Since version 2.5.4, narrowing this pattern (see narrowing patterns above) makes it only match installed versions (see version patterns below). ?name(REGEX)~nREGEX Selects packages where the name matches the given regular expression. @@ -138,6 +138,9 @@ ?codename(REGEX) Selects versions that come from the codename that matches the specified regular expression. Codename, here, means the values after n= in apt-cache policy. + ?installed~i + Selects package versions that are currently installed. Versions prior to 2.5.4 only matched at the package level, hence ?any-version(?installed?version(2.0))matched even if 2.0 was not installed, but another version was. + ?origin(REGEX)~OREGEX Selects versions that come from the origin that matches the specified regular expression. Origin, here, means the values after o= in apt-cache policy. diff --git a/test/integration/test-apt-patterns b/test/integration/test-apt-patterns index 7f202710c..85370aee8 100755 --- a/test/integration/test-apt-patterns +++ b/test/integration/test-apt-patterns @@ -191,6 +191,12 @@ available/unstable 1.0 all conf-only/now 1.0 i386 [residual-config] foreign/unstable 2.0 amd64" apt list '?not(?installed)' +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 '?installed?exact-name(not-obsolete)?version(2.0)' + +testsuccessequal "Listing..." apt list '?narrow(?installed?exact-name(not-obsolete)?version(2.0))' + testsuccessequal "Listing... automatic1/now 1.0 i386 [installed,local] automatic2/now 1.0 i386 [installed,local]" apt list '?name(^automatic)' -- cgit v1.2.3-18-g5258 From 9a29ea6f6d0f9115044c0ccddde3dc6454d483da Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Fri, 13 Jan 2023 12:29:13 +0100 Subject: apt-patterns(7): Grouping with () and or using | are supported They have been since 1.9.9, lol --- doc/apt-patterns.7.xml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/doc/apt-patterns.7.xml b/doc/apt-patterns.7.xml index 9ed8aa835..9d4f0a94e 100644 --- a/doc/apt-patterns.7.xml +++ b/doc/apt-patterns.7.xml @@ -235,10 +235,6 @@ this requires the package to have required priority, but if you do not type the ~, it would require the package name to contain poptional. - - Grouping patterns with (...) or writing ?or(A,B) as A|B are not supported. We - do not believe that the use of | is that common, and the grouping is not necessary without it. - Dependency types for ~D and related operators need to be specified in the canonical case. -- cgit v1.2.3-18-g5258