diff --git a/plugins/providers/virtualbox/driver/base.rb b/plugins/providers/virtualbox/driver/base.rb index 769f845e9..a759e16e8 100644 --- a/plugins/providers/virtualbox/driver/base.rb +++ b/plugins/providers/virtualbox/driver/base.rb @@ -266,6 +266,10 @@ module VagrantPlugins def suspend end + # Unshare folders. + def unshare_folders(names) + end + # Verifies that the driver is ready to accept work. # # This should raise a VagrantError if things are not ready. diff --git a/plugins/providers/virtualbox/driver/version_4_0.rb b/plugins/providers/virtualbox/driver/version_4_0.rb index 11e90f391..37edca0c7 100644 --- a/plugins/providers/virtualbox/driver/version_4_0.rb +++ b/plugins/providers/virtualbox/driver/version_4_0.rb @@ -478,6 +478,27 @@ module VagrantPlugins execute("controlvm", @uuid, "savestate") end + def unshare_folders(names) + names.each do |name| + begin + execute( + "sharedfolder", "remove", @uuid, + "--name", name, + "--transient") + + execute( + "setextradata", @uuid, + "VBoxInternal2/SharedFoldersEnableSymlinksCreate/#{name}") + rescue Vagrant::Errors::VBoxManageError => e + if e.extra_data[:stderr].include?("VBOX_E_FILE_ERROR") + # The folder doesn't exist. ignore. + else + raise + end + end + end + end + def verify! # This command sometimes fails if kernel drivers aren't properly loaded # so we just run the command and verify that it succeeded. diff --git a/plugins/providers/virtualbox/driver/version_4_1.rb b/plugins/providers/virtualbox/driver/version_4_1.rb index 1aba3324d..9fb52c12c 100644 --- a/plugins/providers/virtualbox/driver/version_4_1.rb +++ b/plugins/providers/virtualbox/driver/version_4_1.rb @@ -488,6 +488,27 @@ module VagrantPlugins execute("controlvm", @uuid, "savestate") end + def unshare_folders(names) + names.each do |name| + begin + execute( + "sharedfolder", "remove", @uuid, + "--name", name, + "--transient") + + execute( + "setextradata", @uuid, + "VBoxInternal2/SharedFoldersEnableSymlinksCreate/#{name}") + rescue Vagrant::Errors::VBoxManageError => e + if e.extra_data[:stderr].include?("VBOX_E_FILE_ERROR") + # The folder doesn't exist. ignore. + else + raise + end + end + end + end + def verify! # This command sometimes fails if kernel drivers aren't properly loaded # so we just run the command and verify that it succeeded. diff --git a/plugins/providers/virtualbox/driver/version_4_2.rb b/plugins/providers/virtualbox/driver/version_4_2.rb index e602c3b2c..f0c360c32 100644 --- a/plugins/providers/virtualbox/driver/version_4_2.rb +++ b/plugins/providers/virtualbox/driver/version_4_2.rb @@ -512,6 +512,27 @@ module VagrantPlugins execute("controlvm", @uuid, "savestate") end + def unshare_folders(names) + names.each do |name| + begin + execute( + "sharedfolder", "remove", @uuid, + "--name", name, + "--transient") + + execute( + "setextradata", @uuid, + "VBoxInternal2/SharedFoldersEnableSymlinksCreate/#{name}") + rescue Vagrant::Errors::VBoxManageError => e + if e.extra_data[:stderr].include?("VBOX_E_FILE_ERROR") + # The folder doesn't exist. ignore. + else + raise + end + end + end + end + def verify! # This command sometimes fails if kernel drivers aren't properly loaded # so we just run the command and verify that it succeeded. diff --git a/plugins/providers/virtualbox/driver/version_4_3.rb b/plugins/providers/virtualbox/driver/version_4_3.rb index 25a046d85..925ca03d8 100644 --- a/plugins/providers/virtualbox/driver/version_4_3.rb +++ b/plugins/providers/virtualbox/driver/version_4_3.rb @@ -520,6 +520,27 @@ module VagrantPlugins execute("controlvm", @uuid, "savestate") end + def unshare_folders(names) + names.each do |name| + begin + execute( + "sharedfolder", "remove", @uuid, + "--name", name, + "--transient") + + execute( + "setextradata", @uuid, + "VBoxInternal2/SharedFoldersEnableSymlinksCreate/#{name}") + rescue Vagrant::Errors::VBoxManageError => e + if e.extra_data[:stderr].include?("VBOX_E_FILE_ERROR") + # The folder doesn't exist. ignore. + else + raise + end + end + end + end + def verify! # This command sometimes fails if kernel drivers aren't properly loaded # so we just run the command and verify that it succeeded. diff --git a/plugins/providers/virtualbox/synced_folder.rb b/plugins/providers/virtualbox/synced_folder.rb index 1511a74d9..14f9b0b24 100644 --- a/plugins/providers/virtualbox/synced_folder.rb +++ b/plugins/providers/virtualbox/synced_folder.rb @@ -63,6 +63,14 @@ module VagrantPlugins end end + def disable(machine, folders, _opts) + # TODO: unmount. + + # Remove the shared folders from the VM metadata + names = folders.map { |id, _data| os_friendly_id(id) } + driver(machine).unshare_folders(names) + end + def cleanup(machine, opts) driver(machine).clear_shared_folders if machine.id && machine.id != "" end