summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWill Thames <will@thames.id.au>2016-09-28 00:52:25 +1000
committerBrian Coca <bcoca@users.noreply.github.com>2016-09-27 10:52:25 -0400
commit3c3ffa80bc5a29a2234b993d3f560f6e4ed6d5ef (patch)
treeff22119a4730bbdbd9edf5baf528fc30e0c078cc
parent335d3315581d4b59137809b09b4edd7a850a706f (diff)
downloadansible-modules-core-3c3ffa80bc5a29a2234b993d3f560f6e4ed6d5ef.tar.gz
Check whether yum file or URL install is an upgrade (#5048)
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.py24
1 files changed, 6 insertions, 18 deletions
diff --git a/packaging/os/yum.py b/packaging/os/yum.py
index ad0f93e8..3d6fed0b 100644
--- a/packaging/os/yum.py
+++ b/packaging/os/yum.py
@@ -477,24 +477,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():
@@ -569,9 +556,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
@@ -592,8 +580,8 @@ def install(module, items, repoq, yum_basecmd, conf_file, en_repos, dis_repos):
shutil.rmtree(tempdir)
module.fail_json(msg="Failure downloading %s, %s" % (spec, e))
- 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