summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Andres Klode <jak@debian.org>2021-10-18 13:36:20 +0000
committerJulian Andres Klode <jak@debian.org>2021-10-18 13:36:20 +0000
commitf6b08c78dcdda1734710a5ef01553f53ceb5c52e (patch)
treeb424e0113908194e71b602a277a13e6b136df61a
parentedf4b2169405e7ca6e21f408229e5fc4bbd4f4ed (diff)
parentcdfae5a9624e7283d372fce261efd018841d21cb (diff)
Merge branch 'bug-989558' into 'main'
add pattern to select packages by priority (closes: #989558) See merge request apt-team/apt!185
-rw-r--r--apt-pkg/cachefilter-patterns.cc3
-rw-r--r--apt-pkg/cachefilter-patterns.h16
-rw-r--r--doc/apt-patterns.7.xml3
-rwxr-xr-xtest/integration/test-apt-patterns10
4 files changed, 30 insertions, 2 deletions
diff --git a/apt-pkg/cachefilter-patterns.cc b/apt-pkg/cachefilter-patterns.cc
index 471e698d6..12d8ae748 100644
--- a/apt-pkg/cachefilter-patterns.cc
+++ b/apt-pkg/cachefilter-patterns.cc
@@ -56,6 +56,7 @@ static const constexpr struct
{"n"_sv, "?name"_sv, true},
{"o"_sv, "?obsolete"_sv, false},
{"O"_sv, "?origin"_sv, true},
+ {"p"_sv, "?priority"_sv, true},
{"s"_sv, "?section"_sv, true},
{"e"_sv, "?source-package"_sv, true},
{"T"_sv, "?true"_sv, false},
@@ -477,6 +478,8 @@ std::unique_ptr<APT::CacheFilter::Matcher> PatternParser::aPattern(std::unique_p
return std::make_unique<Patterns::PackageReverseDepends>(aPattern(node->arguments[0]), pkgCache::Dep::Enhances);
if (node->matches("?essential", 0, 0))
return std::make_unique<Patterns::PackageIsEssential>();
+ if (node->matches("?priority", 1, 1))
+ return std::make_unique<Patterns::VersionIsPriority>(aWord(node->arguments[0]));
if (node->matches("?exact-name", 1, 1))
return std::make_unique<Patterns::PackageHasExactName>(aWord(node->arguments[0]));
if (node->matches("?false", 0, 0))
diff --git a/apt-pkg/cachefilter-patterns.h b/apt-pkg/cachefilter-patterns.h
index e0c48dd12..d55cb6335 100644
--- a/apt-pkg/cachefilter-patterns.h
+++ b/apt-pkg/cachefilter-patterns.h
@@ -417,6 +417,22 @@ struct APT_HIDDEN VersionIsVersion : public VersionAnyMatcher
return matcher(Ver.VerStr());
}
};
+
+struct APT_HIDDEN VersionIsPriority : public VersionAnyMatcher
+{
+ std::string name;
+ explicit VersionIsPriority(std::string name) : name(name) {}
+ bool operator()(pkgCache::VerIterator const &Ver) override
+ {
+ std::string Mapping[] = {"", "required","important","standard",
+ "optional","extra"};
+ if (Ver->Priority > 0 && Ver->Priority < APT_ARRAY_SIZE(Mapping)) {
+ return name == Mapping[Ver->Priority];
+ }
+ return false;
+ }
+};
+
} // namespace Patterns
} // namespace Internal
} // namespace APT
diff --git a/doc/apt-patterns.7.xml b/doc/apt-patterns.7.xml
index 4f31b5d27..817ba9fa9 100644
--- a/doc/apt-patterns.7.xml
+++ b/doc/apt-patterns.7.xml
@@ -150,6 +150,9 @@
<varlistentry><term><code>?version(REGEX)</code></term><term><code>~VREGEX</code></term>
<listitem><para>Selects versions where the version string matches the specified regular expression.</para></listitem>
</varlistentry>
+ <varlistentry><term><code>?priority(NAME)</code></term><term><code>~pNAME</code></term>
+ <listitem><para>Selects versions where the Priority string equals the given name.</para></listitem>
+ </varlistentry>
</variablelist>
</refsect1>
diff --git a/test/integration/test-apt-patterns b/test/integration/test-apt-patterns
index 33df21d36..5355becff 100755
--- a/test/integration/test-apt-patterns
+++ b/test/integration/test-apt-patterns
@@ -15,6 +15,7 @@ insertinstalledpackage 'automatic2' 'i386' '1.0' 'Source: automatic (1)'
insertinstalledpackage 'essential' 'i386' '1.0' 'Essential: yes
Section: asection'
+insertinstalledpackage 'required' 'i386' '1.0' 'Priority: required'
insertinstalledpackage 'conf-only' 'i386' '1.0' '' '' 'deinstall ok config-files'
insertinstalledpackage 'broken' 'i386' '1.0' 'Depends: does-not-exist'
@@ -96,7 +97,8 @@ foreign/unstable 2.0 amd64
manual1/now 1.0 i386 [installed,local]
manual2/now 1.0 i386 [installed,local]
nosection/now 29 amd64 [installed,local]
-not-obsolete/unstable 2.0 i386 [upgradable from: 1.0]" apt list "$pattern"
+not-obsolete/unstable 2.0 i386 [upgradable from: 1.0]
+required/now 1.0 i386 [installed,local]" apt list "$pattern"
done
testsuccessequal "Listing..." apt list '?false'
testsuccessequal "Listing..." apt list '?not(?true)'
@@ -159,6 +161,9 @@ 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...
+required/now 1.0 i386 [installed,local]" apt list '?priority(required)'
+
testsuccessequal "Listing..." apt list '?exact-name(automatic)'
testsuccessequal "Listing...
automatic1/now 1.0 i386 [installed,local]" apt list '?exact-name(automatic1)'
@@ -175,7 +180,8 @@ essential/now 1.0 i386 [installed,local]
manual1/now 1.0 i386 [installed,local]
manual2/now 1.0 i386 [installed,local]
nosection/now 29 amd64 [installed,local]
-not-obsolete/unstable 2.0 i386 [upgradable from: 1.0]" apt list '?installed'
+not-obsolete/unstable 2.0 i386 [upgradable from: 1.0]
+required/now 1.0 i386 [installed,local]" apt list '?installed'
testsuccessequal "Listing...
available/unstable 1.0 all