providers/virtualbox: wrap version set in mutex
This commit is contained in:
parent
fb511a43d9
commit
a75b14b769
|
@ -1,4 +1,5 @@
|
||||||
require "forwardable"
|
require "forwardable"
|
||||||
|
require "thread"
|
||||||
|
|
||||||
require "log4r"
|
require "log4r"
|
||||||
|
|
||||||
|
@ -20,6 +21,7 @@ module VagrantPlugins
|
||||||
# We cache the read VirtualBox version here once we have one,
|
# We cache the read VirtualBox version here once we have one,
|
||||||
# since during the execution of Vagrant, it likely doesn't change.
|
# since during the execution of Vagrant, it likely doesn't change.
|
||||||
@@version = nil
|
@@version = nil
|
||||||
|
@@version_lock = Mutex.new
|
||||||
|
|
||||||
# The UUID of the virtual machine we represent
|
# The UUID of the virtual machine we represent
|
||||||
attr_reader :uuid
|
attr_reader :uuid
|
||||||
|
@ -36,16 +38,18 @@ module VagrantPlugins
|
||||||
@logger = Log4r::Logger.new("vagrant::provider::virtualbox::meta")
|
@logger = Log4r::Logger.new("vagrant::provider::virtualbox::meta")
|
||||||
@uuid = uuid
|
@uuid = uuid
|
||||||
|
|
||||||
if !@@version
|
@@version_lock.synchronize do
|
||||||
# Read and assign the version of VirtualBox we know which
|
if !@@version
|
||||||
# specific driver to instantiate.
|
# Read and assign the version of VirtualBox we know which
|
||||||
begin
|
# specific driver to instantiate.
|
||||||
@@version = read_version
|
begin
|
||||||
rescue Vagrant::Errors::CommandUnavailable,
|
@@version = read_version
|
||||||
Vagrant::Errors::CommandUnavailableWindows
|
rescue Vagrant::Errors::CommandUnavailable,
|
||||||
# This means that VirtualBox was not found, so we raise this
|
Vagrant::Errors::CommandUnavailableWindows
|
||||||
# error here.
|
# This means that VirtualBox was not found, so we raise this
|
||||||
raise Vagrant::Errors::VirtualBoxNotDetected
|
# error here.
|
||||||
|
raise Vagrant::Errors::VirtualBoxNotDetected
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue