Use `load` for the Vagrantrc, make sure it is only loaded once

This commit is contained in:
Mitchell Hashimoto 2012-05-06 10:09:33 -07:00
parent 0d6248394c
commit de92f5217c
1 changed files with 8 additions and 5 deletions

View File

@ -1,5 +1,6 @@
require 'pathname'
require 'fileutils' require 'fileutils'
require 'pathname'
require 'set'
require 'log4r' require 'log4r'
require 'rubygems' # This is needed for plugin loading below. require 'rubygems' # This is needed for plugin loading below.
@ -42,6 +43,10 @@ module Vagrant
# The path to the default private key # The path to the default private key
attr_reader :default_private_key_path attr_reader :default_private_key_path
# This is a set of the vagrantrc files already loaded so that they
# are only loaded once.
@@loaded_rc = Set.new
# Initializes a new environment with the given options. The options # Initializes a new environment with the given options. The options
# is a hash where the main available key is `cwd`, which defines where # is a hash where the main available key is `cwd`, which defines where
# the environment represents. There are other options available but # the environment represents. There are other options available but
@ -521,11 +526,9 @@ module Vagrant
# Load the plugins # Load the plugins
rc_path = File.expand_path(ENV["VAGRANT_RC"] || DEFAULT_RC) rc_path = File.expand_path(ENV["VAGRANT_RC"] || DEFAULT_RC)
if File.file?(rc_path) if File.file?(rc_path) && @@loaded_rc.add?(rc_path)
# We use a `require` here instead of a load so the same file will
# only be loaded once.
@logger.debug("Loading RC file: #{rc_path}") @logger.debug("Loading RC file: #{rc_path}")
require rc_path load rc_path
else else
@logger.debug("RC file not found. Not loading: #{rc_path}") @logger.debug("RC file not found. Not loading: #{rc_path}")
end end