mirror of
https://github.com/vagrant-libvirt/vagrant-libvirt.git
synced 2025-02-25 18:55:27 -06:00
Ensure state is fully removed for destroy (#1288)
Completely remove state after a destroy, and ensure removal of a non-existing domain also scrubs the machine folder clean. Closes: #1132
This commit is contained in:
@@ -179,6 +179,7 @@ module VagrantPlugins
|
||||
# Try to remove stale volumes anyway
|
||||
b2.use SetNameOfDomain
|
||||
b2.use RemoveStaleVolume if env[:machine].config.vm.box
|
||||
b2.use CleanMachineFolder, quiet: true
|
||||
b2.use MessageNotCreated unless env[:result]
|
||||
|
||||
next
|
||||
@@ -191,6 +192,7 @@ module VagrantPlugins
|
||||
b3.use PruneNFSExports
|
||||
b3.use DestroyDomain
|
||||
b3.use DestroyNetworks
|
||||
b3.use CleanMachineFolder
|
||||
else
|
||||
b3.use MessageWillNotDestroy
|
||||
end
|
||||
@@ -324,6 +326,7 @@ module VagrantPlugins
|
||||
autoload :CreateDomainVolume, action_root.join('create_domain_volume')
|
||||
autoload :CreateNetworkInterfaces, action_root.join('create_network_interfaces')
|
||||
autoload :CreateNetworks, action_root.join('create_networks')
|
||||
autoload :CleanMachineFolder, action_root.join('clean_machine_folder')
|
||||
autoload :DestroyDomain, action_root.join('destroy_domain')
|
||||
autoload :DestroyNetworks, action_root.join('destroy_networks')
|
||||
autoload :ForwardPorts, action_root.join('forward_ports')
|
||||
|
||||
28
lib/vagrant-libvirt/action/clean_machine_folder.rb
Normal file
28
lib/vagrant-libvirt/action/clean_machine_folder.rb
Normal file
@@ -0,0 +1,28 @@
|
||||
require 'log4r'
|
||||
|
||||
module VagrantPlugins
|
||||
module ProviderLibvirt
|
||||
module Action
|
||||
class CleanMachineFolder
|
||||
|
||||
def initialize(app, env, options=nil)
|
||||
@logger = Log4r::Logger.new('vagrant_libvirt::action::create_domain')
|
||||
@app = app
|
||||
@ui = env[:ui]
|
||||
@quiet = (options || {}).fetch(:quiet, false)
|
||||
end
|
||||
|
||||
def call(env)
|
||||
machine_folder = env[:machine].data_dir
|
||||
|
||||
@ui.info("Deleting the machine folder") unless @quiet
|
||||
|
||||
@logger.debug("Recursively removing: #{machine_folder}")
|
||||
FileUtils.rm_rf(machine_folder, :secure => true)
|
||||
|
||||
@app.call(env)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user