Remove the dotfile (.vagrant) if no more active VMs exist
This commit is contained in:
parent
503a9acf89
commit
46e9250f09
|
@ -305,10 +305,7 @@ module Vagrant
|
||||||
# Persists this environment's VM to the dotfile so it can be
|
# Persists this environment's VM to the dotfile so it can be
|
||||||
# re-loaded at a later time.
|
# re-loaded at a later time.
|
||||||
def update_dotfile
|
def update_dotfile
|
||||||
if parent
|
return parent.update_dotfile if parent
|
||||||
parent.update_dotfile
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
# Generate and save the persisted VM info
|
# Generate and save the persisted VM info
|
||||||
data = vms.inject({}) do |acc, data|
|
data = vms.inject({}) do |acc, data|
|
||||||
|
@ -317,9 +314,13 @@ module Vagrant
|
||||||
acc
|
acc
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if data.empty?
|
||||||
|
File.rm(dotfile_path)
|
||||||
|
else
|
||||||
File.open(dotfile_path, 'w+') do |f|
|
File.open(dotfile_path, 'w+') do |f|
|
||||||
f.write(data.to_json)
|
f.write(data.to_json)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Also add to the global store
|
# Also add to the global store
|
||||||
# active_list.add(vm)
|
# active_list.add(vm)
|
||||||
|
|
|
@ -733,6 +733,16 @@ class EnvironmentTest < Test::Unit::TestCase
|
||||||
@env.update_dotfile
|
@env.update_dotfile
|
||||||
end
|
end
|
||||||
|
|
||||||
|
should "remove the dotfile if the data is empty" do
|
||||||
|
vms = {
|
||||||
|
:foo => create_vm(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
@env.stubs(:vms).returns(vms)
|
||||||
|
File.expects(:rm).with(@env.dotfile_path).once
|
||||||
|
@env.update_dotfile
|
||||||
|
end
|
||||||
|
|
||||||
should "write the proper data to dotfile" do
|
should "write the proper data to dotfile" do
|
||||||
vms = {
|
vms = {
|
||||||
:foo => create_vm(false),
|
:foo => create_vm(false),
|
||||||
|
|
Loading…
Reference in New Issue