diff options
Diffstat (limited to 'lib/puppet/util/execution.rb')
-rw-r--r-- | lib/puppet/util/execution.rb | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/puppet/util/execution.rb b/lib/puppet/util/execution.rb new file mode 100644 index 000000000..67b5ed692 --- /dev/null +++ b/lib/puppet/util/execution.rb @@ -0,0 +1,21 @@ +module Puppet::Util::Execution + module_function + + # Run some code with a specific environment. Resets the environment back to + # what it was at the end of the code. + def withenv(hash) + oldvals = {} + hash.each do |name, val| + name = name.to_s + oldvals[name] = ENV[name] + end + + yield + ensure + oldvals.each do |name, val| + ENV[name] = val + end + end +end + +# $Id$ |