Sha256: 757fd28c6125154ac779803205fd490ff285a2fd7a82bd5b5a9984f235ab04f7

Contents?: true

Size: 1.63 KB

Versions: 48

Compression:

Stored size: 1.63 KB

Contents

module Vagrant
  module Util
    class Env
      def self.with_original_env
        original_env = ENV.to_hash
        if defined?(::Bundler) && defined?(::Bundler::ORIGINAL_ENV)
          ENV.replace(::Bundler::ORIGINAL_ENV)
        end
        ENV.update(Vagrant.original_env)
        yield
      ensure
        ENV.replace(original_env.to_hash)
      end

      # Execute the given command, removing any Ruby-specific environment
      # variables. This is an "enhanced" version of `Bundler.with_clean_env`,
      # which only removes Bundler-specific values. We need to remove all
      # values, specifically:
      #
      # - _ORIGINAL_GEM_PATH
      # - GEM_PATH
      # - GEM_HOME
      # - GEM_ROOT
      # - BUNDLE_BIN_PATH
      # - BUNDLE_GEMFILE
      # - RUBYLIB
      # - RUBYOPT
      # - RUBY_ENGINE
      # - RUBY_ROOT
      # - RUBY_VERSION
      #
      # This will escape Vagrant's environment entirely, which is required if
      # calling an executable that lives in another Ruby environment. The
      # original environment restored at the end of this call.
      #
      # @param [Proc] block
      #   the block to execute with the cleaned environment
      def self.with_clean_env
        with_original_env do
          if ENV["BUNDLE_ORIG_MANPATH"]
            ENV["MANPATH"] = ENV["BUNDLE_ORIG_MANPATH"]
          end
          ENV.delete_if { |k,_| k[0,7] == "BUNDLE_" }
          if ENV.has_key? "RUBYOPT"
            ENV["RUBYOPT"] = ENV["RUBYOPT"].sub("-rbundler/setup", "")
            ENV["RUBYOPT"] = ENV["RUBYOPT"].sub("-I#{File.expand_path('..', __FILE__)}", "")
          end
          yield
        end
      end
    end
  end
end

Version data entries

48 entries across 44 versions & 5 rubygems

Version Path
vagrant-unbundled-2.3.6.0 lib/vagrant/util/env.rb
tamtam-vagrant-reload-1.2.1 vendor/cache/vagrant-2092df529ae7/lib/vagrant/util/env.rb
vagrant-unbundled-2.3.3.0 lib/vagrant/util/env.rb
vagrant-unbundled-2.3.2.0 lib/vagrant/util/env.rb
vagrant-unbundled-2.2.19.0 lib/vagrant/util/env.rb
vagrant-unbundled-2.2.18.0 lib/vagrant/util/env.rb
vagrant-unbundled-2.2.16.0 lib/vagrant/util/env.rb
vagrant-unbundled-2.2.14.0 lib/vagrant/util/env.rb
vagrant-aws-mkubenka-0.7.2.pre.24 vendor/bundle/ruby/2.7.0/bundler/gems/vagrant-22795b161bf6/lib/vagrant/util/env.rb
vagrant-unbundled-2.2.10.0 lib/vagrant/util/env.rb
vagrant-unbundled-2.2.9.0 lib/vagrant/util/env.rb
vagrant-unbundled-2.2.8.0 lib/vagrant/util/env.rb
vagrant-unbundled-2.2.7.0 lib/vagrant/util/env.rb
vagrant-unbundled-2.2.6.2 lib/vagrant/util/env.rb
vagrant-unbundled-2.2.6.1 lib/vagrant/util/env.rb
vagrant-unbundled-2.2.6.0 lib/vagrant/util/env.rb
vagrant-unbundled-2.2.5.0 lib/vagrant/util/env.rb
vagrant-unbundled-2.2.4.0 lib/vagrant/util/env.rb
vagrant-unbundled-2.2.3.0 lib/vagrant/util/env.rb
vagrant-unbundled-2.2.2.0 lib/vagrant/util/env.rb