dnf, dnf5: fix installing via wildcard (#83481)

Fixes #83373
pull/83417/head
Martin Krizek 5 months ago committed by GitHub
parent 8f1fddb161
commit 0ee6e39615
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,2 @@
bugfixes:
- dnf, dnf5 - fix for installing a set of packages by specifying them using a wildcard character (https://github.com/ansible/ansible/issues/83373)

@ -738,9 +738,14 @@ class DnfModule(YumDnf):
self.module.exit_json(msg="", results=results) self.module.exit_json(msg="", results=results)
def _is_installed(self, pkg): def _is_installed(self, pkg):
return bool( installed_query = dnf.subject.Subject(pkg).get_best_query(sack=self.base.sack).installed()
dnf.subject.Subject(pkg).get_best_query(sack=self.base.sack).installed().run() if dnf.util.is_glob_pattern(pkg):
) available_query = dnf.subject.Subject(pkg).get_best_query(sack=self.base.sack).available()
return not (
{p.name for p in available_query} - {p.name for p in installed_query}
)
else:
return bool(installed_query)
def _is_newer_version_installed(self, pkg_name): def _is_newer_version_installed(self, pkg_name):
try: try:

@ -358,10 +358,23 @@ libdnf5 = None
def is_installed(base, spec): def is_installed(base, spec):
settings = libdnf5.base.ResolveSpecSettings() settings = libdnf5.base.ResolveSpecSettings()
query = libdnf5.rpm.PackageQuery(base) installed_query = libdnf5.rpm.PackageQuery(base)
query.filter_installed() installed_query.filter_installed()
match, nevra = query.resolve_pkg_spec(spec, settings, True) match, nevra = installed_query.resolve_pkg_spec(spec, settings, True)
return match
# FIXME use `is_glob_pattern` function when available:
# https://github.com/rpm-software-management/dnf5/issues/1563
glob_patterns = set("*[?")
if any(set(char) & glob_patterns for char in spec):
available_query = libdnf5.rpm.PackageQuery(base)
available_query.filter_available()
available_query.resolve_pkg_spec(spec, settings, True)
return not (
{p.get_name() for p in available_query} - {p.get_name() for p in installed_query}
)
else:
return match
def is_newer_version_installed(base, spec): def is_newer_version_installed(base, spec):

@ -520,3 +520,25 @@
dnf: dnf:
name: epochone name: epochone
state: absent state: absent
# https://github.com/ansible/ansible/issues/83373
- name: test installing a set of packages by specifying them using a wildcard character
block:
- dnf:
name: provides_foo_a
state: present
- dnf:
name: provides_foo*
state: present
register: dnf_results
- assert:
that:
- dnf_results is changed
- "'Installed: provides_foo_b' in dnf_results['results'][0]"
always:
- name: Clean up
dnf:
name: provides_foo*
state: absent

Loading…
Cancel
Save