diff options
author | Jay Mundrawala <jdmundrawala@gmail.com> | 2015-08-26 14:09:05 -0700 |
---|---|---|
committer | Kartik Null Cating-Subramanian <ksubramanian@chef.io> | 2015-08-27 11:54:47 -0400 |
commit | 652b582c1ca7ceabe57cdf6b170fe97f4d661584 (patch) | |
tree | 919c0dd88cefaaa0c2c5699d267eb185761400eb | |
parent | 3fff2b493fe51398cc139f4c4239beee193b0097 (diff) | |
download | chef-652b582c1ca7ceabe57cdf6b170fe97f4d661584.tar.gz |
Rewrite DeleteVolumeMountPoint to use FFI
-rw-r--r-- | lib/chef/util/windows/volume.rb | 10 | ||||
-rw-r--r-- | lib/chef/win32/api/file.rb | 6 | ||||
-rw-r--r-- | lib/chef/win32/file.rb | 10 |
3 files changed, 21 insertions, 5 deletions
diff --git a/lib/chef/util/windows/volume.rb b/lib/chef/util/windows/volume.rb index 08c3a53793..15780d61a1 100644 --- a/lib/chef/util/windows/volume.rb +++ b/lib/chef/util/windows/volume.rb @@ -18,6 +18,7 @@ #simple wrapper around Volume APIs. might be possible with WMI, but possibly more complex. +require 'chef/win32/api/file' require 'chef/util/windows' require 'windows/volume' @@ -25,9 +26,6 @@ class Chef::Util::Windows::Volume < Chef::Util::Windows private include Windows::Volume - #XXX not defined in the current windows-pr release - DeleteVolumeMountPoint = - Windows::API.new('DeleteVolumeMountPoint', 'S', 'B') unless defined? DeleteVolumeMountPoint public @@ -46,8 +44,10 @@ class Chef::Util::Windows::Volume < Chef::Util::Windows end def delete - unless DeleteVolumeMountPoint.call(@name) - raise ArgumentError, get_last_error + begin + Chef::ReservedNames::Win32::File.delete_volume_mount_point(@name) + rescue Chef::Exceptions::Win32APIError => e + raise ArgumentError, e end end diff --git a/lib/chef/win32/api/file.rb b/lib/chef/win32/api/file.rb index 86b2b942c2..4ea07ad39b 100644 --- a/lib/chef/win32/api/file.rb +++ b/lib/chef/win32/api/file.rb @@ -450,6 +450,12 @@ BOOL WINAPI DeviceIoControl( =end safe_attach_function :DeviceIoControl, [:HANDLE, :DWORD, :LPVOID, :DWORD, :LPVOID, :DWORD, :LPDWORD, :pointer], :BOOL + +#BOOL WINAPI DeleteVolumeMountPoint( + #_In_ LPCTSTR lpszVolumeMountPoint +#); + safe_attach_function :DeleteVolumeMountPointW, [:LPCTSTR], :BOOL + ############################################### # Helpers ############################################### diff --git a/lib/chef/win32/file.rb b/lib/chef/win32/file.rb index e6640caa3c..a577f04acc 100644 --- a/lib/chef/win32/file.rb +++ b/lib/chef/win32/file.rb @@ -20,6 +20,7 @@ require 'chef/win32/api/file' require 'chef/win32/api/security' require 'chef/win32/error' +require 'chef/mixin/wstring' class Chef module ReservedNames::Win32 @@ -27,6 +28,9 @@ class Chef include Chef::ReservedNames::Win32::API::File extend Chef::ReservedNames::Win32::API::File + include Chef::Mixin::WideString + extend Chef::Mixin::WideString + # Creates a symbolic link called +new_name+ for the file or directory # +old_name+. # @@ -176,6 +180,12 @@ class Chef desired_access, mapping) end + def self.delete_volume_mount_point(mount_point) + unless DeleteVolumeMountPointW(wstring(mount_point)) + Chef::ReservedNames::Win32::Error.raise! + end + end + # ::File compat class << self alias :stat :info |