diff options
author | Will Thames <will@thames.id.au> | 2016-09-20 11:13:23 +1000 |
---|---|---|
committer | Brian Coca <bcoca@users.noreply.github.com> | 2016-09-19 21:13:23 -0400 |
commit | a076309a0f5bb9912392db6ae77f4a8043e2d9cd (patch) | |
tree | 48d088642023f11ac4b824d30d3be41e674f4934 | |
parent | 600228ca7f82c1a1eefae18a6928b7d28bf0ce70 (diff) | |
download | ansible-modules-core-a076309a0f5bb9912392db6ae77f4a8043e2d9cd.tar.gz |
Check whether yum file or URL install is an upgrade (#4547)
Rather than just checking whether a package with the right
name is installed, use `local_nvra` to check whether the
version/release/arch differs too.
Remove `local_name` as it is a shortcut too far.
Fixes #3807
Fixes #4529
-rw-r--r-- | packaging/os/yum.py | 23 |
1 files changed, 5 insertions, 18 deletions
diff --git a/packaging/os/yum.py b/packaging/os/yum.py index cc0ad419..45bfd2d5 100644 --- a/packaging/os/yum.py +++ b/packaging/os/yum.py @@ -507,24 +507,11 @@ def local_nvra(module, path): finally: os.close(fd) - return '%s-%s-%s.%s' % (header[rpm.RPMTAG_NAME], + return '%s-%s-%s.%s' % (header[rpm.RPMTAG_NAME], header[rpm.RPMTAG_VERSION], header[rpm.RPMTAG_RELEASE], header[rpm.RPMTAG_ARCH]) - -def local_name(module, path): - """return package name of a local rpm passed in""" - ts = rpm.TransactionSet() - ts.setVSFlags(rpm._RPMVSF_NOSIGNATURES) - fd = os.open(path, os.O_RDONLY) - try: - header = ts.hdrFromFdno(fd) - finally: - os.close(fd) - - return header[rpm.RPMTAG_NAME] - def pkg_to_dict(pkgstr): if pkgstr.strip(): @@ -599,10 +586,10 @@ def install(module, items, repoq, yum_basecmd, conf_file, en_repos, dis_repos): res['msg'] += "No Package file matching '%s' found on system" % spec module.fail_json(**res) - pkg_name = local_name(module, spec) + nvra = local_nvra(module, spec) # look for them in the rpmdb - if is_installed(module, repoq, pkg_name, conf_file, en_repos=en_repos, dis_repos=dis_repos): + if is_installed(module, repoq, nvra, conf_file, en_repos=en_repos, dis_repos=dis_repos): # if they are there, skip it continue pkg = spec @@ -611,8 +598,8 @@ def install(module, items, repoq, yum_basecmd, conf_file, en_repos, dis_repos): elif '://' in spec: # download package so that we can check if it's already installed package = fetch_rpm_from_url(spec, module=module) - pkg_name = local_name(module, package) - if is_installed(module, repoq, pkg_name, conf_file, en_repos=en_repos, dis_repos=dis_repos): + nvra = local_nvra(module, package) + if is_installed(module, repoq, nvra, conf_file, en_repos=en_repos, dis_repos=dis_repos): # if it's there, skip it continue pkg = package |