summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2018-02-20 15:38:40 -0800
committerTim Smith <tsmith@chef.io>2018-02-20 15:49:12 -0800
commit1d41fef6963e64806194665f3e49c6c2f0f1398d (patch)
tree27ff571d8ac8e40582843d594fc613d6f7d2bbe5
parentc31f425c0a64d07b83e598ab5927b0bb8d48dc63 (diff)
downloadchef-1d41fef6963e64806194665f3e49c6c2f0f1398d.tar.gz
Load the current value properly in the resource
Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--lib/chef/resource/macos_userdefaults.rb25
1 files changed, 10 insertions, 15 deletions
diff --git a/lib/chef/resource/macos_userdefaults.rb b/lib/chef/resource/macos_userdefaults.rb
index 435e3682b3..c0066c84b5 100644
--- a/lib/chef/resource/macos_userdefaults.rb
+++ b/lib/chef/resource/macos_userdefaults.rb
@@ -82,24 +82,19 @@ class Chef
val
end
- action :write do
- description "Write the setting to the specified domain"
-
- @userdefaults = Chef::Resource.resource_for_node(:macos_userdefaults, node).new(new_resource.name)
- @userdefaults.key(new_resource.key)
- @userdefaults.domain(new_resource.domain)
- Chef::Log.debug("Checking #{new_resource.domain} value")
-
- drcmd = "defaults read '#{new_resource.domain}' "
- drcmd << "'#{new_resource.key}' " if new_resource.key
+ load_current_value do |desired|
+ drcmd = "defaults read '#{desired.domain}' "
+ drcmd << "'#{desired.key}' " if desired.key
shell_out_opts = {}
- shell_out_opts[:user] = new_resource.user unless new_resource.user.nil?
- vc = shell_out("#{drcmd} | grep -qx '#{new_resource.value}'", shell_out_opts)
+ shell_out_opts[:user] = desired.user unless desired.user.nil?
+ vc = shell_out("#{drcmd} | grep -qx '#{desired.value}'", shell_out_opts)
+ is_set vc.exitstatus == 0 ? true : false
+ end
- is_set = vc.exitstatus == 0 ? true : false
- @userdefaults.is_set(is_set)
+ action :write do
+ description "Write the setting to the specified domain"
- unless @userdefaults.is_set
+ unless current_value.is_set
cmd = ["defaults write"]
cmd.unshift("sudo") if new_resource.sudo