Sha256: a46bcd50c2dd28a361bdf1f9dff741f0b53685dc92fdf6091dddf79c96e21df2

Contents?: true

Size: 1.1 KB

Versions: 16

Compression:

Stored size: 1.1 KB

Contents

#include <leatherman/util/scoped_env.hpp>
#include <leatherman/util/environment.hpp>

using namespace std;

namespace leatherman { namespace util {

    scoped_env::scoped_env(string var, string const& val) : scoped_resource()
    {
        string oldval;
        bool was_set = environment::get(var, oldval);
        environment::set(var, val);

        _resource = make_tuple(move(var), was_set ? boost::optional<std::string>(move(oldval)) : boost::none);
        _deleter = scoped_env::restore;
    }

    scoped_env::scoped_env(string var) : scoped_resource()
    {
        string oldval;
        bool was_set = environment::get(var, oldval);
        environment::clear(var);

        _resource = make_tuple(move(var), was_set ? boost::optional<std::string>(move(oldval)) : boost::none);
        _deleter = scoped_env::restore;
    }

    void scoped_env::restore(tuple<string, boost::optional<std::string>> & old)
    {
        if (get<1>(old)) {
            environment::set(get<0>(old), *get<1>(old));
        } else {
            environment::clear(get<0>(old));
        }
    }

}}  // namespace leatherman::util

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
facter-3.12.2.cfacter.20181217 ext/facter/leatherman/util/src/scoped_env.cc
facter-3.12.1.cfacter.20181031 ext/facter/leatherman/util/src/scoped_env.cc
facter-3.11.6.cfacter.20181031 ext/facter/leatherman/util/src/scoped_env.cc
facter-3.12.1.cfacter.20181023 ext/facter/leatherman/util/src/scoped_env.cc
facter-3.11.5.cfacter.20181022 ext/facter/leatherman/util/src/scoped_env.cc
facter-3.12.0.cfacter.20181004 ext/facter/leatherman/util/src/scoped_env.cc
facter-3.12.0.cfacter.20181001 ext/facter/leatherman/util/src/scoped_env.cc
facter-3.12.0.cfacter.20180918 ext/facter/leatherman/util/src/scoped_env.cc
facter-3.11.4.cfacter.20180821 ext/facter/leatherman/util/src/scoped_env.cc
facter-3.11.3.cfacter.20180716 ext/facter/leatherman/util/src/scoped_env.cc
facter-3.11.2.cfacter.20180612 ext/facter/leatherman/util/src/scoped_env.cc
facter-3.9.6.cfacter.20180612 ext/facter/leatherman/util/src/scoped_env.cc
facter-3.11.2.cfacter.20180606 ext/facter/leatherman/util/src/scoped_env.cc
facter-3.9.6.cfacter.20180606 ext/facter/leatherman/util/src/scoped_env.cc
facter-3.11.0.cfacter.20180319 ext/facter/leatherman/util/src/scoped_env.cc
cfacter-3.11.0.rc.20180314 ext/facter/leatherman/util/src/scoped_env.cc