summaryrefslogtreecommitdiffstats
path: root/lib/puppet/util
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-09-05 22:57:48 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-09-05 22:57:48 +0000
commit8310c9d18a89e499b63a10e7890d836dcfc86f46 (patch)
tree60fcb3ad16dffce1acdb8a4e3088f848cf7b8b2e /lib/puppet/util
parentf8254c6a1a080c89608ca98b7fe8e6231a9d213f (diff)
downloadpuppet-8310c9d18a89e499b63a10e7890d836dcfc86f46.tar.gz
puppet-8310c9d18a89e499b63a10e7890d836dcfc86f46.tar.xz
puppet-8310c9d18a89e499b63a10e7890d836dcfc86f46.zip
Adding a "withenv" execution util method, and using it in :exec for path handling. Next will be other env handling.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1567 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/puppet/util')
-rw-r--r--lib/puppet/util/execution.rb21
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$