summaryrefslogtreecommitdiffstats
path: root/lib/puppet/util
diff options
context:
space:
mode:
authorMax Martin <max@puppetlabs.com>2011-03-15 15:52:37 -0700
committerMax Martin <max@puppetlabs.com>2011-03-15 15:58:32 -0700
commit25926d1922a9b75bc87ed7feed30693a69cdea9a (patch)
tree2fa66f45306be3dfa1f37564a686e0f49d23b7be /lib/puppet/util
parent9016662cc108dbcced5ad9c9a33f4ecd61cac178 (diff)
downloadpuppet-25926d1922a9b75bc87ed7feed30693a69cdea9a.tar.gz
puppet-25926d1922a9b75bc87ed7feed30693a69cdea9a.tar.xz
puppet-25926d1922a9b75bc87ed7feed30693a69cdea9a.zip
(#6723) Fix withenv environment restoration bug
Ensured that withenv properly restores the environment after it runs a block and added testing for the method. Reviewed-by: Matt Robinson and Daniel Pittman
Diffstat (limited to 'lib/puppet/util')
-rw-r--r--lib/puppet/util/execution.rb9
1 files changed, 4 insertions, 5 deletions
diff --git a/lib/puppet/util/execution.rb b/lib/puppet/util/execution.rb
index dd820f856..69f4f2c15 100644
--- a/lib/puppet/util/execution.rb
+++ b/lib/puppet/util/execution.rb
@@ -4,16 +4,15 @@ module Puppet::Util::Execution
# 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 = {}
+ saved = ENV.to_hash
hash.each do |name, val|
- name = name.to_s
- oldvals[name] = ENV[name]
- ENV[name] = val
+ ENV[name.to_s] = val
end
yield
ensure
- oldvals.each do |name, val|
+ ENV.clear
+ saved.each do |name, val|
ENV[name] = val
end
end