providers/docker: remove synced folders after docker rm
This commit is contained in:
parent
cd38f891da
commit
3edfe6deaf
|
@ -79,6 +79,14 @@ module VagrantPlugins
|
||||||
"/sbin/initctl emit --no-wait vagrant-mounted MOUNTPOINT=#{expanded_guest_path}")
|
"/sbin/initctl emit --no-wait vagrant-mounted MOUNTPOINT=#{expanded_guest_path}")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.unmount_virtualbox_shared_folder(machine, guestpath, options)
|
||||||
|
result = machine.communicate.sudo(
|
||||||
|
"umount #{guestpath}", error_check: false)
|
||||||
|
if result == 0
|
||||||
|
machine.communicate.sudo("rm -rf #{guestpath}", error_check: false)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -70,6 +70,11 @@ module VagrantPlugins
|
||||||
require_relative "cap/rsync"
|
require_relative "cap/rsync"
|
||||||
Cap::RSync
|
Cap::RSync
|
||||||
end
|
end
|
||||||
|
|
||||||
|
guest_capability("linux", "unmount_virtualbox_shared_folder") do
|
||||||
|
require_relative "cap/mount_virtualbox_shared_folder"
|
||||||
|
Cap::MountVirtualBoxSharedFolder
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -17,28 +17,28 @@ module VagrantPlugins
|
||||||
def call(env)
|
def call(env)
|
||||||
return @app.call(env) if !env[:machine].provider.host_vm?
|
return @app.call(env) if !env[:machine].provider.host_vm?
|
||||||
|
|
||||||
|
# Read our random ID for this instance
|
||||||
|
id_path = env[:machine].data_dir.join("host_machine_sfid")
|
||||||
|
return @app.call(env) if !id_path.file?
|
||||||
|
host_sfid = id_path.read.chomp
|
||||||
|
|
||||||
host_machine = env[:machine].provider.host_vm
|
host_machine = env[:machine].provider.host_vm
|
||||||
|
|
||||||
|
@app.call(env)
|
||||||
|
|
||||||
begin
|
begin
|
||||||
env[:machine].provider.host_vm_lock do
|
env[:machine].provider.host_vm_lock do
|
||||||
setup_synced_folders(host_machine, env)
|
setup_synced_folders(host_machine, host_sfid, env)
|
||||||
end
|
end
|
||||||
rescue Vagrant::Errors::EnvironmentLockedError
|
rescue Vagrant::Errors::EnvironmentLockedError
|
||||||
sleep 1
|
sleep 1
|
||||||
retry
|
retry
|
||||||
end
|
end
|
||||||
|
|
||||||
@app.call(env)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def setup_synced_folders(host_machine, env)
|
def setup_synced_folders(host_machine, host_sfid, env)
|
||||||
# Read our random ID for this instance
|
|
||||||
id_path = env[:machine].data_dir.join("host_machine_sfid")
|
|
||||||
return if !id_path.file?
|
|
||||||
host_sfid = id_path.read.chomp
|
|
||||||
|
|
||||||
to_disable = []
|
to_disable = []
|
||||||
|
|
||||||
# Read the existing folders that are setup
|
# Read the existing folders that are setup
|
||||||
|
|
|
@ -67,7 +67,13 @@ module VagrantPlugins
|
||||||
end
|
end
|
||||||
|
|
||||||
def disable(machine, folders, _opts)
|
def disable(machine, folders, _opts)
|
||||||
# TODO: unmount.
|
if machine.guest.capability?(:unmount_virtualbox_shared_folder)
|
||||||
|
folders.each do |id, data|
|
||||||
|
machine.guest.capability(
|
||||||
|
:unmount_virtualbox_shared_folder,
|
||||||
|
data[:guestpath], data)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Remove the shared folders from the VM metadata
|
# Remove the shared folders from the VM metadata
|
||||||
names = folders.map { |id, _data| os_friendly_id(id) }
|
names = folders.map { |id, _data| os_friendly_id(id) }
|
||||||
|
|
Loading…
Reference in New Issue