From d2e33768f3f5804111866c358e4e6f8338dfdb13 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 21 Dec 2011 14:45:14 -0800 Subject: [PATCH] CleanMachineFolder action works with VBoxManage --- lib/vagrant/action/vm/clean_machine_folder.rb | 6 +++--- lib/vagrant/driver/virtualbox.rb | 11 +++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/vagrant/action/vm/clean_machine_folder.rb b/lib/vagrant/action/vm/clean_machine_folder.rb index 99c64c837..66c522342 100644 --- a/lib/vagrant/action/vm/clean_machine_folder.rb +++ b/lib/vagrant/action/vm/clean_machine_folder.rb @@ -13,12 +13,12 @@ module Vagrant end def call(env) - clean_machine_folder + clean_machine_folder(env[:vm].driver.read_machine_folder) @app.call(env) end - def clean_machine_folder - folder = File.join(VirtualBox::Global.global.system_properties.default_machine_folder, "*") + def clean_machine_folder(machine_folder) + folder = File.join(machine_folder, "*") # Small safeguard against potentially unwanted rm-rf, since the default # machine folder will typically always be greater than 10 characters long. diff --git a/lib/vagrant/driver/virtualbox.rb b/lib/vagrant/driver/virtualbox.rb index 910f50017..99d86011a 100644 --- a/lib/vagrant/driver/virtualbox.rb +++ b/lib/vagrant/driver/virtualbox.rb @@ -146,6 +146,17 @@ module Vagrant return nil end + # This reads the folder where VirtualBox places it's VMs. + def read_machine_folder + execute("list", "systemproperties").split("\n").each do |line| + if line =~ /^Default machine folder:\s+(.+?)$/ + return $1.to_s + end + end + + nil + end + # This reads the state for the given UUID. The state of the VM # will be returned as a symbol. def read_state