Skip to content

Commit

Permalink
Merge pull request #234 from legal90/f-cache-version
Browse files Browse the repository at this point in the history
driver/meta: cache Parallels Desktop version
  • Loading branch information
legal90 committed Nov 23, 2015
2 parents 827dfdf + 5811395 commit a31a9d3
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions lib/vagrant-parallels/driver/meta.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ class VMNotFound < StandardError; end
# We use forwardable to do all our driver forwarding
extend Forwardable

# We cache the Parallels Desktop version here once we have one,
# since during the execution of Vagrant, it likely doesn't change.
@@version = nil
@@version_lock = Mutex.new

# The UUID of the virtual machine we represent
attr_reader :uuid

Expand All @@ -29,12 +34,14 @@ def initialize(uuid=nil)

# Read and assign the version of Parallels Desktop we know which
# specific driver to instantiate.
@version = read_version || ''

@@version_lock.synchronize do
@@version = read_version
end

# Instantiate the proper version driver for Parallels Desktop
@logger.debug("Finding driver for Parallels Desktop version: #{@version}")
@logger.debug("Finding driver for Parallels Desktop version: #{@@version}")

major_ver = @version.split('.').first.to_i
major_ver = @@version.split('.').first.to_i
driver_klass =
case major_ver
when 1..7 then raise Errors::ParallelsUnsupportedVersion
Expand All @@ -55,6 +62,7 @@ def initialize(uuid=nil)

@logger.info("Using Parallels driver: #{driver_klass}")
@driver = driver_klass.new(@uuid)
@version = @@version

if @uuid
# Verify the VM exists, and if it doesn't, then don't worry
Expand Down

0 comments on commit a31a9d3

Please # to comment.