diff --git a/plugins/providers/virtualbox/driver/version_4_1.rb b/plugins/providers/virtualbox/driver/version_4_1.rb index ac07efd3f..850684bf6 100644 --- a/plugins/providers/virtualbox/driver/version_4_1.rb +++ b/plugins/providers/virtualbox/driver/version_4_1.rb @@ -584,8 +584,10 @@ module VagrantPlugins folder[:hostpath]] args << "--transient" if folder.key?(:transient) && folder[:transient] - # Enable symlinks on the shared folder - execute("setextradata", @uuid, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/#{folder[:name]}", "1") + if folder[:SharedFoldersEnableSymlinksCreate] + # Enable symlinks on the shared folder + execute("setextradata", @uuid, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/#{folder[:name]}", "1") + end # Add the shared folder execute("sharedfolder", "add", @uuid, *args) diff --git a/plugins/providers/virtualbox/driver/version_4_2.rb b/plugins/providers/virtualbox/driver/version_4_2.rb index 2cae69d43..eabd3c78e 100644 --- a/plugins/providers/virtualbox/driver/version_4_2.rb +++ b/plugins/providers/virtualbox/driver/version_4_2.rb @@ -517,8 +517,10 @@ module VagrantPlugins folder[:hostpath]] args << "--transient" if folder.key?(:transient) && folder[:transient] - # Enable symlinks on the shared folder - execute("setextradata", @uuid, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/#{folder[:name]}", "1") + if folder[:SharedFoldersEnableSymlinksCreate] + # Enable symlinks on the shared folder + execute("setextradata", @uuid, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/#{folder[:name]}", "1") + end # Add the shared folder execute("sharedfolder", "add", @uuid, *args) diff --git a/plugins/providers/virtualbox/driver/version_4_3.rb b/plugins/providers/virtualbox/driver/version_4_3.rb index 8a1377055..8e220cb03 100644 --- a/plugins/providers/virtualbox/driver/version_4_3.rb +++ b/plugins/providers/virtualbox/driver/version_4_3.rb @@ -639,8 +639,10 @@ module VagrantPlugins hostpath] args << "--transient" if folder.key?(:transient) && folder[:transient] - # Enable symlinks on the shared folder - execute("setextradata", @uuid, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/#{folder[:name]}", "1") + if folder[:SharedFoldersEnableSymlinksCreate] + # Enable symlinks on the shared folder + execute("setextradata", @uuid, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/#{folder[:name]}", "1") + end # Add the shared folder execute("sharedfolder", "add", @uuid, *args) diff --git a/plugins/providers/virtualbox/driver/version_5_0.rb b/plugins/providers/virtualbox/driver/version_5_0.rb index 3efb31f38..80c0d607e 100644 --- a/plugins/providers/virtualbox/driver/version_5_0.rb +++ b/plugins/providers/virtualbox/driver/version_5_0.rb @@ -673,8 +673,10 @@ module VagrantPlugins hostpath] args << "--transient" if folder.key?(:transient) && folder[:transient] - # Enable symlinks on the shared folder - execute("setextradata", @uuid, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/#{folder[:name]}", "1", retryable: true) + if folder[:SharedFoldersEnableSymlinksCreate] + # Enable symlinks on the shared folder + execute("setextradata", @uuid, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/#{folder[:name]}", "1", retryable: true) + end # Add the shared folder execute("sharedfolder", "add", @uuid, *args, retryable: true) diff --git a/plugins/providers/virtualbox/synced_folder.rb b/plugins/providers/virtualbox/synced_folder.rb index a3eff1f29..695b41ee5 100644 --- a/plugins/providers/virtualbox/synced_folder.rb +++ b/plugins/providers/virtualbox/synced_folder.rb @@ -103,12 +103,23 @@ module VagrantPlugins hostpath = Vagrant::Util::Platform.cygwin_windows_path(hostpath) end + sharefoldersenablesymlinkscreate = true + + if ENV['VAGRANT_DISABLE_VBOXSYMLINKCREATE'] + sharefoldersenablesymlinkscreate = false + end + + unless data[:SharedFoldersEnableSymlinksCreate].nil? + sharefoldersenablesymlinkscreate = data[:SharedFoldersEnableSymlinksCreate] + 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, + SharedFoldersEnableSymlinksCreate: sharefoldersenablesymlinkscreate } end end diff --git a/test/unit/plugins/providers/virtualbox/driver/version_5_0_test.rb b/test/unit/plugins/providers/virtualbox/driver/version_5_0_test.rb new file mode 100644 index 000000000..49e6c0bc7 --- /dev/null +++ b/test/unit/plugins/providers/virtualbox/driver/version_5_0_test.rb @@ -0,0 +1,43 @@ +require_relative "../base" + +describe VagrantPlugins::ProviderVirtualBox::Driver::Version_5_0 do + include_context "virtualbox" + + let(:vbox_version) { "5.0.0" } + + subject { VagrantPlugins::ProviderVirtualBox::Driver::Meta.new(uuid) } + + it_behaves_like "a version 4.x virtualbox driver" + + describe "#shared_folders" do + let(:folders) { [{:name=>"folder", + :hostpath=>"/Users/brian/vagrant-folder", + :transient=>false, + :SharedFoldersEnableSymlinksCreate=>true}]} + + let(:folders_disabled) { [{:name=>"folder", + :hostpath=>"/Users/brian/vagrant-folder", + :transient=>false, + :SharedFoldersEnableSymlinksCreate=>false}]} + + it "enables SharedFoldersEnableSymlinksCreate if true" do + expect(subprocess).to receive(:execute). + with("VBoxManage", "setextradata", anything, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/folder", "1", {:notify=>[:stdout, :stderr]}). + and_return(subprocess_result(exit_code: 0)) + + expect(subprocess).to receive(:execute). + with("VBoxManage", "sharedfolder", "add", anything, "--name", "folder", "--hostpath", "/Users/brian/vagrant-folder", {:notify=>[:stdout, :stderr]}). + and_return(subprocess_result(exit_code: 0)) + subject.share_folders(folders) + + end + + it "disables SharedFoldersEnableSymlinksCreate if false" do + expect(subprocess).to receive(:execute). + with("VBoxManage", "sharedfolder", "add", anything, "--name", "folder", "--hostpath", "/Users/brian/vagrant-folder", {:notify=>[:stdout, :stderr]}). + and_return(subprocess_result(exit_code: 0)) + subject.share_folders(folders_disabled) + + end + end +end diff --git a/test/unit/plugins/providers/virtualbox/synced_folder_test.rb b/test/unit/plugins/providers/virtualbox/synced_folder_test.rb index 0e898991c..683fd9dee 100644 --- a/test/unit/plugins/providers/virtualbox/synced_folder_test.rb +++ b/test/unit/plugins/providers/virtualbox/synced_folder_test.rb @@ -5,6 +5,7 @@ require Vagrant.source_root.join("plugins/providers/virtualbox/config") require Vagrant.source_root.join("plugins/providers/virtualbox/synced_folder") describe VagrantPlugins::ProviderVirtualBox::SyncedFolder do + include_context "unit" let(:machine) do double("machine").tap do |m| allow(m).to receive(:provider_config).and_return(VagrantPlugins::ProviderVirtualBox::Config.new) @@ -37,12 +38,54 @@ describe VagrantPlugins::ProviderVirtualBox::SyncedFolder do describe "prepare" do let(:driver) { double("driver") } + let(:provider) { double("driver", driver: driver) } + let(:folders) { {"/folder"=> + {:SharedFoldersEnableSymlinksCreate=>true, + :guestpath=>"/folder", + :hostpath=>"/Users/brian/vagrant-folder", + :disabled=>false, + :__vagrantfile=>true}} } + + let(:folders_disabled) { {"/folder"=> + {:SharedFoldersEnableSymlinksCreate=>false, + :guestpath=>"/folder", + :hostpath=>"/Users/brian/vagrant-folder", + :disabled=>false, + :__vagrantfile=>true}} } + + let(:folders_nosymvar) { {"/folder"=> + {:guestpath=>"/folder", + :hostpath=>"/Users/brian/vagrant-folder", + :disabled=>false, + :__vagrantfile=>true}} } before do - allow(machine).to receive(:driver).and_return(driver) + allow(machine).to receive(:provider).and_return(provider) end - it "should share the folders" + it "should prepare and share the folders" do + expect(driver).to receive(:share_folders).with([{:name=>"folder", :hostpath=>"/Users/brian/vagrant-folder", :transient=>false, :SharedFoldersEnableSymlinksCreate=>true}]) + subject.prepare(machine, folders, nil) + end + + it "should prepare and share the folders without symlinks enabled" do + expect(driver).to receive(:share_folders).with([{:name=>"folder", :hostpath=>"/Users/brian/vagrant-folder", :transient=>false, :SharedFoldersEnableSymlinksCreate=>false}]) + subject.prepare(machine, folders_disabled, nil) + end + + it "should prepare and share the folders without symlinks enabled with env var set" do + stub_env('VAGRANT_DISABLE_VBOXSYMLINKCREATE'=>'1') + + expect(driver).to receive(:share_folders).with([{:name=>"folder", :hostpath=>"/Users/brian/vagrant-folder", :transient=>false, :SharedFoldersEnableSymlinksCreate=>false}]) + subject.prepare(machine, folders_nosymvar, nil) + end + + it "should prepare and share the folders and override symlink setting" do + stub_env('VAGRANT_DISABLE_VBOXSYMLINKCREATE'=>'1') + + expect(driver).to receive(:share_folders).with([{:name=>"folder", :hostpath=>"/Users/brian/vagrant-folder", :transient=>false, :SharedFoldersEnableSymlinksCreate=>true}]) + subject.prepare(machine, folders, nil) + end end describe "os_friendly_id" do diff --git a/website/source/docs/other/environmental-variables.html.md b/website/source/docs/other/environmental-variables.html.md index cec3e600f..c28df34d3 100644 --- a/website/source/docs/other/environmental-variables.html.md +++ b/website/source/docs/other/environmental-variables.html.md @@ -211,3 +211,10 @@ but just a filename. This environmental variable is commonly used in scripting environments where a single folder may contain multiple Vagrantfiles representing different configurations. + +## `VAGRANT_DISABLE_VBOXSYMLINKCREATE` + +If set, this will disable the ability to create symlinks with all virtualbox +shared folders. Defaults to true if the option is not set. This can be overriden +on a per-folder basis within your Vagrantfile config by settings the +`SharedFoldersEnableSymlinksCreate` option to true. diff --git a/website/source/docs/synced-folders/virtualbox.html.md b/website/source/docs/synced-folders/virtualbox.html.md index efb9a5e4b..bbad47bdf 100644 --- a/website/source/docs/synced-folders/virtualbox.html.md +++ b/website/source/docs/synced-folders/virtualbox.html.md @@ -16,6 +16,12 @@ VirtualBox shared folders are the default synced folder type. These synced folders use the VirtualBox shared folder system to sync file changes from the guest to the host and vice versa. +## Options + +* `SharedFoldersEnableSymlinksCreate` (boolean) - If false, will disable the +ability to create symlinks with the given virtualbox shared folder. Defaults to +true if the option is not present. + ## Caveats There is a [VirtualBox bug][sendfile bug] related to `sendfile` which can result