diff options
author | Harikesh Kolekar <harikesh.kolekar@msystechnologies.com> | 2017-03-08 01:58:28 +0530 |
---|---|---|
committer | Bryan McLellan <btm@loftninjas.org> | 2017-03-07 15:28:28 -0500 |
commit | eca4feab0f062446271cc3d70870074ef3c5876d (patch) | |
tree | 8823b27caf0cd4e745ec58d27c075024f86c37fa | |
parent | bda35a4d05b7b5ff63f9fca2e78a0752fd497eb9 (diff) | |
download | chef-eca4feab0f062446271cc3d70870074ef3c5876d.tar.gz |
add support QuietUninstallString for windows packages (#5849)
* add support QuietUninstallString for windows packages
Signed-off-by: MSys <harikesh.kolekar@msystechnologies.com>
-rw-r--r-- | lib/chef/provider/package/windows/registry_uninstall_entry.rb | 12 | ||||
-rw-r--r-- | spec/unit/provider/package/windows/registry_uninstall_entry_spec.rb | 25 |
2 files changed, 34 insertions, 3 deletions
diff --git a/lib/chef/provider/package/windows/registry_uninstall_entry.rb b/lib/chef/provider/package/windows/registry_uninstall_entry.rb index a693558883..03f6ff318e 100644 --- a/lib/chef/provider/package/windows/registry_uninstall_entry.rb +++ b/lib/chef/provider/package/windows/registry_uninstall_entry.rb @@ -41,7 +41,8 @@ class Chef entry = reg.open(key, desired) display_name = read_registry_property(entry, "DisplayName") if display_name == package_name - entries.push(RegistryUninstallEntry.new(hkey, key, entry)) + quiet_uninstall_string = RegistryUninstallEntry.read_registry_property(entry, "QuietUninstallString") + entries.push(quiet_uninstall_string_key?(quiet_uninstall_string, hkey, key, entry)) end rescue ::Win32::Registry::Error => ex Chef::Log.debug("Registry error opening key '#{key}' on node #{desired}: #{ex}") @@ -55,6 +56,11 @@ class Chef entries end + def self.quiet_uninstall_string_key?(quiet_uninstall_string, hkey, key, entry) + return RegistryUninstallEntry.new(hkey, key, entry) if quiet_uninstall_string.nil? + RegistryUninstallEntry.new(hkey, key, entry, "QuietUninstallString") + end + def self.read_registry_property(data, property) data[property] rescue ::Win32::Registry::Error => ex @@ -62,14 +68,14 @@ class Chef nil end - def initialize(hive, key, registry_data) + def initialize(hive, key, registry_data, uninstall_key = "UninstallString") Chef::Log.debug("Creating uninstall entry for #{hive}::#{key}") @hive = hive @key = key @data = registry_data @display_name = RegistryUninstallEntry.read_registry_property(registry_data, "DisplayName") @display_version = RegistryUninstallEntry.read_registry_property(registry_data, "DisplayVersion") - @uninstall_string = RegistryUninstallEntry.read_registry_property(registry_data, "UninstallString") + @uninstall_string = RegistryUninstallEntry.read_registry_property(registry_data, uninstall_key) end attr_reader :hive diff --git a/spec/unit/provider/package/windows/registry_uninstall_entry_spec.rb b/spec/unit/provider/package/windows/registry_uninstall_entry_spec.rb new file mode 100644 index 0000000000..d9339861a4 --- /dev/null +++ b/spec/unit/provider/package/windows/registry_uninstall_entry_spec.rb @@ -0,0 +1,25 @@ +require "spec_helper" +require "chef/provider/package/windows/registry_uninstall_entry" + +describe Chef::Provider::Package::Windows::RegistryUninstallEntry do + let(:hkey) { :hkey } # mock all the methods + let(:key) { :key } + let(:entry) { { "UninstallString" => "UninstallStringPath", "QuietUninstallString" => "QuietUninstallStringPath" } } + + describe "when QuietUninstallString key not present" do + let(:quiet_uninstall_string) { nil } + let (:quiet_uninstall_string_key) { Chef::Provider::Package::Windows::RegistryUninstallEntry.quiet_uninstall_string_key?(quiet_uninstall_string, hkey, key, entry).uninstall_string } + it "should return UninstallString key value" do + expect(quiet_uninstall_string_key).to eql "UninstallStringPath" + end + end + + describe "when QuietUninstallString key present" do + let(:quiet_uninstall_string) { "QuietUninstallString" } + let (:quiet_uninstall_string_key) { Chef::Provider::Package::Windows::RegistryUninstallEntry.quiet_uninstall_string_key?(quiet_uninstall_string, hkey, key, entry).uninstall_string } + + it "should return QuietUninstallString key value" do + expect(quiet_uninstall_string_key).to eql "QuietUninstallStringPath" + end + end +end |