Skip to content

Commit

Permalink
Add file search result for repoquery --whatprovides
Browse files Browse the repository at this point in the history
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: #1153
  • Loading branch information
j-mracek authored and m-blaha committed Apr 29, 2024
1 parent 4a05cfb commit 96ed8de
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
18 changes: 14 additions & 4 deletions dnf5/commands/repoquery/repoquery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> 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;
}
}

Expand Down
2 changes: 1 addition & 1 deletion doc/commands/repoquery.8.rst
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ Options
| This is a list option.
``--whatprovides=CAPABILITY,...``
| Limit to packages that provide any of <capabilities>.
| Limit to packages that provide any of <capabilities>. Capabilities :ref:`specifying a file provide <file_provides_ref-label>` are also matched against file provides.
| This is a list option.
``--whatrecommends=CAPABILITY,...``
Expand Down
1 change: 1 addition & 0 deletions doc/misc/specs.7.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
------------------------
Expand Down

0 comments on commit 96ed8de

Please sign in to comment.