core: Remove box information from state file after box removal

This commit is contained in:
Fabio Rehm 2013-10-04 21:55:27 -03:00
parent e4b5db829e
commit 1c689d2211
3 changed files with 37 additions and 0 deletions

View File

@ -22,6 +22,7 @@ module Vagrant
autoload :NFS, "vagrant/action/builtin/nfs"
autoload :Provision, "vagrant/action/builtin/provision"
autoload :ProvisionerCleanup, "vagrant/action/builtin/provisioner_cleanup"
autoload :RemoveBoxInfo, "vagrant/action/builtin/remove_box_info"
autoload :SetHostname, "vagrant/action/builtin/set_hostname"
autoload :SSHExec, "vagrant/action/builtin/ssh_exec"
autoload :SSHRun, "vagrant/action/builtin/ssh_run"
@ -51,6 +52,7 @@ module Vagrant
def self.action_box_remove
Builder.new.tap do |b|
b.use Builtin::BoxRemove
b.use Builtin::RemoveBoxInfo
end
end
end

View File

@ -0,0 +1,26 @@
require "log4r"
module Vagrant
module Action
module Builtin
# This middleware will persist some extra information about the base box
class RemoveBoxInfo
def initialize(app, env)
@app = app
@logger = Log4r::Logger.new("vagrant::action::builtin::remove_box_info")
end
def call(env)
box_removed = env[:box_removed]
box_state_file = env[:box_state_file]
# Mark that we removed the box
@logger.info("Removing the box from the state file...")
box_state_file.remove_box(box_removed)
@app.call(env)
end
end
end
end
end

View File

@ -28,6 +28,15 @@ module VagrantPlugins
save!
end
# Remove a box that has been previously downloaded from the state file.
#
# @param [Box] box The box that was removed.
def remove_box(box)
box_key = "#{box.name}-#{box.provider}"
@data["boxes"].delete(box_key)
save!
end
# This saves the state back into the state file.
def save!
@path.open("w+") do |f|