From a5597127294b65df79dc1b98cefe845e4e36de2b Mon Sep 17 00:00:00 2001 From: Jon Cowie Date: Wed, 13 Sep 2017 14:57:15 +0100 Subject: Fixes to package upgrade behaviour This commit introduces fixes to the behaviour of the various providers of the "package" resource (and subtypes like dnf_package etc) when a more recent version of the package has been installed than that present in an available repository or file source and "action :upgrade" is called against the package. Currently, a number of package providers will attempt to downgrade a package under this scenario, where the desired action should be to recognise that a more up to date version is already installed and do nothing. I've introduced a ```version_compare``` method to the package superclass which by default uses ```Gem::Version``` comparison with spaceship-operator semantics to ensure that an upgrade is attempted only when the candidate version is not older than the current version. Additionally, this commit introduces a method called ```version_equals?``` which is functionally identical to ```target_version_already_installed?``` (and that method now in fact calls ```version_equals?```. This has been done to clarify the purpose and functionality of that method, but since it's a public API, deprecation of the old method name will have to be done more gradually. Signed-off-by: Jon Cowie --- lib/chef/provider/package/rpm.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'lib/chef/provider/package/rpm.rb') diff --git a/lib/chef/provider/package/rpm.rb b/lib/chef/provider/package/rpm.rb index 7ec24f8c24..07617c814e 100644 --- a/lib/chef/provider/package/rpm.rb +++ b/lib/chef/provider/package/rpm.rb @@ -18,6 +18,7 @@ require "chef/provider/package" require "chef/resource/package" require "chef/mixin/get_source_from_package" +require "chef/provider/package/yum/rpm_utils" class Chef class Provider @@ -109,6 +110,10 @@ class Chef private + def version_compare(v1, v2) + Chef::Provider::Package::Yum::RPMVersion.parse(v1) <=> Chef::Provider::Package::Yum::RPMVersion.parse(v2) + end + def uri_scheme?(str) scheme = URI.split(str).first return false unless scheme -- cgit v1.2.1