summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@chef.io>2019-04-30 17:18:58 -0700
committerGitHub <noreply@github.com>2019-04-30 17:18:58 -0700
commit58bcea78cb99d5f0ec1abf6f4870a3c0b9b3a2db (patch)
tree5b5b59c97b0fcd5949e08d991dce05a990c1da36
parentdf1a3db1deff96233756f1b2f80f48ae477881d2 (diff)
parent9ea76290936316ce6fe2d40621581210b2006572 (diff)
downloadchef-58bcea78cb99d5f0ec1abf6f4870a3c0b9b3a2db.tar.gz
Merge pull request #8417 from jaymzh/link_message
file: Tell people what file a link is pointing at in warning messages
-rw-r--r--lib/chef/provider/file.rb2
-rw-r--r--lib/chef/win32/file.rb8
-rw-r--r--spec/support/shared/unit/provider/file.rb1
3 files changed, 10 insertions, 1 deletions
diff --git a/lib/chef/provider/file.rb b/lib/chef/provider/file.rb
index 589a70de09..02da092418 100644
--- a/lib/chef/provider/file.rb
+++ b/lib/chef/provider/file.rb
@@ -228,7 +228,7 @@ class Chef
elsif file_class.symlink?(path) && new_resource.manage_symlink_source
verify_symlink_sanity(path)
elsif file_class.symlink?(new_resource.path) && new_resource.manage_symlink_source.nil?
- logger.warn("File #{path} managed by #{new_resource} is really a symlink. Managing the source file instead.")
+ logger.warn("File #{path} managed by #{new_resource} is really a symlink (to #{file_class.realpath(new_resource.path)}). Managing the source file instead.")
logger.warn("Disable this warning by setting `manage_symlink_source true` on the resource")
logger.warn("In a future Chef release, 'manage_symlink_source' will not be enabled by default")
verify_symlink_sanity(path)
diff --git a/lib/chef/win32/file.rb b/lib/chef/win32/file.rb
index 03d4496fa8..422cc194dc 100644
--- a/lib/chef/win32/file.rb
+++ b/lib/chef/win32/file.rb
@@ -89,6 +89,14 @@ class Chef
is_symlink
end
+ def self.realpath(file_name)
+ if symlink?(file_name)
+ readlink(file_name)
+ else
+ file_name
+ end
+ end
+
# Returns the path of the of the symbolic link referred to by +file+.
#
# Requires Windows Vista or later. On older versions of Windows it
diff --git a/spec/support/shared/unit/provider/file.rb b/spec/support/shared/unit/provider/file.rb
index a7c7af92f6..b3039f9be4 100644
--- a/spec/support/shared/unit/provider/file.rb
+++ b/spec/support/shared/unit/provider/file.rb
@@ -76,6 +76,7 @@ def setup_symlink
allow(File).to receive(:directory?).with(path).and_return(false)
allow(File).to receive(:writable?).with(path).and_return(true)
allow(file_symlink_class).to receive(:symlink?).with(path).and_return(true)
+ allow(file_symlink_class).to receive(:realpath).with(path).and_return(path)
end
allow(File).to receive(:directory?).with(enclosing_directory).and_return(true)
end