diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/chef/provider/package.rb | 3 | ||||
-rw-r--r-- | lib/chef/provider/package/apt.rb | 12 | ||||
-rw-r--r-- | lib/chef/provider/package/dpkg.rb | 16 |
3 files changed, 27 insertions, 4 deletions
diff --git a/lib/chef/provider/package.rb b/lib/chef/provider/package.rb index 95d16dd666..7116bc9045 100644 --- a/lib/chef/provider/package.rb +++ b/lib/chef/provider/package.rb @@ -477,6 +477,9 @@ class Chef elsif candidate_version.nil? Chef::Log.debug("#{new_resource} #{package_name} has no candidate_version to upgrade to") target_version_array.push(nil) + elsif current_version.nil? + Chef::Log.debug("#{new_resource} has no existing installed version. Installing install #{candidate_version}") + target_version_array.push(candidate_version) elsif version_compare(current_version, candidate_version) == 1 && !new_resource.allow_downgrade Chef::Log.debug("#{new_resource} #{package_name} has installed version #{current_version}, which is newer than available version #{candidate_version}. Skipping...)") target_version_array.push(nil) diff --git a/lib/chef/provider/package/apt.rb b/lib/chef/provider/package/apt.rb index 605bbc70eb..3f32f9d380 100644 --- a/lib/chef/provider/package/apt.rb +++ b/lib/chef/provider/package/apt.rb @@ -127,12 +127,16 @@ class Chef private + # compare 2 versions to each other to see which is newer. + # this differs from the standard package method because we + # need to be able to parse debian version strings which contain + # tildes which Gem cannot properly parse + # + # @return [Integer] 1 if v1 > v2. 0 if they're equal. -1 if v1 < v2 def version_compare(v1, v2) - dpkg_v1 = v1 || '0' - dpkg_v2 = v2 || '0' - if shell_out_compact_timeout("dpkg", "--compare-versions", dpkg_v1, "gt", dpkg_v2).status.success? + if !shell_out_compact_timeout("dpkg", "--compare-versions", v1.to_s, "gt", v2.to_s).error? 1 - elsif shell_out_compact_timeout("dpkg", "--compare-versions", dpkg_v1, "eq", dpkg_v2).status.success? + elsif !shell_out_compact_timeout("dpkg", "--compare-versions", v1.to_s, "eq", v2.to_s).error? 0 else -1 diff --git a/lib/chef/provider/package/dpkg.rb b/lib/chef/provider/package/dpkg.rb index 89a57affac..cf92e6d3e7 100644 --- a/lib/chef/provider/package/dpkg.rb +++ b/lib/chef/provider/package/dpkg.rb @@ -106,6 +106,22 @@ class Chef private + # compare 2 versions to each other to see which is newer. + # this differs from the standard package method because we + # need to be able to parse debian version strings which contain + # tildes which Gem cannot properly parse + # + # @return [Integer] 1 if v1 > v2. 0 if they're equal. -1 if v1 < v2 + def version_compare(v1, v2) + if !shell_out_compact_timeout("dpkg", "--compare-versions", v1.to_s, "gt", v2.to_s).error? + 1 + elsif !shell_out_compact_timeout("dpkg", "--compare-versions", v1.to_s, "eq", v2.to_s).error? + 0 + else + -1 + end + end + def read_current_version_of_package(package_name) Chef::Log.debug("#{new_resource} checking install state of #{package_name}") status = shell_out_compact_timeout!("dpkg", "-s", package_name, returns: [0, 1]) |