summaryrefslogtreecommitdiff
path: root/lib/chef/provider/package
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2015-11-17 18:04:28 -0800
committerLamont Granquist <lamont@scriptkiddie.org>2015-11-17 18:05:06 -0800
commit4e292e9c40b396c370ede42d49c75a7d20981e73 (patch)
tree436a05cc769a0f56d0ae438a79aefea4b2be2209 /lib/chef/provider/package
parent0e9c4382e9d58fbcf53ed67043b8de0bda01da21 (diff)
downloadchef-4e292e9c40b396c370ede42d49c75a7d20981e73.tar.gz
base package provider fixes
* removes the mutation of the new_resource.version * adds package_class_supports_arrays for multipackage providers * cleans up the package resource initializer and sets the package_name correctly through the accessor method. By mutating new_resource.version we were destroying the original intent of what the user was requesting. This is a bug that must be fixed. Generally, subclasses will be able to get the correct information they need through either the version argument they were passed in install_package(name, version) instead, or through their `#target_version_array` method. If this breaks anything then those providers need bugfixes as well (since this is a change to an internal API accessible only to subclassing, and there are backwards compatible and correct ways to get the information, this is *not* a SemVer violating change). See the fix I made to the OpenBSD provider to preserve the same semantics, avoid using new_resource.version where it was inappropriate, and make the code more symmetrical where before substantially different looking code in install_package and remove_package had exactly the same ultimate effect. The package_class_supports_arrays 'DSL' for writing multipackage providers coerces the arguments to the virtual methods (e.g. install_package) into arrays, even if the user is only requesting a single package install. This removes most of the `is_a?(Array)` checks from the implementation subclasses. The cleanup of the initializer is similarly necessary so that we can use Chef 12.5 coercions to make the package_name and version arguments accept string, but always be Arrays. This should eliminate the rest of the need to write `is_a?(Array)` code all over the package provider implementations.
Diffstat (limited to 'lib/chef/provider/package')
-rw-r--r--lib/chef/provider/package/openbsd.rb12
1 files changed, 5 insertions, 7 deletions
diff --git a/lib/chef/provider/package/openbsd.rb b/lib/chef/provider/package/openbsd.rb
index 7a6582363e..00d9e5941d 100644
--- a/lib/chef/provider/package/openbsd.rb
+++ b/lib/chef/provider/package/openbsd.rb
@@ -72,18 +72,16 @@ class Chef
if parts = name.match(/^(.+?)--(.+)/) # use double-dash for stems with flavors, see man page for pkg_add
name = parts[1]
end
- shell_out_with_timeout!("pkg_add -r #{name}#{version_string}", :env => {"PKG_PATH" => pkg_path}).status
+ shell_out_with_timeout!("pkg_add -r #{name}#{version_string(version)}", :env => {"PKG_PATH" => pkg_path}).status
Chef::Log.debug("#{new_resource.package_name} installed")
end
end
def remove_package(name, version)
- version_string = ''
- version_string += "-#{version}" if version
if parts = name.match(/^(.+?)--(.+)/)
name = parts[1]
end
- shell_out_with_timeout!("pkg_delete #{name}#{version_string}", :env => nil).status
+ shell_out_with_timeout!("pkg_delete #{name}#{version_string(version)}", :env => nil).status
end
private
@@ -103,7 +101,7 @@ class Chef
def candidate_version
@candidate_version ||= begin
results = []
- shell_out_with_timeout!("pkg_info -I \"#{new_resource.package_name}#{version_string}\"", :env => nil, :returns => [0,1]).stdout.each_line do |line|
+ shell_out_with_timeout!("pkg_info -I \"#{new_resource.package_name}#{version_string(new_resource.version)}\"", :env => nil, :returns => [0,1]).stdout.each_line do |line|
if parts = new_resource.package_name.match(/^(.+?)--(.+)/)
results << line[/^#{Regexp.escape(parts[1])}-(.+?)\s/, 1]
else
@@ -123,9 +121,9 @@ class Chef
end
end
- def version_string
+ def version_string(version)
ver = ''
- ver += "-#{new_resource.version}" if new_resource.version
+ ver += "-#{version}" if version
end
def pkg_path