dnf5 - consolidate package resolving settings (#84335)

Fixes #84334
pull/74103/head
Martin Krizek 4 days ago committed by GitHub
parent a27a7a27d1
commit c99493eb3f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,2 @@
bugfixes:
- dnf5 - matching on a binary can be achieved only by specifying a full path (https://github.com/ansible/ansible/issues/84334)

@ -358,14 +358,20 @@ libdnf5 = None
def is_installed(base, spec): def is_installed(base, spec):
settings = libdnf5.base.ResolveSpecSettings() settings = libdnf5.base.ResolveSpecSettings()
# Disable checking whether SPEC is a binary -> `/usr/(s)bin/<SPEC>`, try:
# this prevents scenarios like the following: settings.set_group_with_name(True)
# * the `sssd-common` package is installed and provides `/usr/sbin/sssd` binary # Disable checking whether SPEC is a binary -> `/usr/(s)bin/<SPEC>`,
# * the `sssd` package is NOT installed # this prevents scenarios like the following:
# * due to `set_with_binaries(True)` being default `is_installed(base, "sssd")` would "unexpectedly" return True # * the `sssd-common` package is installed and provides `/usr/sbin/sssd` binary
# If users wish to target the `sssd` binary they can by specifying the full path `name=/usr/sbin/sssd` explicitly # * the `sssd` package is NOT installed
# due to settings.set_with_filenames(True) being default. # * due to `set_with_binaries(True)` being default `is_installed(base, "sssd")` would "unexpectedly" return True
settings.set_with_binaries(False) # If users wish to target the `sssd` binary they can by specifying the full path `name=/usr/sbin/sssd` explicitly
# due to settings.set_with_filenames(True) being default.
settings.set_with_binaries(False)
except AttributeError:
# dnf5 < 5.2.0.0
settings.group_with_name = True
settings.with_binaries = False
installed_query = libdnf5.rpm.PackageQuery(base) installed_query = libdnf5.rpm.PackageQuery(base)
installed_query.filter_installed() installed_query.filter_installed()
@ -655,9 +661,12 @@ class Dnf5Module(YumDnf):
settings = libdnf5.base.GoalJobSettings() settings = libdnf5.base.GoalJobSettings()
try: try:
settings.set_group_with_name(True) settings.set_group_with_name(True)
settings.set_with_binaries(False)
except AttributeError: except AttributeError:
# dnf5 < 5.2.0.0 # dnf5 < 5.2.0.0
settings.group_with_name = True settings.group_with_name = True
settings.with_binaries = False
if self.bugfix or self.security: if self.bugfix or self.security:
advisory_query = libdnf5.advisory.AdvisoryQuery(base) advisory_query = libdnf5.advisory.AdvisoryQuery(base)
types = [] types = []

@ -564,3 +564,26 @@
dnf: dnf:
name: provides-binary name: provides-binary
state: absent state: absent
# https://github.com/ansible/ansible/issues/84334
- name: test that a binary is not matched by its base name
block:
- dnf:
name: provides-binary
state: present
- dnf:
name: package-name
state: absent
register: dnf_result
- assert:
that:
- dnf_result is not changed
always:
- name: Clean up
dnf:
name:
- provides-binary
- package-name
state: absent

Loading…
Cancel
Save