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
|
||||
# re-loaded at a later time.
|
||||
def update_dotfile
|
||||
if parent
|
||||
parent.update_dotfile
|
||||
return
|
||||
end
|
||||
return parent.update_dotfile if parent
|
||||
|
||||
# Generate and save the persisted VM info
|
||||
data = vms.inject({}) do |acc, data|
|
||||
|
@ -317,9 +314,13 @@ module Vagrant
|
|||
acc
|
||||
end
|
||||
|
||||
if data.empty?
|
||||
File.rm(dotfile_path)
|
||||
else
|
||||
File.open(dotfile_path, 'w+') do |f|
|
||||
f.write(data.to_json)
|
||||
end
|
||||
end
|
||||
|
||||
# Also add to the global store
|
||||
# active_list.add(vm)
|
||||
|
|
|
@ -733,6 +733,16 @@ class EnvironmentTest < Test::Unit::TestCase
|
|||
@env.update_dotfile
|
||||
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
|
||||
vms = {
|
||||
:foo => create_vm(false),
|
||||
|
|
Loading…
Reference in New Issue