From a1af2d920f704c447046543e43688d73b676dcc6 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 27 Apr 2014 16:35:54 -0700 Subject: [PATCH] core: MachineIndex entry invalid if machine with name not in Vagrantfile --- lib/vagrant/machine_index.rb | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/vagrant/machine_index.rb b/lib/vagrant/machine_index.rb index bbe99f0d7..07bf7162c 100644 --- a/lib/vagrant/machine_index.rb +++ b/lib/vagrant/machine_index.rb @@ -419,15 +419,30 @@ module Vagrant return false if !vagrantfile_path return false if !vagrantfile_path.directory? + # Create an environment so we can determine the active # machines... + found = false env = vagrant_env(home_path) env.active_machines.each do |name, provider| - return true if name.to_s == self.name.to_s && + if name.to_s == self.name.to_s && provider.to_s == self.provider.to_s + found = true + break + end end - false + # If an active machine of the same name/provider was not + # found, it is already false. + return false if !found + + # If the environment doesn't contain the machine with this + # name, then it is also false. At some point, we can remove + # this limitation if we support destroying machines where + # the Vagrantfile is moved. + return false if !env.machine_names.find { |n| n == self.name.to_sym } + + true end # Creates a {Vagrant::Environment} for this entry.