From 3edfe6deaf8174503dbc10028b2021e8556fac37 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 16 Apr 2014 14:59:23 -0700 Subject: [PATCH] providers/docker: remove synced folders after docker rm --- .../cap/mount_virtualbox_shared_folder.rb | 8 ++++++++ plugins/guests/linux/plugin.rb | 5 +++++ .../host_machine_sync_folders_disable.rb | 18 +++++++++--------- plugins/providers/virtualbox/synced_folder.rb | 8 +++++++- 4 files changed, 29 insertions(+), 10 deletions(-) diff --git a/plugins/guests/linux/cap/mount_virtualbox_shared_folder.rb b/plugins/guests/linux/cap/mount_virtualbox_shared_folder.rb index 571fc5b8a..f2882d82d 100644 --- a/plugins/guests/linux/cap/mount_virtualbox_shared_folder.rb +++ b/plugins/guests/linux/cap/mount_virtualbox_shared_folder.rb @@ -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 diff --git a/plugins/guests/linux/plugin.rb b/plugins/guests/linux/plugin.rb index 8aa903edd..4b8810769 100644 --- a/plugins/guests/linux/plugin.rb +++ b/plugins/guests/linux/plugin.rb @@ -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 diff --git a/plugins/providers/docker/action/host_machine_sync_folders_disable.rb b/plugins/providers/docker/action/host_machine_sync_folders_disable.rb index 944889b3f..b7912d93a 100644 --- a/plugins/providers/docker/action/host_machine_sync_folders_disable.rb +++ b/plugins/providers/docker/action/host_machine_sync_folders_disable.rb @@ -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 diff --git a/plugins/providers/virtualbox/synced_folder.rb b/plugins/providers/virtualbox/synced_folder.rb index 351b5adfe..2e2a33b2a 100644 --- a/plugins/providers/virtualbox/synced_folder.rb +++ b/plugins/providers/virtualbox/synced_folder.rb @@ -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) }