From f475df0987d4195b0433273b61109161185c4190 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 5 May 2014 15:44:45 -0700 Subject: [PATCH] providers/virtualbox: don't do transient by default --- CHANGELOG.md | 5 +- .../action/host_machine_sync_folders.rb | 5 ++ plugins/providers/virtualbox/synced_folder.rb | 49 +++++++++++++------ 3 files changed, 39 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 482e3cbe7..8f0778d06 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,9 +2,6 @@ BACKWARDS INCOMPATIBILITIES: - - providers/virtualbox: Shared folders backed by VirtualBox are now - "transient". They will be removed if you reboot outside of Vagrant. - Always use `vagrant reload`. - Deprecated: `halt_timeout` and `halt_check_interval` settings for SmartOS, Solaris, and Solaris11 guests. These will be fully removed in 1.7. A warning will be shown if they're in use in @@ -46,7 +43,7 @@ IMPROVEMENTS: - core: Vagrant locks machine access to one Vagrant process at a time. This will protect against two simultaneous `up` actions happening on the same environment. - - core: Boxes can be compressed with LZMA now as well. + - core: Boxes can be compressed with LZMA now as well. - commands/box/remove: Warns if the box appears to be in use by an environment. Can be forced with `--force`. - commands/destroy: Exit codes changes. 0 means everything succeeded. diff --git a/plugins/providers/docker/action/host_machine_sync_folders.rb b/plugins/providers/docker/action/host_machine_sync_folders.rb index 15bb0c22b..aa6d5ddb3 100644 --- a/plugins/providers/docker/action/host_machine_sync_folders.rb +++ b/plugins/providers/docker/action/host_machine_sync_folders.rb @@ -117,6 +117,11 @@ module VagrantPlugins # Add this synced folder onto the new config if we haven't # already shared it before. if !existing_ids.has_key?(id) + # A bit of a hack for VirtualBox to mount our + # folder as transient. This can be removed once + # the VirtualBox synced folder mechanism is smarter. + data[:virtualbox__transient] = true + new_config.synced_folder( data[:hostpath], data[:guestpath], diff --git a/plugins/providers/virtualbox/synced_folder.rb b/plugins/providers/virtualbox/synced_folder.rb index 2e2a33b2a..0616f46fd 100644 --- a/plugins/providers/virtualbox/synced_folder.rb +++ b/plugins/providers/virtualbox/synced_folder.rb @@ -9,23 +9,12 @@ module VagrantPlugins machine.provider_config.functional_vboxsf end + def prepare(machine, folders, _opts) + share_folders(machine, folders, false) + end + def enable(machine, folders, _opts) - # Export the shared folders to the VM - defs = [] - folders.each do |id, data| - hostpath = data[:hostpath] - if !data[:hostpath_exact] - hostpath = Vagrant::Util::Platform.cygwin_windows_path(hostpath) - end - - defs << { - name: os_friendly_id(id), - hostpath: hostpath.to_s, - transient: true, - } - end - - driver(machine).share_folders(defs) + share_folders(machine, folders, true) # short guestpaths first, so we don't step on ourselves folders = folders.sort_by do |id, data| @@ -94,6 +83,34 @@ module VagrantPlugins def os_friendly_id(id) id.gsub(/[\/]/,'_').sub(/^_/, '') end + + # share_folders sets up the shared folder definitions on the + # VirtualBox VM. + # + # The transient parameter determines if we're FORCING transient + # or not. If this is false, then any shared folders will be + # shared as non-transient unless they've specifically asked for + # transient. + def share_folders(machine, folders, transient) + defs = [] + folders.each do |id, data| + hostpath = data[:hostpath] + if !data[:hostpath_exact] + hostpath = Vagrant::Util::Platform.cygwin_windows_path(hostpath) + end + + # Only setup the shared folders that match our transient level + if (!!data[:transient]) == transient + defs << { + name: os_friendly_id(id), + hostpath: hostpath.to_s, + transient: transient, + } + end + end + + driver(machine).share_folders(defs) + end end end end