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

Fix repository specific excludes #234

Merged
merged 2 commits into from
Jan 24, 2023
Merged

Fix repository specific excludes #234

merged 2 commits into from
Jan 24, 2023

Conversation

m-blaha
Copy link
Member

@m-blaha m-blaha commented Jan 16, 2023

rq.filter_id(disable_excludes, libdnf::sack::QueryCmp::NOT_GLOB) in case of empty disable_excludes filters out all repositories.

Resolves #233

@m-blaha
Copy link
Member Author

m-blaha commented Jan 16, 2023

There is also another way how to fix it.

What is the desired behavior of bool match_string(const std::string & value, QueryCmp cmp, const std::vector<std::string> & patterns) function in case the patterns vector is empty and the cmp comparator is negative? - e.g. rq.filter_id([], libdnf::sack::QueryCmp::NOT_GLOB) in this issue, which leads to match_string(repo_id, libdnf::sack::QueryCmp::NOT_GLOB, [])

I believe it should return true. Any comments?

bool match_string(const std::string & value, QueryCmp cmp, const std::vector<std::string> & patterns) {
bool result = false;
for (auto & pattern : patterns) {
if (match_string(value, cmp, pattern)) {
result = true;
break;
}
}
return result;
}

@kontura
Copy link
Contributor

kontura commented Jan 17, 2023

I believe it should return true. Any comments?

It would also make sense to me. It seems like a cleaner solution, especially since we have tests for this.
If we modify match_string() I would also change match_int64() in the same way.

@kontura kontura self-assigned this Jan 17, 2023
@m-blaha m-blaha force-pushed the mblaha/repository_excludes branch from d2d3bd9 to c6d3929 Compare January 17, 2023 09:40
@m-blaha
Copy link
Member Author

m-blaha commented Jan 17, 2023

I tried to fix the behavior of match_string() function in case one (or both) of operands are vectors and the cmp operator is negative. I tried to describe the new behavior both in commit message and in the comments.
The fix for match_int64() is still not present, but I'd appreciate a partial review here - to make sure that the logic change makes sense.

@mcurlej mcurlej added this to the Fedora 38 milestone Jan 18, 2023
@m-blaha m-blaha force-pushed the mblaha/repository_excludes branch from c6d3929 to 5fb701a Compare January 20, 2023 10:29
@kontura
Copy link
Contributor

kontura commented Jan 23, 2023

The PR looks good, but I think that in the commit msg: match_string("fedora", NOT_GLOB, ["fedora", "testing"]) would return true is wrong. "fedora" is in the string list and since we use NOT_ it would return false no?

@m-blaha
Copy link
Member Author

m-blaha commented Jan 24, 2023

I should have written the commit message more clearly. The part you mentioned is an example of clearly wrong behaviour of current (unfixed by this pach) implementation. Let me try to re-formulate the commit message.

Current implementation sometimes behaves wrong in case the `cmp` is
negative (e.g. NOT_GLOB) and either the `values` or `patterns` is a
vector.
For example here are the results of unfixed code:
A) match_string("fedora", NOT_GLOB, ["fedora", "testing"]) -> true
(which is wrong)
B) match_string("fedora", NOT_GLOB, ["updates", "testing"]) -> true
(correct)
C) match_string("fedora", NOT_GLOB, []) -> false (which is wrong)

The new implementation in this patch follows these rules:

1. in case the `cmp` is positive, return true if any of values match at
   least one of patterns (nothing has changed in this case)

2. if the `cmp` is negative, return true if none of the values match
   none of the patterns

With the patch the exapmle calls will result with:

A) match_string("fedora", NOT_GLOB, ["fedora", "testing"]) -> false
B) match_string("fedora", NOT_GLOB, ["updates", "testing"]) -> true
C) match_string("fedora", NOT_GLOB, []) -> true

Resolves #233
No need to filter repositories if the disable_excludes vector is empty.
@m-blaha m-blaha force-pushed the mblaha/repository_excludes branch from 5fb701a to 303d0ba Compare January 24, 2023 07:51
@kontura
Copy link
Contributor

kontura commented Jan 24, 2023

I see, thanks, it is much more understandable for me now.

@kontura kontura merged commit de7be26 into main Jan 24, 2023
@kontura kontura deleted the mblaha/repository_excludes branch January 24, 2023 08:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

dnf5 does not respect exclude key in .repo files
3 participants