diff options
author | Jay Mundrawala <jdmundrawala@gmail.com> | 2014-09-09 17:44:36 -0700 |
---|---|---|
committer | Jay Mundrawala <jdmundrawala@gmail.com> | 2014-09-11 12:12:55 -0700 |
commit | 3f01d0a3ad058e3b21244d205ac1a7ad793875dc (patch) | |
tree | c0304f06d6c15f461c18a6ac411abdfc2275f37b /lib/chef | |
parent | e6613a101de325caab78a1b392d0a149d02e270c (diff) | |
download | chef-3f01d0a3ad058e3b21244d205ac1a7ad793875dc.tar.gz |
Use windows api to expand path. Cleaned up tests
Diffstat (limited to 'lib/chef')
-rw-r--r-- | lib/chef/provider/env/windows.rb | 10 | ||||
-rw-r--r-- | lib/chef/win32/api/system.rb | 9 |
2 files changed, 14 insertions, 5 deletions
diff --git a/lib/chef/provider/env/windows.rb b/lib/chef/provider/env/windows.rb index 990ab178af..79abda8708 100644 --- a/lib/chef/provider/env/windows.rb +++ b/lib/chef/provider/env/windows.rb @@ -33,10 +33,9 @@ class Chef end obj.variablevalue = @new_resource.value obj.put_ - value = @new_resource.value + value = @new_resource.value value = expand_path(value) if @new_resource.key_name.upcase == 'PATH' ENV[@new_resource.key_name] = value - broadcast_env_change end @@ -78,10 +77,11 @@ class Chef private def expand_path(path) - system_vars = %w(HomeDrive HomePath ProgramFiles SystemDirectory SystemDrive SystemRoot Temp Tmp UserProfile WinDir) - system_vars.each_with_object(path) do |variable, new_path| - new_path.gsub!(/%#{variable}%/i, ENV[variable]) if ENV[variable] + buf = 0.chr * 32 * (1 << 10) # http://msdn.microsoft.com/en-us/library/windows/desktop/ms724265%28v=vs.85%29.aspx + if ExpandEnvironmentStringsA(path, buf, buf.length) == 0 + Chef::ReservedNames::Win32::Error.raise! end + buf.strip end end end diff --git a/lib/chef/win32/api/system.rb b/lib/chef/win32/api/system.rb index a58c0f38f4..d57699acb4 100644 --- a/lib/chef/win32/api/system.rb +++ b/lib/chef/win32/api/system.rb @@ -200,6 +200,15 @@ LRESULT WINAPI SendMessageTimeout( safe_attach_function :SendMessageTimeoutW, [:HWND, :UINT, :WPARAM, :LPARAM, :UINT, :UINT, :PDWORD_PTR], :LRESULT safe_attach_function :SendMessageTimeoutA, [:HWND, :UINT, :WPARAM, :LPARAM, :UINT, :UINT, :PDWORD_PTR], :LRESULT +=begin +DWORD WINAPI ExpandEnvironmentStrings( + _In_ LPCTSTR lpSrc, + _Out_opt_ LPTSTR lpDst, + _In_ DWORD nSize +); +=end + safe_attach_function :ExpandEnvironmentStringsW, [:pointer, :pointer, :DWORD], :DWORD + safe_attach_function :ExpandEnvironmentStringsA, [:pointer, :pointer, :DWORD], :DWORD end end end |