summaryrefslogtreecommitdiff
path: root/lib/chef/win32
diff options
context:
space:
mode:
authorClaire McQuin <claire@chef.io>2015-09-03 11:15:27 -0700
committerClaire McQuin <claire@chef.io>2015-09-03 11:18:27 -0700
commit25b77f4e175e8a56865d3c908f29147c6d41c93a (patch)
tree13042cbc3c87bda943edd5dda0939cf1d1183d07 /lib/chef/win32
parentc00a3bdc8e00e512f4c3cbb2ff7169ff20a66672 (diff)
downloadchef-25b77f4e175e8a56865d3c908f29147c6d41c93a.tar.gz
Implement delete_key with Win32::Registry#delete_key
Diffstat (limited to 'lib/chef/win32')
-rw-r--r--lib/chef/win32/registry.rb39
1 files changed, 13 insertions, 26 deletions
diff --git a/lib/chef/win32/registry.rb b/lib/chef/win32/registry.rb
index e699a9bc06..12ad08a965 100644
--- a/lib/chef/win32/registry.rb
+++ b/lib/chef/win32/registry.rb
@@ -127,36 +127,23 @@ class Chef
Chef::Log.debug("Registry key #{key_path}, does not exist, not deleting")
return true
end
- #key_path is in the form "HKLM\Software\Opscode" for example, extracting
- #hive = HKLM,
- #hive_namespace = ::Win32::Registry::HKEY_LOCAL_MACHINE
- hive = key_path.split("\\").shift
- hive_namespace, key_including_parent = get_hive_and_key(key_path)
- if has_subkeys?(key_path)
- if recursive == true
- subkeys = get_subkeys(key_path)
- subkeys.each do |key|
- keypath_to_check = hive+"\\"+key_including_parent+"\\"+key
- Chef::Log.debug("Deleting registry key #{key_path} recursively")
- delete_key(keypath_to_check, true)
- end
- delete_key_ex(hive_namespace, key_including_parent)
- else
- raise Chef::Exceptions::Win32RegNoRecursive, "Registry key #{key_path} has subkeys, and recursive not specified"
- end
- else
- delete_key_ex(hive_namespace, key_including_parent)
- return true
+ if has_subkeys?(key_path) && !recursive
+ raise Chef::Exceptions::Win32RegNoRecursive, "Registry key #{key_path} has subkeys, and recursive not specified"
+ end
+ hive, key_including_parent = get_hive_and_key(key_path)
+ # key_including_parent: Software\\Root\\Branch\\Fruit
+ # key => Fruit
+ # key_parent => Software\\Root\\Branch
+ key_parts = key_including_parent.split("\\")
+ key = key_parts.pop
+ key_parent = key_parts.join("\\")
+ hive.open(key_parent, ::Win32::Registry::KEY_WRITE | registry_system_architecture) do |reg|
+ reg.delete_key(key, recursive)
end
+ Chef::Log.debug("Registry key #{key_path} deleted")
true
end
- #Using the 'RegDeleteKeyEx' Windows API that correctly supports WOW64 systems (Win2003)
- #instead of the 'RegDeleteKey'
- def delete_key_ex(hive, key)
- RegDeleteKeyExW(hive.hkey, wstring(key), 0, 0) == 0
- end
-
def key_exists?(key_path)
hive, key = get_hive_and_key(key_path)
begin