diff options
Diffstat (limited to 'lib/chef/win32')
-rw-r--r-- | lib/chef/win32/api.rb | 10 | ||||
-rw-r--r-- | lib/chef/win32/api/file.rb | 56 | ||||
-rw-r--r-- | lib/chef/win32/api/installer.rb | 4 | ||||
-rw-r--r-- | lib/chef/win32/file.rb | 10 | ||||
-rw-r--r-- | lib/chef/win32/registry.rb | 18 | ||||
-rw-r--r-- | lib/chef/win32/security/acl.rb | 4 | ||||
-rw-r--r-- | lib/chef/win32/unicode.rb | 4 | ||||
-rw-r--r-- | lib/chef/win32/version.rb | 2 |
8 files changed, 49 insertions, 59 deletions
diff --git a/lib/chef/win32/api.rb b/lib/chef/win32/api.rb index 64db9d2b63..503920a0ed 100644 --- a/lib/chef/win32/api.rb +++ b/lib/chef/win32/api.rb @@ -29,12 +29,10 @@ class Chef # function into the calling module. If this fails a dummy method is # defined which when called, raises a helpful exception to the end-user. def safe_attach_function(win32_func, *args) - begin - attach_function(win32_func.to_sym, *args) - rescue FFI::NotFoundError - define_method(win32_func.to_sym) do |*margs| - raise Chef::Exceptions::Win32APIFunctionNotImplemented, "This version of Windows does not implement the Win32 function [#{win32_func}]." - end + attach_function(win32_func.to_sym, *args) + rescue FFI::NotFoundError + define_method(win32_func.to_sym) do |*margs| + raise Chef::Exceptions::Win32APIFunctionNotImplemented, "This version of Windows does not implement the Win32 function [#{win32_func}]." end end diff --git a/lib/chef/win32/api/file.rb b/lib/chef/win32/api/file.rb index 7489c94fd9..355cc81378 100644 --- a/lib/chef/win32/api/file.rb +++ b/lib/chef/win32/api/file.rb @@ -537,24 +537,22 @@ BOOL WINAPI VerQueryValue( # ensures the handle is closed on exit of the block # FIXME: yard with @yield def file_search_handle(path) - begin # Workaround for CHEF-4419: # Make sure paths starting with "/" has a drive letter # assigned from the current working diretory. # Note: With CHEF-4427 this issue will be fixed with a # broader fix to map all the paths starting with "/" to # SYSTEM_DRIVE on windows. - path = ::File.expand_path(path) if path.start_with? "/" - path = canonical_encode_path(path) - find_data = WIN32_FIND_DATA.new - handle = FindFirstFileW(path, find_data) - if handle == INVALID_HANDLE_VALUE - Chef::ReservedNames::Win32::Error.raise! - end - yield(handle, find_data) - ensure - FindClose(handle) if handle && handle != INVALID_HANDLE_VALUE + path = ::File.expand_path(path) if path.start_with? "/" + path = canonical_encode_path(path) + find_data = WIN32_FIND_DATA.new + handle = FindFirstFileW(path, find_data) + if handle == INVALID_HANDLE_VALUE + Chef::ReservedNames::Win32::Error.raise! end + yield(handle, find_data) + ensure + FindClose(handle) if handle && handle != INVALID_HANDLE_VALUE end # retrieves a file handle and passes it @@ -562,34 +560,30 @@ BOOL WINAPI VerQueryValue( # ensures the handle is closed on exit of the block # FIXME: yard with @yield def file_handle(path) - begin - path = canonical_encode_path(path) - handle = CreateFileW(path, GENERIC_READ, FILE_SHARE_READ, - nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_BACKUP_SEMANTICS, nil) + path = canonical_encode_path(path) + handle = CreateFileW(path, GENERIC_READ, FILE_SHARE_READ, + nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_BACKUP_SEMANTICS, nil) - if handle == INVALID_HANDLE_VALUE - Chef::ReservedNames::Win32::Error.raise! - end - yield(handle) - ensure - CloseHandle(handle) if handle && handle != INVALID_HANDLE_VALUE + if handle == INVALID_HANDLE_VALUE + Chef::ReservedNames::Win32::Error.raise! end + yield(handle) + ensure + CloseHandle(handle) if handle && handle != INVALID_HANDLE_VALUE end # FIXME: yard with @yield def symlink_file_handle(path) - begin - path = encode_path(path) - handle = CreateFileW(path, FILE_READ_EA, FILE_SHARE_READ, - nil, OPEN_EXISTING, FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_BACKUP_SEMANTICS, nil) + path = encode_path(path) + handle = CreateFileW(path, FILE_READ_EA, FILE_SHARE_READ, + nil, OPEN_EXISTING, FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_BACKUP_SEMANTICS, nil) - if handle == INVALID_HANDLE_VALUE - Chef::ReservedNames::Win32::Error.raise! - end - yield(handle) - ensure - CloseHandle(handle) if handle && handle != INVALID_HANDLE_VALUE + if handle == INVALID_HANDLE_VALUE + Chef::ReservedNames::Win32::Error.raise! end + yield(handle) + ensure + CloseHandle(handle) if handle && handle != INVALID_HANDLE_VALUE end def retrieve_file_info(file_name) diff --git a/lib/chef/win32/api/installer.rb b/lib/chef/win32/api/installer.rb index caf7b23f59..46930b65fc 100644 --- a/lib/chef/win32/api/installer.rb +++ b/lib/chef/win32/api/installer.rb @@ -107,7 +107,7 @@ UINT MsiCloseHandle( end msi_close_handle(pkg_ptr.read_pointer) - return buffer.chomp(0.chr) + buffer.chomp(0.chr) end # Opens a Microsoft Installer (MSI) file from an absolute path and returns a pointer to a handle @@ -124,7 +124,7 @@ UINT MsiCloseHandle( else raise Chef::Exceptions::Package, "msi_open_package: unexpected status #{status}: #{Chef::ReservedNames::Win32::Error.format_message(status)}" end - return pkg_ptr + pkg_ptr end # All installed product_codes should have a VersionString diff --git a/lib/chef/win32/file.rb b/lib/chef/win32/file.rb index 1009f8c5a9..fa3d0f7a9d 100644 --- a/lib/chef/win32/file.rb +++ b/lib/chef/win32/file.rb @@ -155,13 +155,11 @@ class Chef end def self.verify_links_supported! - begin - CreateSymbolicLinkW(nil) - rescue Chef::Exceptions::Win32APIFunctionNotImplemented => e - raise e - rescue Exception + CreateSymbolicLinkW(nil) + rescue Chef::Exceptions::Win32APIFunctionNotImplemented => e + raise e + rescue Exception # things are ok. - end end def self.file_access_check(path, desired_access) diff --git a/lib/chef/win32/registry.rb b/lib/chef/win32/registry.rb index 613994295c..6f1eb9ff12 100644 --- a/lib/chef/win32/registry.rb +++ b/lib/chef/win32/registry.rb @@ -170,7 +170,7 @@ class Chef rescue Chef::Exceptions::Win32RegHiveMissing => e return false end - return true + true end def has_subkeys?(key_path) @@ -179,7 +179,7 @@ class Chef hive.open(key, ::Win32::Registry::KEY_READ | registry_system_architecture) do |reg| reg.each_key { |key| return true } end - return false + false end def get_subkeys(key_path) @@ -189,7 +189,7 @@ class Chef hive.open(key, ::Win32::Registry::KEY_READ | registry_system_architecture) do |reg| reg.each_key { |current_key| subkeys << current_key } end - return subkeys + subkeys end # 32-bit chef clients running on 64-bit machines will default to reading the 64-bit registry @@ -204,7 +204,7 @@ class Chef hive.open(key, ::Win32::Registry::KEY_READ | registry_system_architecture) do |reg| return true if reg.any? { |val| safely_downcase(val) == safely_downcase(value[:name]) } end - return false + false end def data_exists?(key_path, value) @@ -219,7 +219,7 @@ class Chef end end end - return false + false end def value_exists!(key_path, value) @@ -249,7 +249,7 @@ class Chef end end end - return false + false end def type_matches!(key_path, value) @@ -279,7 +279,7 @@ class Chef if val.is_a? String return val.downcase end - return val + val end def node @@ -316,7 +316,7 @@ class Chef raise Chef::Exceptions::Win32RegHiveMissing, "Registry Hive #{hive_name} does not exist" unless hive - return hive, key + [hive, key] end def _type_name_map @@ -345,7 +345,7 @@ class Chef 5 => ::Win32::Registry::REG_DWORD_BIG_ENDIAN, 11 => ::Win32::Registry::REG_QWORD, }[val_type] - return value + value end def create_missing(key_path) diff --git a/lib/chef/win32/security/acl.rb b/lib/chef/win32/security/acl.rb index 8a04987e44..0d9f7decd0 100644 --- a/lib/chef/win32/security/acl.rb +++ b/lib/chef/win32/security/acl.rb @@ -48,7 +48,7 @@ class Chef 0.upto(length - 1) do |i| return false if self[i] != other[i] end - return true + true end def pointer @@ -88,7 +88,7 @@ class Chef end def to_s - "[#{self.collect { |ace| ace.to_s }.join(", ")}]" + "[#{collect { |ace| ace.to_s }.join(", ")}]" end def self.align_dword(size) diff --git a/lib/chef/win32/unicode.rb b/lib/chef/win32/unicode.rb index d531463be0..dd5a197f71 100644 --- a/lib/chef/win32/unicode.rb +++ b/lib/chef/win32/unicode.rb @@ -40,13 +40,13 @@ module FFI last_char = nil while last_char != "\000\000" length += 1 - last_char = self.get_bytes(0, length * 2)[-2..-1] + last_char = get_bytes(0, length * 2)[-2..-1] end num_wchars = length end - wide_to_utf8(self.get_bytes(0, num_wchars * 2)) + wide_to_utf8(get_bytes(0, num_wchars * 2)) end end end diff --git a/lib/chef/win32/version.rb b/lib/chef/win32/version.rb index 303fe1531d..3e2d6bc1fe 100644 --- a/lib/chef/win32/version.rb +++ b/lib/chef/win32/version.rb @@ -100,7 +100,7 @@ class Chef define_method(:marketing_name) do marketing_names.each do |mn| - break mn[0] if self.send(mn[1]) + break mn[0] if send(mn[1]) end end |