summaryrefslogtreecommitdiffstats
path: root/lib/puppet/util/execution.rb
blob: b8dcde58d4e695722e7afc8314d5c89079c1d0f3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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]
            ENV[name] = val
        end

        yield
    ensure
        oldvals.each do |name, val|
            ENV[name] = val
        end
    end
end