rpm-software-management / libdnf

Package management library.
GNU Lesser General Public License v2.1
183 stars 140 forks source link

`Subject.get_best_query`'s `with_filenames` argument is not honored #1673

Open gotmax23 opened 2 weeks ago

gotmax23 commented 2 weeks ago

Since the latest libdnf update, hawkey.Subject.get_best_query does not honor the with_filenames argument. Filenames are still matched even if with_filenames is explicitly set to False.

import dnf
import dnf.subject
import fedrq.config
import hawkey

def get_base() -> dnf.Base:
    """
    Use fedrq to generate a Base object with filelists loaded
.
    This can also be done manually.
    """
    base = (
        fedrq.config.get_config(backend="dnf", load_filelists="always")
        .get_rq(branch="rawhide")
        .base
    )
    assert "filelists" in base.conf.optional_metadata_types
    assert isinstance(base, dnf.Base)
    return base

def main() -> None:
    base = get_base()
    print("Hawkey version:", hawkey.VERSION)
    print("dnf version:", dnf.VERSION)
    path = "/usr/share/ansible"
    # Filenames are not enabled for the query
    subject = dnf.subject.Subject(path).get_best_query(base.sack, with_filenames=False)
    # Query length should be 0
    print("Query length:", len(subject))
    # for package in subject:
    #     print(package)

if __name__ == "__main__":
    main()
$ python with_filelists.py
Hawkey version: 0.73.0
dnf version: 4.19.0
Query length: 0
$ python with_filelists.py 
Hawkey version: 0.73.3
dnf version: 4.21.1
Query length: 3

This is breaking fedrq's unit tests that check that our wrapper of the Subject API returns the correct results when with_filenames is disabled.

m-blaha commented 2 weeks ago

After a bit of experimenting - this regression is a side effect of the patch https://github.com/rpm-software-management/libdnf/pull/1670. The string in question /usr/share/ansible is found during search in provides https://github.com/rpm-software-management/libdnf/blob/fbd34472e5edea0a3ed88ae14a47666e23538e4a/libdnf/sack/query.cpp#L2751-L2757

This causes the query is returned even before the string was searched in file lists.

It looks like POOL_FLAG_ADDFILEPROVIDESFILTERED causes that when filelists metadata are loaded, they are always added to provides. @kontura can you please take a look?