diff --git a/lib/vagrant/machine_index.rb b/lib/vagrant/machine_index.rb index c9ab6d63c..f8ed442ba 100644 --- a/lib/vagrant/machine_index.rb +++ b/lib/vagrant/machine_index.rb @@ -379,6 +379,17 @@ module Vagrant @extra_data = raw["extra_data"] || {} end + # Creates a {Vagrant::Environment} for this entry. + # + # @return [Vagrant::Environment] + def vagrant_env(home_path, **opts) + Environment.new({ + cwd: @vagrantfile_path, + home_path: home_path, + vagrantfile_name: @vagrantfile_name, + }.merge(opts)) + end + # Converts to the structure used by the JSON def to_json_struct { diff --git a/lib/vagrant/plugin/v2/command.rb b/lib/vagrant/plugin/v2/command.rb index df7256319..423e6259c 100644 --- a/lib/vagrant/plugin/v2/command.rb +++ b/lib/vagrant/plugin/v2/command.rb @@ -135,11 +135,8 @@ module Vagrant # Vagrantfiles often have constants, so people would otherwise # constantly (heh) get "already initialized constant" warnings. machine = Vagrant::Util::SilenceWarnings.silence! do - env = Vagrant::Environment.new( - cwd: entry.vagrantfile_path, - home_path: @env.home_path, - ui_class: @env.ui_class, - ) + env = entry.vagrant_env( + @env.home_path, ui_class: @env.ui_class) env.machine(entry.name.to_sym, entry.provider.to_sym) end diff --git a/plugins/commands/global-status/command.rb b/plugins/commands/global-status/command.rb index c97368db1..94dfd6c63 100644 --- a/plugins/commands/global-status/command.rb +++ b/plugins/commands/global-status/command.rb @@ -100,15 +100,11 @@ module VagrantPlugins # Tests if a entry is invalid and should be pruned def invalid?(entry) - return true if !entry.vagrantfile_path.file? + return true if !entry.vagrantfile_path.directory? # Create an environment so we can determine the active # machines... - env = Vagrant::Environment.new( - cwd: entry.vagrantfile_path.dirname, - home_path: @env.home_path, - ) - + env = entry.vagrant_env(@env.home_path) env.active_machines.each do |name, provider| return false if name.to_s == entry.name.to_s && provider.to_s == entry.provider.to_s diff --git a/test/unit/plugins/commands/global-status/command_test.rb b/test/unit/plugins/commands/global-status/command_test.rb index 1107a3464..ebedcedb6 100644 --- a/test/unit/plugins/commands/global-status/command_test.rb +++ b/test/unit/plugins/commands/global-status/command_test.rb @@ -51,7 +51,7 @@ describe VagrantPlugins::CommandGlobalStatus::Command do entryB_env = isolated_environment entryB_env.vagrantfile("") entryB = new_entry("B") - entryB.vagrantfile_path = entryB_env.workdir.join("Vagrantfile") + entryB.vagrantfile_path = entryB_env.workdir locked = iso_env.machine_index.set(entryB) iso_env.machine_index.release(locked) @@ -63,7 +63,7 @@ describe VagrantPlugins::CommandGlobalStatus::Command do entryC_machine.id = "foo" entryC = new_entry(entryC_machine.name) entryC.provider = "dummy" - entryC.vagrantfile_path = entryC_env.workdir.join("Vagrantfile") + entryC.vagrantfile_path = entryC_env.workdir locked = iso_env.machine_index.set(entryC) iso_env.machine_index.release(locked)