Skip to content

Commit

Permalink
Add a method accepting std::string for filter_provides()
Browse files Browse the repository at this point in the history
This is required for Python binding, because when string argument is
provided, binding convert it to vector of characters. The change might
be problematic because filter_provides({"dnf"}) stop to work.
  • Loading branch information
j-mracek committed Dec 14, 2023
1 parent 864061d commit e3048b5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
14 changes: 13 additions & 1 deletion include/libdnf5/rpm/package_query.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,12 +275,24 @@ class PackageQuery : public PackageSet {

/// Filter packages by their `provides`.
///
/// @param patterns A vector of strings the filter is matched against.
/// @param pattern A string the filter is matched against.
/// @param cmp_type A comparison (match) operator, defaults to `QueryCmp::EQ`.
/// Supported values: `EQ`, `NEQ`, `GLOB`, `NOT_GLOB`.
/// @since 5.0
//
// @replaces libdnf/sack/query.hpp:method:addFilter(int keyname, int cmp_type, const char *match) - cmp_type = HY_PKG_PROVIDES
void filter_provides(const std::string & pattern, libdnf5::sack::QueryCmp cmp_type = libdnf5::sack::QueryCmp::EQ) {
std::vector<std::string> patterns{pattern};
filter_provides(patterns, cmp_type);
};

/// Filter packages by their `provides`.
///
/// @param patterns A vector of strings the filter is matched against.
/// @param cmp_type A comparison (match) operator, defaults to `QueryCmp::EQ`.
/// Supported values: `EQ`, `NEQ`, `GLOB`, `NOT_GLOB`.
/// @since 5.0
//
// @replaces libdnf/sack/query.hpp:method:addFilter(int keyname, int cmp_type, const char **matches) - cmp_type = HY_PKG_PROVIDES
void filter_provides(
const std::vector<std::string> & patterns, libdnf5::sack::QueryCmp cmp_type = libdnf5::sack::QueryCmp::EQ);
Expand Down
2 changes: 1 addition & 1 deletion libdnf5/module/module_sack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ std::optional<std::pair<std::string, std::string>> ModuleSack::Impl::detect_plat
}

libdnf5::rpm::PackageQuery base_query(base);
base_query.filter_provides({"system-release"});
base_query.filter_provides("system-release");
base_query.filter_latest_evr();

// try to detect platform id from available packages
Expand Down
8 changes: 4 additions & 4 deletions test/libdnf5/rpm/test_package_query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ void RpmPackageQueryTest::test_filter_provides() {

// packages with Provides == "libpkg.so.0()(64bit)"
PackageQuery query1(base);
query1.filter_provides({"libpkg.so.0()(64bit)"});
query1.filter_provides("libpkg.so.0()(64bit)");

std::vector<Package> expected = {get_pkg("pkg-libs-1:1.2-4.x86_64")};
CPPUNIT_ASSERT_EQUAL(expected, to_vector(query1));
Expand All @@ -548,7 +548,7 @@ void RpmPackageQueryTest::test_filter_provides() {

// packages without Provides == "libpkg.so.0()(64bit)"
PackageQuery query2(base);
query2.filter_provides({"libpkg.so.0()(64bit)"}, libdnf5::sack::QueryCmp::NEQ);
query2.filter_provides("libpkg.so.0()(64bit)", libdnf5::sack::QueryCmp::NEQ);

expected = {
get_pkg("pkg-0:1.2-3.src"),
Expand Down Expand Up @@ -657,7 +657,7 @@ void RpmPackageQueryTest::test_filter_chain() {
query.filter_version({"1.2"});
query.filter_release({"3"});
query.filter_arch({"x86_64"});
query.filter_provides({"foo"}, libdnf5::sack::QueryCmp::NEQ);
query.filter_provides("foo", libdnf5::sack::QueryCmp::NEQ);
query.filter_requires({"foo"}, libdnf5::sack::QueryCmp::NEQ);

std::vector<Package> expected = {get_pkg("pkg-0:1.2-3.x86_64")};
Expand Down Expand Up @@ -827,6 +827,6 @@ void RpmPackageQueryTest::test_filter_provides_performance() {

for (int i = 0; i < 100000; ++i) {
PackageQuery query(base);
query.filter_provides({"prv-all"});
query.filter_provides("prv-all");
}
}

0 comments on commit e3048b5

Please sign in to comment.