summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaire McQuin <mcquin@users.noreply.github.com>2015-09-04 11:00:00 -0700
committerClaire McQuin <mcquin@users.noreply.github.com>2015-09-04 11:00:00 -0700
commitd6cda2252c6bb318a88f44db9b878dd279bb0e46 (patch)
treeacf36e5c020d2b1211ffdced7abeb0153ee00332
parent886a3faa3d689957acbda4ee4c836140bfb98b1f (diff)
parent33fa66713f26456992cfb6f7dff8ebbe2d9e2140 (diff)
downloadchef-d6cda2252c6bb318a88f44db9b878dd279bb0e46.tar.gz
Merge pull request #3876 from chef/mcquin/tidy-win32-registry-monkeypatches
Put all Win32::Registry monkeypatches together
-rw-r--r--lib/chef/monkey_patches/win32/registry.rb31
-rw-r--r--lib/chef/win32/unicode.rb27
2 files changed, 28 insertions, 30 deletions
diff --git a/lib/chef/monkey_patches/win32/registry.rb b/lib/chef/monkey_patches/win32/registry.rb
index 5ebe67c45d..2ce2ac97f1 100644
--- a/lib/chef/monkey_patches/win32/registry.rb
+++ b/lib/chef/monkey_patches/win32/registry.rb
@@ -21,8 +21,9 @@ require 'win32/registry'
module Win32
class Registry
+
module API
-
+
extend Chef::ReservedNames::Win32::API::Registry
module_function
@@ -41,7 +42,31 @@ module Win32
def DeleteKey(hkey, name)
check RegDeleteKeyExW(hkey, name.to_wstring, 0, 0)
end
-
+
+ end
+
+ if RUBY_VERSION =~ /^2.1/
+ # ::Win32::Registry#write does not correctly handle data in Ruby 2.1 (up to Ruby 2.1.6).
+ # https://bugs.ruby-lang.org/issues/11439
+ def write(name, type, data)
+ case type
+ when REG_SZ, REG_EXPAND_SZ
+ data = data.to_s.encode(WCHAR) + WCHAR_NUL
+ when REG_MULTI_SZ
+ data = data.to_a.map {|s| s.encode(WCHAR)}.join(WCHAR_NUL) << WCHAR_NUL << WCHAR_NUL
+ when REG_BINARY
+ data = data.to_s
+ when REG_DWORD
+ data = API.packdw(data.to_i)
+ when REG_DWORD_BIG_ENDIAN
+ data = [data.to_i].pack('N')
+ when REG_QWORD
+ data = API.packqw(data.to_i)
+ else
+ raise TypeError, "Unsupported type #{type}"
+ end
+ API.SetValue(@hkey, name, type, data, data.bytesize)
+ end
end
end
-end \ No newline at end of file
+end
diff --git a/lib/chef/win32/unicode.rb b/lib/chef/win32/unicode.rb
index 562301a040..d63b9790b9 100644
--- a/lib/chef/win32/unicode.rb
+++ b/lib/chef/win32/unicode.rb
@@ -58,30 +58,3 @@ class String
utf8_to_wide(self)
end
end
-
-# https://bugs.ruby-lang.org/issues/11439
-if RUBY_VERSION =~ /^2\.1/
- module Win32
- class Registry
- def write(name, type, data)
- case type
- when REG_SZ, REG_EXPAND_SZ
- data = data.to_s.encode(WCHAR) + WCHAR_NUL
- when REG_MULTI_SZ
- data = data.to_a.map {|s| s.encode(WCHAR)}.join(WCHAR_NUL) << WCHAR_NUL << WCHAR_NUL
- when REG_BINARY
- data = data.to_s
- when REG_DWORD
- data = API.packdw(data.to_i)
- when REG_DWORD_BIG_ENDIAN
- data = [data.to_i].pack('N')
- when REG_QWORD
- data = API.packqw(data.to_i)
- else
- raise TypeError, "Unsupported type #{type}"
- end
- API.SetValue(@hkey, name, type, data, data.bytesize)
- end
- end
- end
-end \ No newline at end of file