Skip to content

Commit

Permalink
Normalize the package name only once on install/remove
Browse files Browse the repository at this point in the history
  • Loading branch information
vzhestkov committed Feb 18, 2022
1 parent 89fece2 commit 05ff303
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 19 deletions.
46 changes: 29 additions & 17 deletions salt/modules/yumpkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -1533,14 +1533,15 @@ def install(name=None,
if ignore_epoch is True:
version_num = version_num.split(':', 1)[-1]
arch = ''
try:
namepart, archpart = pkgname.rsplit('.', 1)
except ValueError:
pass
else:
if archpart in salt.utils.pkg.rpm.ARCHES:
arch = '.' + archpart
pkgname = namepart
if normalize:
try:
namepart, archpart = pkgname.rsplit('.', 1)
except ValueError:
pass
else:
if archpart in salt.utils.pkg.rpm.ARCHES:
arch = '.' + archpart
pkgname = namepart

if '*' in version_num:
# Resolve wildcard matches
Expand Down Expand Up @@ -1970,7 +1971,7 @@ def update(name=None,
return upgrade(name, pkgs, refresh, skip_verify, normalize, minimal, obsoletes, **kwargs)


def remove(name=None, pkgs=None, **kwargs): # pylint: disable=W0613
def remove(name=None, pkgs=None, normalize=True, **kwargs): # pylint: disable=W0613
'''
.. versionchanged:: 2015.8.12,2016.3.3,2016.11.0
On minions running systemd>=205, `systemd-run(1)`_ is now used to
Expand Down Expand Up @@ -2000,6 +2001,16 @@ def remove(name=None, pkgs=None, **kwargs): # pylint: disable=W0613
.. versionadded:: 0.16.0
normalize : True
Normalize the package name by removing the architecture. This is useful
for poorly created packages which might include the architecture as an
actual part of the name such as kernel modules which match a specific
kernel version.
.. code-block:: bash
salt -G role:nsd pkg.install gpfs.gplbin-2.6.32-279.31.1.el6.x86_64 normalize=False
Returns a dict containing the changes.
Expand Down Expand Up @@ -2030,14 +2041,15 @@ def remove(name=None, pkgs=None, **kwargs): # pylint: disable=W0613
elif target in old and version_to_remove in installed_versions:
arch = ''
pkgname = target
try:
namepart, archpart = target.rsplit('.', 1)
except ValueError:
pass
else:
if archpart in salt.utils.pkg.rpm.ARCHES:
arch = '.' + archpart
pkgname = namepart
if normalize:
try:
namepart, archpart = pkgname.rsplit('.', 1)
except ValueError:
pass
else:
if archpart in salt.utils.pkg.rpm.ARCHES:
arch = '.' + archpart
pkgname = namepart
# Since we don't always have the arch info, epoch information has to parsed out. But
# a version check was already performed, so we are removing the right version.
targets.append(
Expand Down
6 changes: 4 additions & 2 deletions salt/states/pkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -1782,7 +1782,7 @@ def installed(
pkgs=pkgs,
sources=sources,
reinstall=bool(to_reinstall),
normalize=normalize,
normalize=False,
update_holds=update_holds,
ignore_epoch=ignore_epoch,
**kwargs)
Expand Down Expand Up @@ -2743,7 +2743,9 @@ def _uninstall(
'comment': 'The following packages will be {0}d: '
'{1}.'.format(action, ', '.join(targets))}

changes = __salt__['pkg.{0}'.format(action)](name, pkgs=pkgs, version=version, **kwargs)
changes = __salt__['pkg.{0}'.format(action)](
name, pkgs=pkgs, version=version, normalize=False, **kwargs
)
new = __salt__['pkg.list_pkgs'](versions_as_list=True, **kwargs)
failed = []
for param in pkg_params:
Expand Down

0 comments on commit 05ff303

Please sign in to comment.