This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Update to load_current_resource replacing 'truthy' with 'truefalse'.

    defaults --help
    <value> is one of:
      -bool[ean] (true | false | yes | no)

Right now we only convert 'TRUE' or 'true' which leads to a situation whereby chef-client reapplies settings (defaults write <DOMAIN> <KEY> -bool 'false') upon each run because the recipe value may validly be 'false'.

Example recipe snippet which triggers this situation -

  mac_os_x_userdefaults "dont show quarantine warnings on downloaded files" do
    domain "com.apple.LaunchServices"
    key "LSQuarantine"
    value "false"
    type "bool"
    notifies :run, 'execute[killall Finder]'
    only_if { node[:platform_version].to_f >= 10.5 }
  end

I've also taken the opportunity to extend things so that "YES" and "yes" are considered to be true values, because they would be accepted on the command-line by /usr/bin/defaults as valid input.
  • Loading branch information...
agh committed Mar 4, 2012
1 parent 9b31946 commit 4f07be3239b8d83f2280d2354c36c6d0d9a5fec6
Showing with 3 additions and 2 deletions.
  1. +3 −2 providers/userdefaults.rb
@@ -26,11 +26,12 @@ def load_current_resource
@userdefaults.key(new_resource.key)
@userdefaults.domain(new_resource.domain)
Chef::Log.debug("Checking #{new_resource.domain} value")
- truthy = 1 if ['TRUE','1','true'].include?(new_resource.value)
+ truefalse = 1 if ['TRUE','1','true','YES','yes'].include?(new_resource.value)
+ truefalse = 0 if ['FALSE','0','false','NO','no'].include?(new.resource.value)
drcmd = "defaults read #{new_resource.domain} "
drcmd << "-g " if new_resource.global
drcmd << "#{new_resource.key} " if new_resource.key
- v = shell_out("#{drcmd} | grep -qx '#{truthy || new_resource.value}'")
+ v = shell_out("#{drcmd} | grep -qx '#{truefalse || new_resource.value}'")
is_set = v.exitstatus == 0 ? true : false
@userdefaults.is_set(is_set)
end

0 comments on commit 4f07be3

Please sign in to comment.