summaryrefslogtreecommitdiffstats
path: root/lib/puppet/provider/augeas/augeas.rb
diff options
context:
space:
mode:
authorDavid Lutterkort <lutter@redhat.com>2009-05-30 23:23:11 -0700
committerJames Turnbull <james@lovedthanlost.net>2009-06-03 23:34:52 +1000
commit4951cdf4c66bfbad6495ffcab0b53d7601e73a44 (patch)
tree9147f69a0c054c8da45d8b3e25c93638690c79e1 /lib/puppet/provider/augeas/augeas.rb
parent0d5a24dd0ba4c7d1cc4827cb2d52411447202eae (diff)
downloadpuppet-4951cdf4c66bfbad6495ffcab0b53d7601e73a44.tar.gz
puppet-4951cdf4c66bfbad6495ffcab0b53d7601e73a44.tar.xz
puppet-4951cdf4c66bfbad6495ffcab0b53d7601e73a44.zip
* provider/augeas: ensure Augeas connection is always closed
Turn code like open_augeas ... close_augeas into begin open_augeas ... ensure close_augeas end Would have liked to pass the '...' as a block into a 'with_augeas' method, but that makes the spec tests fail in ways I don't understand.
Diffstat (limited to 'lib/puppet/provider/augeas/augeas.rb')
-rw-r--r--lib/puppet/provider/augeas/augeas.rb76
1 files changed, 41 insertions, 35 deletions
diff --git a/lib/puppet/provider/augeas/augeas.rb b/lib/puppet/provider/augeas/augeas.rb
index 700a09853..d435b483b 100644
--- a/lib/puppet/provider/augeas/augeas.rb
+++ b/lib/puppet/provider/augeas/augeas.rb
@@ -245,57 +245,63 @@ Puppet::Type.type(:augeas).provide(:augeas) do
def need_to_run?
force = resource[:force]
return_value = true
- open_augeas
- filter = resource[:onlyif]
- unless filter == ""
- cmd_array = parse_commands(filter)[0]
- command = cmd_array[0];
- begin
- case command
+ begin
+ open_augeas
+ filter = resource[:onlyif]
+ unless filter == ""
+ cmd_array = parse_commands(filter)[0]
+ command = cmd_array[0];
+ begin
+ case command
when "get"; return_value = process_get(cmd_array)
when "match"; return_value = process_match(cmd_array)
+ end
+ rescue Exception => e
+ fail("Error sending command '#{command}' with params #{cmd_array[1..-1].inspect}/#{e.message}")
end
- rescue Exception => e
- fail("Error sending command '#{command}' with params #{cmd_array[1..-1].inspect}/#{e.message}")
end
- end
- unless force
- # If we have a verison of augeas which is at least 0.3.6 then we
- # can make the changes now, see if changes were made, and
- # actually do the save.
- if return_value and get_augeas_version >= "0.3.6"
- debug("Will attempt to save and only run if files changed")
- set_augeas_save_mode(SAVE_NOOP)
- do_execute_changes
- save_result = @aug.save
- saved_files = @aug.match("/augeas/events/saved")
- if save_result and not files_changed?
- debug("Skipping becuase no files were changed")
- return_value = false
- else
- debug("Files changed, should execute")
+ unless force
+ # If we have a verison of augeas which is at least 0.3.6 then we
+ # can make the changes now, see if changes were made, and
+ # actually do the save.
+ if return_value and get_augeas_version >= "0.3.6"
+ debug("Will attempt to save and only run if files changed")
+ set_augeas_save_mode(SAVE_NOOP)
+ do_execute_changes
+ save_result = @aug.save
+ saved_files = @aug.match("/augeas/events/saved")
+ if save_result and not files_changed?
+ debug("Skipping becuase no files were changed")
+ return_value = false
+ else
+ debug("Files changed, should execute")
+ end
end
end
+ ensure
+ close_augeas
end
- close_augeas
return return_value
end
def execute_changes
# Re-connect to augeas, and re-execute the changes
- open_augeas
- if get_augeas_version >= "0.3.6"
- set_augeas_save_mode(SAVE_OVERWRITE)
- end
+ begin
+ open_augeas
+ if get_augeas_version >= "0.3.6"
+ set_augeas_save_mode(SAVE_OVERWRITE)
+ end
- do_execute_changes
+ do_execute_changes
- success = @aug.save
- if success != true
- fail("Save failed with return code #{success}")
+ success = @aug.save
+ if success != true
+ fail("Save failed with return code #{success}")
+ end
+ ensure
+ close_augeas
end
- close_augeas
return :executed
end