providers/docker: remove synced folders after docker rm

This commit is contained in:
Mitchell Hashimoto 2014-04-16 14:59:23 -07:00
parent cd38f891da
commit 3edfe6deaf
4 changed files with 29 additions and 10 deletions

View File

@ -79,6 +79,14 @@ module VagrantPlugins
"/sbin/initctl emit --no-wait vagrant-mounted MOUNTPOINT=#{expanded_guest_path}")
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

View File

@ -70,6 +70,11 @@ module VagrantPlugins
require_relative "cap/rsync"
Cap::RSync
end
guest_capability("linux", "unmount_virtualbox_shared_folder") do
require_relative "cap/mount_virtualbox_shared_folder"
Cap::MountVirtualBoxSharedFolder
end
end
end
end

View File

@ -17,28 +17,28 @@ module VagrantPlugins
def call(env)
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
@app.call(env)
begin
env[:machine].provider.host_vm_lock do
setup_synced_folders(host_machine, env)
setup_synced_folders(host_machine, host_sfid, env)
end
rescue Vagrant::Errors::EnvironmentLockedError
sleep 1
retry
end
@app.call(env)
end
protected
def setup_synced_folders(host_machine, 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
def setup_synced_folders(host_machine, host_sfid, env)
to_disable = []
# Read the existing folders that are setup

View File

@ -67,7 +67,13 @@ module VagrantPlugins
end
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
names = folders.map { |id, _data| os_friendly_id(id) }