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:
Darragh Bailey
2021-05-18 18:21:54 +01:00
committed by GitHub
parent 07391048af
commit 878b5ffe61
3 changed files with 79 additions and 0 deletions

View File

@@ -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')

View 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