summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThom May <thom@may.lt>2016-10-14 09:33:52 +0100
committerGitHub <noreply@github.com>2016-10-14 09:33:52 +0100
commitd07e5ba629fdda3500709981ea2aeba16404d560 (patch)
treeb46e1f83f81f09b11ca1295f01de9def70049d5d
parentfa6bf6391590aae181feb64840c6cc5110f60275 (diff)
parenta28b5024f9725939e2bd3666e83d5ea576b5ffa3 (diff)
downloadchef-d07e5ba629fdda3500709981ea2aeba16404d560.tar.gz
Merge pull request #5452 from phene/better-user-provider-comparison-of-home-paths
User Provider: Fix home folder comparison
-rw-r--r--lib/chef/provider/user.rb10
-rw-r--r--spec/unit/provider/user_spec.rb6
2 files changed, 10 insertions, 6 deletions
diff --git a/lib/chef/provider/user.rb b/lib/chef/provider/user.rb
index f6b088d333..4b05ac8f5e 100644
--- a/lib/chef/provider/user.rb
+++ b/lib/chef/provider/user.rb
@@ -113,15 +113,13 @@ class Chef
# <true>:: If a change is required
# <false>:: If the users are identical
def compare_user
- changed = [ :comment, :home, :shell, :password ].select do |user_attrib|
- !@new_resource.send(user_attrib).nil? && @new_resource.send(user_attrib) != @current_resource.send(user_attrib)
- end
+ return true if !@new_resource.home.nil? && Pathname.new(@new_resource.home).cleanpath != Pathname.new(@current_resource.home).cleanpath
- changed += [ :uid, :gid ].select do |user_attrib|
- !@new_resource.send(user_attrib).nil? && @new_resource.send(user_attrib).to_s != @current_resource.send(user_attrib).to_s
+ [ :comment, :shell, :password, :uid, :gid ].each do |user_attrib|
+ return true if !@new_resource.send(user_attrib).nil? && @new_resource.send(user_attrib).to_s != @current_resource.send(user_attrib).to_s
end
- changed.any?
+ false
end
def action_create
diff --git a/spec/unit/provider/user_spec.rb b/spec/unit/provider/user_spec.rb
index 1a8ad6ad1b..719dc8d492 100644
--- a/spec/unit/provider/user_spec.rb
+++ b/spec/unit/provider/user_spec.rb
@@ -221,6 +221,12 @@ describe Chef::Provider::User do
it "should return false if the objects are identical" do
expect(@provider.compare_user).to eql(false)
end
+
+ it "should ignore differences in trailing slash in home paths" do
+ @new_resource.home "/home/adam"
+ @current_resource.home "/home/adam/"
+ expect(@provider.compare_user).to eql(false)
+ end
end
describe "action_create" do