diff options
author | Serdar Sutay <serdar@opscode.com> | 2014-12-11 16:43:46 -0800 |
---|---|---|
committer | Serdar Sutay <serdar@opscode.com> | 2014-12-11 16:43:46 -0800 |
commit | af20f1f996b58bef6972da92e3226135318c60cd (patch) | |
tree | 62e2aec02fc4588d1eca658a14aba458e5e20efc /lib/chef/win32 | |
parent | da59a45b758793562babf871a9aedb1cd51726fd (diff) | |
download | chef-af20f1f996b58bef6972da92e3226135318c60cd.tar.gz |
As https://github.com/opscode/chef/issues/2580 summarizes, Link resource need to support relative paths in its 'to' attribute since one can create a symlink pointing to a relative location. This is useful if the directory that symlink resides in moves to a different place (e.g. mounting a disk on a separate location).sersut/revert-1901
This commit preserves relative paths inside the "encode_path" method used by the link operations and expands relative paths in similar fashion when being used by file operations.
Diffstat (limited to 'lib/chef/win32')
-rw-r--r-- | lib/chef/win32/api/file.rb | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/lib/chef/win32/api/file.rb b/lib/chef/win32/api/file.rb index 7a8dafd8b5..86b2b942c2 100644 --- a/lib/chef/win32/api/file.rb +++ b/lib/chef/win32/api/file.rb @@ -457,11 +457,21 @@ BOOL WINAPI DeviceIoControl( # takes the given path pre-pends "\\?\" and # UTF-16LE encodes it. Used to prepare paths # to be passed to the *W vesion of WinAPI File - # functions + # functions. + # This function is used by the "Link" resources where we need + # preserve relative paths because symbolic links can actually + # point to a relative path (relative to the link itself). def encode_path(path) (path_prepender << path.gsub(::File::SEPARATOR, ::File::ALT_SEPARATOR)).to_wstring end + # Expands the path, prepends "\\?\" and UTF-16LE encodes it. + # This function is used by the "File" resources where we need + # convert relative paths to fully qualified paths. + def canonical_encode_path(path) + Chef::Util::PathHelper.canonical_path(path).to_wstring + end + def path_prepender "\\\\?\\" end @@ -478,7 +488,7 @@ BOOL WINAPI DeviceIoControl( # broader fix to map all the paths starting with "/" to # SYSTEM_DRIVE on windows. path = ::File.expand_path(path) if path.start_with? "/" - path = encode_path(path) + path = canonical_encode_path(path) find_data = WIN32_FIND_DATA.new handle = FindFirstFileW(path, find_data) if handle == INVALID_HANDLE_VALUE @@ -495,7 +505,7 @@ BOOL WINAPI DeviceIoControl( # ensures the handle is closed on exit of the block def file_handle(path, &block) begin - path = encode_path(path) + path = canonical_encode_path(path) handle = CreateFileW(path, GENERIC_READ, FILE_SHARE_READ, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_BACKUP_SEMANTICS, nil) |