From 96ed8deac9ac967065553e537a23f02a739fc7b2 Mon Sep 17 00:00:00 2001 From: Jaroslav Mracek Date: Tue, 23 Apr 2024 14:08:53 +0200 Subject: [PATCH] Add file search result for repoquery --whatprovides File provides are not only present in file provides, but also in normal provides. The code did not searched for file provides when filter_provide() already gained a result. It means that for some glob pattern, dnf5 provides incomplete results without the patch. Closes: https://github.com/rpm-software-management/dnf5/issues/1153 --- dnf5/commands/repoquery/repoquery.cpp | 18 ++++++++++++++---- doc/commands/repoquery.8.rst | 2 +- doc/misc/specs.7.rst | 1 + 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/dnf5/commands/repoquery/repoquery.cpp b/dnf5/commands/repoquery/repoquery.cpp index 4e112e68e..999815437 100644 --- a/dnf5/commands/repoquery/repoquery.cpp +++ b/dnf5/commands/repoquery/repoquery.cpp @@ -693,11 +693,21 @@ void RepoqueryCommand::run() { if (!whatprovides->get_value().empty()) { auto provides_query = result_query; provides_query.filter_provides(whatprovides->get_value(), libdnf5::sack::QueryCmp::GLOB); - if (!provides_query.empty()) { - result_query = provides_query; + + std::vector file_patterns; + // Search additionally for files to ensure that all providers are listed + // Limit file search only to files patterns to ensure that we are not providing unexpected resurts. + // Additionally it is a performance optimization - file search is very expensive + for (auto & capability : whatprovides->get_value()) { + if (libdnf5::utils::is_file_pattern(capability)) { + file_patterns.push_back(capability); + } + } + if (!file_patterns.empty()) { + result_query.filter_file(file_patterns, libdnf5::sack::QueryCmp::GLOB); + result_query |= provides_query; } else { - // If provides query doesn't match anything try matching files - result_query.filter_file(whatprovides->get_value(), libdnf5::sack::QueryCmp::GLOB); + result_query = provides_query; } } diff --git a/doc/commands/repoquery.8.rst b/doc/commands/repoquery.8.rst index 737aeceac..ff03f9e30 100644 --- a/doc/commands/repoquery.8.rst +++ b/doc/commands/repoquery.8.rst @@ -159,7 +159,7 @@ Options | This is a list option. ``--whatprovides=CAPABILITY,...`` - | Limit to packages that provide any of . + | Limit to packages that provide any of . Capabilities :ref:`specifying a file provide ` are also matched against file provides. | This is a list option. ``--whatrecommends=CAPABILITY,...`` diff --git a/doc/misc/specs.7.rst b/doc/misc/specs.7.rst index 4813f0b87..aeaaf465f 100644 --- a/doc/misc/specs.7.rst +++ b/doc/misc/specs.7.rst @@ -153,6 +153,7 @@ packages providing the given spec. This can either be an explicit provide, an implicit provide (i.e. name of the package) or a file provide. The selection is case-sensitive and globbing is supported. +.. _file_provides_ref-label: Specifying File Provides ------------------------