Make resolv-replace loading optional not automatic

This commit is contained in:
Chris Roberts 2018-04-02 11:53:25 -07:00
parent e5b6271e85
commit 30e7e81eab
3 changed files with 34 additions and 10 deletions

View File

@ -134,15 +134,17 @@ module Vagrant
#
# @return [boolean] enabled or not
def self.enable_resolv_replace
if !ENV["VAGRANT_DISABLE_RESOLV_REPLACE"]
begin
require "resolv-replace"
true
rescue
if ENV["VAGRANT_ENABLE_RESOLV_REPLACE"]
if !ENV["VAGRANT_DISABLE_RESOLV_REPLACE"]
begin
require "resolv-replace"
true
rescue
false
end
else
false
end
else
false
end
end
end

View File

@ -143,4 +143,23 @@ describe Vagrant do
expect(subject.prerelease?).to be(false)
end
end
describe "#enable_resolv_replace" do
it "should not attempt to require resolv-replace by default" do
expect(subject).not_to receive(:require).with("resolv-replace")
subject.enable_resolv_replace
end
it "should require resolv-replace when VAGRANT_ENABLE_RESOLV_REPLACE is set" do
expect(subject).to receive(:require).with("resolv-replace")
with_temp_env("VAGRANT_ENABLE_RESOLV_REPLACE" => "1"){ subject.enable_resolv_replace }
end
it "should not require resolv-replace when VAGRANT_DISABLE_RESOLV_REPLACE is set" do
expect(subject).not_to receive(:require).with("resolv-replace")
with_temp_env("VAGRANT_ENABLE_RESOLV_REPLACE" => "1", "VAGRANT_DISABLE_RESOLV_REPLACE" => "1") do
subject.enable_resolv_replace
end
end
end
end

View File

@ -219,8 +219,11 @@ shared folders. Defaults to true if the option is not set. This can be overridde
on a per-folder basis within your Vagrantfile config by settings the
`SharedFoldersEnableSymlinksCreate` option to true.
## `VAGRANT_ENABLE_RESOLV_REPLACE`
Use the Ruby Resolv library in place of the libc resolver.
## `VAGRANT_DISABLE_RESOLV_REPLACE`
Vagrant will automatically load `resolv-replace` to use Ruby's Resolv library
in place of the libc resolver. This behavior can be disabled by setting this
environment variable.
Vagrant can optionally use the Ruby Resolv library in place of the libc resolver.
This can be disabled setting this environment variable.