diff options
author | Jay Mundrawala <jdmundrawala@gmail.com> | 2014-10-17 16:09:11 -0700 |
---|---|---|
committer | Jay Mundrawala <jdmundrawala@gmail.com> | 2014-10-23 18:05:50 -0700 |
commit | dc6dc017e706840a9681bef1a75391a91ab6a2e0 (patch) | |
tree | a1e6ba5483a3263fcd6b35503278254a7aeff11a /lib/chef/provider/env.rb | |
parent | 4e9b9ff856632a16559afc52fc4651340986c2e3 (diff) | |
download | chef-dc6dc017e706840a9681bef1a75391a91ab6a2e0.tar.gz |
Modified env resource to break values up by delimiter before comparing.
For example, if someone were to do before this patch,
```ruby
windows_path 'C:\foo;C:\bar' do
action :create
...
end
```
the path would grow each time this recipe was executed. This is because
compare_path would break up the current path with ;, but would not do
the same for the value being added.
Diffstat (limited to 'lib/chef/provider/env.rb')
-rw-r--r-- | lib/chef/provider/env.rb | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/lib/chef/provider/env.rb b/lib/chef/provider/env.rb index e91b8bbb97..e2c23dec8b 100644 --- a/lib/chef/provider/env.rb +++ b/lib/chef/provider/env.rb @@ -61,8 +61,9 @@ class Chef def compare_value if @new_resource.delim #e.g. check for existing value within PATH - not @current_resource.value.split(@new_resource.delim).any? do |val| - val == @new_resource.value + current_values = @current_resource.value.split(@new_resource.delim) + not @new_resource.value.split(@new_resource.delim).all? do |val| + current_values.include? val end else @new_resource.value != @current_resource.value @@ -91,13 +92,16 @@ class Chef # after we removed the element. def delete_element return false unless @new_resource.delim #no delim: delete the key - if compare_value + values = @new_resource.value.split(@new_resource.delim) + current_values = @current_resource.value.split(@new_resource.delim) + needs_delete = values.any? { |v| current_values.include?(v) } + if not needs_delete Chef::Log.debug("#{@new_resource} element '#{@new_resource.value}' does not exist") return true #do not delete the key else new_value = @current_resource.value.split(@new_resource.delim).select { |item| - item != @new_resource.value + values.include?(item) }.join(@new_resource.delim) if new_value.empty? @@ -142,8 +146,11 @@ class Chef def modify_env if @new_resource.delim - #e.g. add to PATH - @new_resource.value(@new_resource.value + @new_resource.delim + @current_resource.value) + current_values = @current_resource.value.split(@new_resource.delim) + values = @new_resource.value.split(@new_resource.delim).reject do |v| + current_values.include?(v) + end + @new_resource.value((values + [@current_resource.value]).join(@new_resource.delim)) end create_env end |