Cache value for modinfo_path

This commit is contained in:
Jeff Bonhag 2019-11-05 14:57:09 -05:00
parent 59901bd9fc
commit c5439f6b43
2 changed files with 27 additions and 8 deletions

View File

@ -262,16 +262,25 @@ module VagrantPlugins
end
def self.modinfo_path
path = Vagrant::Util::Which.which("modinfo")
return path if path
if !defined?(@_modinfo_path)
@_modinfo_path = Vagrant::Util::Which.which("modinfo")
folders = ["/sbin"]
folders.each do |folder|
path = "#{folder}/modinfo"
return path if File.file?(path)
if @_modinfo_path.to_s.empty?
folders = ["/sbin"]
folders.each do |folder|
path = "#{folder}/modinfo"
if File.file?(path)
@_modinfo_path = path
break
end
end
end
if @_modinfo_path.to_s.empty?
@_modinfo_path = "modinfo"
end
end
"modinfo"
@_modinfo_path
end
# @private

View File

@ -372,5 +372,15 @@ EOH
expect(cap.modinfo_path).to eq("modinfo")
end
end
context "with cached value for modinfo_path" do
before do
cap.instance_variable_set(:@_modinfo_path, "/usr/local/bin/modinfo")
end
it "should use cached value" do
expect(cap.modinfo_path).to eq("/usr/local/bin/modinfo")
end
end
end
end