Skip to content

Commit e8a386c

Browse files
committed
Restructure the package provider to use the candidate_version accessor vs the variable directly.
This allows us to delay loading the candidate_version until it's actually needed. For example, it's not needed if we didn't specify a version, we're doing an install, and we already have a version installed. If we do this, then we can possibly speed up the other providers because they don't have to look up a candidate version, only an actual installed version. Some can do this via disk instead of via the package maintainers, and this makes it go faster.
1 parent d4a4742 commit e8a386c

1 file changed

Lines changed: 10 additions & 11 deletions

File tree

chef/lib/chef/provider/package.rb

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,25 +36,24 @@ def initialize(node, new_resource)
3636
end
3737

3838
def action_install
39-
# First, select what version we should be using
40-
install_version = @new_resource.version
41-
install_version ||= @candidate_version
42-
43-
unless install_version
44-
raise(Chef::Exceptions::Package, "No version specified, and no candidate version available!")
45-
end
46-
4739
do_package = false
4840
# If it's not installed at all, install it
4941
if @current_resource.version == nil
5042
do_package = true
43+
install_version = candidate_version
5144
# If we specified a version, and it's not the current version, move to the current version
5245
elsif @new_resource.version != nil
46+
install_version = @new_resource.version
5347
if @new_resource.version != @current_resource.version
5448
do_package = true
5549
end
5650
end
51+
5752
if do_package
53+
unless install_version
54+
raise(Chef::Exceptions::Package, "No version specified, and no candidate version available!")
55+
end
56+
5857
Chef::Log.info("Installing #{@new_resource} version #{install_version}")
5958

6059
# We need to make sure we handle the preseed file
@@ -70,10 +69,10 @@ def action_install
7069
end
7170

7271
def action_upgrade
73-
if @current_resource.version != @candidate_version
72+
if @current_resource.version != candidate_version
7473
orig_version = @current_resource.version || "uninstalled"
75-
Chef::Log.info("Upgrading #{@new_resource} version from #{orig_version} to #{@candidate_version}")
76-
status = upgrade_package(@new_resource.package_name, @candidate_version)
74+
Chef::Log.info("Upgrading #{@new_resource} version from #{orig_version} to #{candidate_version}")
75+
status = upgrade_package(@new_resource.package_name, candidate_version)
7776
if status
7877
@new_resource.updated = true
7978
end

0 commit comments

Comments
 (0)