diff options
author | Julian Andres Klode <julian.klode@canonical.com> | 2020-12-14 14:28:35 +0100 |
---|---|---|
committer | Julian Andres Klode <julian.klode@canonical.com> | 2020-12-27 13:36:07 +0100 |
commit | 53d18fe48618c9864de021cc5862685faac7c752 (patch) | |
tree | 75426646b4aac37272f746b97388f52002922092 | |
parent | 4215b6b2ce64f7bd0988c63c8d7d3e34833ec813 (diff) |
patterns: Add dependency patterns ?depends, ?conflicts, etc.
These match the target package, not target versions which is
slightly unfortunate but might make sense. Maybe we should add
a version that matches Versions instead.
-rw-r--r-- | apt-pkg/cachefilter-patterns.cc | 29 | ||||
-rw-r--r-- | apt-pkg/cachefilter-patterns.h | 22 | ||||
-rw-r--r-- | doc/apt-patterns.7.xml | 19 |
3 files changed, 70 insertions, 0 deletions
diff --git a/apt-pkg/cachefilter-patterns.cc b/apt-pkg/cachefilter-patterns.cc index fded7d92f..4a99635db 100644 --- a/apt-pkg/cachefilter-patterns.cc +++ b/apt-pkg/cachefilter-patterns.cc @@ -28,6 +28,17 @@ static const constexpr struct {"M"_sv, "?automatic"_sv, false}, {"b"_sv, "?broken"_sv, false}, {"c"_sv, "?config-files"_sv, false}, + // FIXME: The words after ~D should be case-insensitive + {"DDepends:"_sv, "?depends"_sv, true}, + {"DPre-Depends:"_sv, "?pre-depends"_sv, true}, + {"DSuggests:"_sv, "?suggests"_sv, true}, + {"DRecommends:"_sv, "?recommends"_sv, true}, + {"DConflicts:"_sv, "?conflicts"_sv, true}, + {"DReplaces:"_sv, "?replaces"_sv, true}, + {"DObsoletes:"_sv, "?obsoletes"_sv, true}, + {"DBreaks:"_sv, "?breaks"_sv, true}, + {"DEnhances:"_sv, "?enhances"_sv, true}, + {"D"_sv, "?depends"_sv, true}, {"E"_sv, "?essential"_sv, false}, {"F"_sv, "?false"_sv, false}, {"g"_sv, "?garbage"_sv, false}, @@ -418,6 +429,24 @@ std::unique_ptr<APT::CacheFilter::Matcher> PatternParser::aPattern(std::unique_p return std::make_unique<Patterns::PackageIsBroken>(file); if (node->matches("?config-files", 0, 0)) return std::make_unique<Patterns::PackageIsConfigFiles>(); + if (node->matches("?depends", 1, 1)) + return std::make_unique<Patterns::VersionDepends>(aPattern(node->arguments[0])); + if (node->matches("?predepends", 1, 1)) + return std::make_unique<Patterns::VersionDepends>(aPattern(node->arguments[0]), pkgCache::Dep::PreDepends); + if (node->matches("?suggests", 1, 1)) + return std::make_unique<Patterns::VersionDepends>(aPattern(node->arguments[0]), pkgCache::Dep::Suggests); + if (node->matches("?recommends", 1, 1)) + return std::make_unique<Patterns::VersionDepends>(aPattern(node->arguments[0]), pkgCache::Dep::Recommends); + if (node->matches("?conflicts", 1, 1)) + return std::make_unique<Patterns::VersionDepends>(aPattern(node->arguments[0]), pkgCache::Dep::Conflicts); + if (node->matches("?replaces", 1, 1)) + return std::make_unique<Patterns::VersionDepends>(aPattern(node->arguments[0]), pkgCache::Dep::Replaces); + if (node->matches("?obsoletes", 1, 1)) + return std::make_unique<Patterns::VersionDepends>(aPattern(node->arguments[0]), pkgCache::Dep::Obsoletes); + if (node->matches("?breaks", 1, 1)) + return std::make_unique<Patterns::VersionDepends>(aPattern(node->arguments[0]), pkgCache::Dep::DpkgBreaks); + if (node->matches("?enhances", 1, 1)) + return std::make_unique<Patterns::VersionDepends>(aPattern(node->arguments[0]), pkgCache::Dep::Enhances); if (node->matches("?essential", 0, 0)) return std::make_unique<Patterns::PackageIsEssential>(); if (node->matches("?exact-name", 1, 1)) diff --git a/apt-pkg/cachefilter-patterns.h b/apt-pkg/cachefilter-patterns.h index d64bc4ccf..048c7041f 100644 --- a/apt-pkg/cachefilter-patterns.h +++ b/apt-pkg/cachefilter-patterns.h @@ -295,6 +295,28 @@ struct APT_HIDDEN VersionIsAllVersions : public Matcher } }; +struct APT_HIDDEN VersionDepends : public VersionAnyMatcher +{ + std::unique_ptr<APT::CacheFilter::Matcher> base; + pkgCache::Dep::DepType type; + VersionDepends(std::unique_ptr<APT::CacheFilter::Matcher> base, pkgCache::Dep::DepType type = pkgCache::Dep::Depends) : base(std::move(base)), type(type) {} + bool operator()(pkgCache::GrpIterator const &) override { return false; } + bool operator()(pkgCache::VerIterator const &Ver) override + { + for (auto D = Ver.DependsList(); not D.end(); D++) + { + if (D.IsImplicit()) + continue; + if (D->Type != type) + continue; + if ((*base)(D.TargetPkg())) + return true; + } + + return false; + } +}; + struct APT_HIDDEN VersionIsAnyVersion : public VersionAnyMatcher { std::unique_ptr<APT::CacheFilter::Matcher> base; diff --git a/doc/apt-patterns.7.xml b/doc/apt-patterns.7.xml index 168ba3c59..161d8ded3 100644 --- a/doc/apt-patterns.7.xml +++ b/doc/apt-patterns.7.xml @@ -153,7 +153,23 @@ </variablelist> </refsect1> + <refsect1><title>Package relationship patterns</title> + <para>These patterns match specific package versions that depend/conflict with some other packages.</para> + <variablelist> + <varlistentry> + <term><code>?depends(PATTERN)</code></term><term><code>~DPATTERN</code></term> + <term><code>?pre-depends(PATTERN)</code></term><term><code>~DPre-Depends:PATTERN</code></term> + <term><code>?suggests(PATTERN)</code></term><term><code>~DSuggests:PATTERN</code></term> + <term><code>?conflicts(PATTERN)</code></term><term><code>~DConflicts:PATTERN</code></term> + <term><code>?replaces(PATTERN)</code></term><term><code>~DReplaces:PATTERN</code></term> + <term><code>?obsoletes(PATTERN)</code></term><term><code>~DObsoletes:PATTERN</code></term> + <term><code>?breaks(PATTERN)</code></term><term><code>~DBreaks:PATTERN</code></term> + <term><code>?enhances(PATTERN)</code></term><term><code>~DEnhances:PATTERN</code></term> + <listitem><para>Selects packages depending/pre-depending/suggesting/conflicting/etc on/with/ packages matching PATTERN.</para></listitem> + </varlistentry> + </variablelist> + </refsect1> <refsect1><title>Examples</title> <variablelist> <varlistentry><term><code>apt remove ?garbage</code></term> @@ -206,6 +222,9 @@ <para>Grouping patterns with <code>(...)</code> or writing <code>?or(A,B)</code> as <code>A|B</code> are not supported. We do not believe that the use of <code>|</code> is that common, and the grouping is not necessary without it.</para> </listitem> + <listitem> + <para>Dependency types for ~D and related operators need to be specified in the canonical case.</para> + </listitem> </itemizedlist> </refsect1> |