diff options
author | John Keiser <john@johnkeiser.com> | 2016-08-03 08:53:05 -0700 |
---|---|---|
committer | John Keiser <john@johnkeiser.com> | 2016-08-03 14:16:52 -0700 |
commit | ea3ccf9d95ef751e1f2efe1a645648e75e7add24 (patch) | |
tree | 2448697b8b4da94ee3169ea156fe0e8e2633a379 | |
parent | f34d47a1ffc29291c0ea9f544254ccaf0c9db319 (diff) | |
download | chef-ea3ccf9d95ef751e1f2efe1a645648e75e7add24.tar.gz |
Fix Ruby 2.3 `symlink?` when symlink points to nonexistent file
-rw-r--r-- | lib/chef/file_access_control/windows.rb | 6 | ||||
-rw-r--r-- | lib/chef/win32/file.rb | 8 | ||||
-rw-r--r-- | spec/functional/resource/link_spec.rb | 7 |
3 files changed, 8 insertions, 13 deletions
diff --git a/lib/chef/file_access_control/windows.rb b/lib/chef/file_access_control/windows.rb index 6b7184bbd3..6f1ac5f581 100644 --- a/lib/chef/file_access_control/windows.rb +++ b/lib/chef/file_access_control/windows.rb @@ -128,7 +128,7 @@ class Chef end def should_update_dacl? - return true unless ::File.exists?(file) + return true unless ::File.exists?(file) || ::File.symlink?(file) dacl = target_dacl existing_dacl = existing_descriptor.dacl inherits = target_inherits @@ -161,7 +161,7 @@ class Chef end def should_update_group? - return true unless ::File.exists?(file) + return true unless ::File.exists?(file) || ::File.symlink?(file) (group = target_group) && (group != existing_descriptor.group) end @@ -180,7 +180,7 @@ class Chef end def should_update_owner? - return true unless ::File.exists?(file) + return true unless ::File.exists?(file) || ::File.symlink?(file) (owner = target_owner) && (owner != existing_descriptor.owner) end diff --git a/lib/chef/win32/file.rb b/lib/chef/win32/file.rb index 2a8f453432..1009f8c5a9 100644 --- a/lib/chef/win32/file.rb +++ b/lib/chef/win32/file.rb @@ -39,7 +39,7 @@ class Chef # returns nil as per MRI. # def self.link(old_name, new_name) - raise Errno::ENOENT, "(#{old_name}, #{new_name})" unless ::File.exist?(old_name) + raise Errno::ENOENT, "(#{old_name}, #{new_name})" unless ::File.exist?(old_name) || ::File.symlink?(old_name) # TODO do a check for CreateHardLinkW and # raise NotImplemented exception on older Windows old_name = encode_path(old_name) @@ -56,7 +56,7 @@ class Chef # returns nil as per MRI. # def self.symlink(old_name, new_name) - # raise Errno::ENOENT, "(#{old_name}, #{new_name})" unless ::File.exist?(old_name) + # raise Errno::ENOENT, "(#{old_name}, #{new_name})" unless ::File.exist?(old_name) || ::File.symlink?(old_name) # TODO do a check for CreateSymbolicLinkW and # raise NotImplemented exception on older Windows flags = ::File.directory?(old_name) ? SYMBOLIC_LINK_FLAG_DIRECTORY : 0 @@ -75,7 +75,7 @@ class Chef def self.symlink?(file_name) is_symlink = false path = encode_path(file_name) - if ::File.exists?(file_name) + if ::File.exists?(file_name) || ::File.symlink?(file_name) if (GetFileAttributesW(path) & FILE_ATTRIBUTE_REPARSE_POINT) > 0 file_search_handle(file_name) do |handle, find_data| if find_data[:dw_reserved_0] == IO_REPARSE_TAG_SYMLINK @@ -93,7 +93,7 @@ class Chef # will raise a NotImplementedError, as per MRI. # def self.readlink(link_name) - raise Errno::ENOENT, link_name unless ::File.exists?(link_name) + raise Errno::ENOENT, link_name unless ::File.exists?(link_name) || ::File.symlink?(link_name) symlink_file_handle(link_name) do |handle| # Go to DeviceIoControl to get the symlink information # http://msdn.microsoft.com/en-us/library/windows/desktop/aa364571(v=vs.85).aspx diff --git a/spec/functional/resource/link_spec.rb b/spec/functional/resource/link_spec.rb index 6dd6ad8422..5e58d0918a 100644 --- a/spec/functional/resource/link_spec.rb +++ b/spec/functional/resource/link_spec.rb @@ -580,12 +580,7 @@ describe Chef::Resource::Link do it "links to the target file" do skip("OS X/FreeBSD/AIX fails to create hardlinks to broken symlinks") if os_x? || freebsd? || aix? resource.run_action(:create) - # Windows and Unix have different definitions of exists? here, and that's OK. - if windows? - expect(File.exists?(target_file)).to be_truthy - else - expect(File.exists?(target_file)).to be_falsey - end + expect(File.exists?(target_file) || File.symlink?(target_file)).to be_truthy expect(symlink?(target_file)).to be_truthy expect(readlink(target_file)).to eq(canonicalize(@other_target)) end |