Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

package_query: Fix filter_version with non EQ comparator #1127

Merged
merged 2 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions libdnf5/rpm/package_query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -982,7 +982,7 @@ inline static void filter_version_internal(
std::string vr(pool.split_evr(pool.get_evr(candidate_id)).v);
vr.append("-0");
int cmp = pool.evrcmp_str(vr.c_str(), formatted_c_pattern, EVRCMP_COMPARE);
if (cmp_eq(cmp)) {
if (cmp_fnc(cmp)) {
filter_result.add_unsafe(candidate_id);
}
}
Expand Down Expand Up @@ -1050,7 +1050,7 @@ inline static void filter_release_internal(
std::string vr("0-");
vr.append(pool.split_evr(pool.get_evr(candidate_id)).r);
int cmp = pool.evrcmp_str(vr.c_str(), formatted_c_pattern, EVRCMP_COMPARE);
if (cmp_eq(cmp)) {
if (cmp_fnc(cmp)) {
filter_result.add_unsafe(candidate_id);
}
}
Expand Down
42 changes: 42 additions & 0 deletions test/libdnf5/rpm/test_package_query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,29 @@ void RpmPackageQueryTest::test_filter_version() {

expected = {get_pkg("pkg-libs-1:1.3-4.x86_64")};
CPPUNIT_ASSERT_EQUAL(expected, to_vector(query2));

// packages with version < "1.3"
PackageQuery query3(base);
query3.filter_version({"1.3"}, libdnf5::sack::QueryCmp::LT);

expected = {
get_pkg("pkg-0:1.2-3.src"),
get_pkg("pkg-0:1.2-3.x86_64"),
get_pkg("pkg-libs-0:1.2-3.x86_64"),
get_pkg("pkg-libs-1:1.2-4.x86_64")};
CPPUNIT_ASSERT_EQUAL(expected, to_vector(query3));

// packages with version <= "1.3"
PackageQuery query4(base);
query4.filter_version({"1.3"}, libdnf5::sack::QueryCmp::LTE);

expected = {
get_pkg("pkg-0:1.2-3.src"),
get_pkg("pkg-0:1.2-3.x86_64"),
get_pkg("pkg-libs-0:1.2-3.x86_64"),
get_pkg("pkg-libs-1:1.2-4.x86_64"),
get_pkg("pkg-libs-1:1.3-4.x86_64")};
CPPUNIT_ASSERT_EQUAL(expected, to_vector(query4));
}


Expand All @@ -523,6 +546,25 @@ void RpmPackageQueryTest::test_filter_release() {

expected = {get_pkg("pkg-libs-1:1.2-4.x86_64"), get_pkg("pkg-libs-1:1.3-4.x86_64")};
CPPUNIT_ASSERT_EQUAL(expected, to_vector(query2));

// packages with release > "3"
PackageQuery query3(base);
query3.filter_release({"3"}, libdnf5::sack::QueryCmp::GT);

expected = {get_pkg("pkg-libs-1:1.2-4.x86_64"), get_pkg("pkg-libs-1:1.3-4.x86_64")};
CPPUNIT_ASSERT_EQUAL(expected, to_vector(query3));

// packages with release >= "3"
PackageQuery query4(base);
query4.filter_release({"3"}, libdnf5::sack::QueryCmp::GTE);

expected = {
get_pkg("pkg-0:1.2-3.src"),
get_pkg("pkg-0:1.2-3.x86_64"),
get_pkg("pkg-libs-0:1.2-3.x86_64"),
get_pkg("pkg-libs-1:1.2-4.x86_64"),
get_pkg("pkg-libs-1:1.3-4.x86_64")};
CPPUNIT_ASSERT_EQUAL(expected, to_vector(query4));
}

void RpmPackageQueryTest::test_filter_priority() {
Expand Down
Loading