summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2015-02-16 18:04:35 -0800
committerLamont Granquist <lamont@scriptkiddie.org>2015-02-17 13:58:07 -0800
commitaf9b718928a063baac2fc559a3d9b98c25327e01 (patch)
treee5a2ecca47904df1a4db6483bb89c48030cf72df
parent4f6fa576a5a46ae9739e1e13fc9f79f1d3c489f8 (diff)
downloadchef-af9b718928a063baac2fc559a3d9b98c25327e01.tar.gz
convert is_virtual_package to hash
make this a hash based on name so that when we pass an array of names to install_package we can look up the right one and do not have to synchronize arrays. we should probably convert the arrays in the superclass to hashes based on name as well.
-rw-r--r--lib/chef/provider/package/apt.rb17
-rw-r--r--spec/unit/provider/package/apt_spec.rb2
2 files changed, 14 insertions, 5 deletions
diff --git a/lib/chef/provider/package/apt.rb b/lib/chef/provider/package/apt.rb
index c960806e8f..c6fb47b5d5 100644
--- a/lib/chef/provider/package/apt.rb
+++ b/lib/chef/provider/package/apt.rb
@@ -27,8 +27,14 @@ class Chef
provides :apt_package, os: "linux"
+ # return [Hash] mapping of package name to Boolean value
attr_accessor :is_virtual_package
+ def initialize(new_resource, run_context)
+ super
+ @is_virtual_package = {}
+ end
+
def load_current_resource
@current_resource = Chef::Resource::Package.new(@new_resource.name)
@current_resource.package_name(@new_resource.package_name)
@@ -108,8 +114,11 @@ class Chef
end
@candidate_version = final_candidate_version
@current_resource.version(final_installed_version)
- @is_virtual_package = final_virtual
-
+
+ [package].flatten.each do |pkg|
+ @is_virtual_package[pkg] = final_virtual
+ end
+
return final_installed.is_a?(Array) ? final_installed.any? : final_installed
end
@@ -118,7 +127,7 @@ class Chef
index = 0
package_name = name.zip(version).map do |x, y|
namestr = nil
- if @is_virtual_package[index]
+ if is_virtual_package[name]
namestr = x
else
namestr = "#{x}=#{y}"
@@ -128,7 +137,7 @@ class Chef
end.join(' ')
else
package_name = "#{name}=#{version}"
- package_name = name if @is_virtual_package
+ package_name = name if is_virtual_package[name]
end
run_noninteractive("apt-get -q -y#{expand_options(default_release_options)}#{expand_options(@new_resource.options)} install #{package_name}")
end
diff --git a/spec/unit/provider/package/apt_spec.rb b/spec/unit/provider/package/apt_spec.rb
index acf0707bbf..8b1d40aab9 100644
--- a/spec/unit/provider/package/apt_spec.rb
+++ b/spec/unit/provider/package/apt_spec.rb
@@ -356,7 +356,7 @@ mpg123 1.12.1-0ubuntu1
describe "when installing a virtual package" do
it "should install the package without specifying a version" do
- @provider.is_virtual_package = true
+ @provider.is_virtual_package['libmysqlclient-dev'] = true
expect(@provider).to receive(:shell_out!).with(
"apt-get -q -y install libmysqlclient-dev",
:env => {"DEBIAN_FRONTEND" => "noninteractive", "LC_ALL" => nil },