diff --git a/plugins/providers/virtualbox/driver/version_5_0.rb b/plugins/providers/virtualbox/driver/version_5_0.rb index 1d6e5ec4f..e8522e7ac 100644 --- a/plugins/providers/virtualbox/driver/version_5_0.rb +++ b/plugins/providers/virtualbox/driver/version_5_0.rb @@ -674,6 +674,8 @@ module VagrantPlugins hostpath] args << "--transient" if folder.key?(:transient) && folder[:transient] + args << "--automount" if folder.key?(:automount) && folder[:automount] + if folder[:SharedFoldersEnableSymlinksCreate] # Enable symlinks on the shared folder execute("setextradata", @uuid, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/#{folder[:name]}", "1", retryable: true) diff --git a/plugins/providers/virtualbox/synced_folder.rb b/plugins/providers/virtualbox/synced_folder.rb index 5b8a9799b..89b006cf2 100644 --- a/plugins/providers/virtualbox/synced_folder.rb +++ b/plugins/providers/virtualbox/synced_folder.rb @@ -124,7 +124,8 @@ module VagrantPlugins name: os_friendly_id(id), hostpath: hostpath.to_s, transient: transient, - SharedFoldersEnableSymlinksCreate: enable_symlink_create + SharedFoldersEnableSymlinksCreate: enable_symlink_create, + automount: !!data[:automount] } 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 index 194306799..1e833afcc 100644 --- a/test/unit/plugins/providers/virtualbox/driver/version_5_0_test.rb +++ b/test/unit/plugins/providers/virtualbox/driver/version_5_0_test.rb @@ -15,6 +15,12 @@ describe VagrantPlugins::ProviderVirtualBox::Driver::Version_5_0 do :transient=>false, :SharedFoldersEnableSymlinksCreate=>true}]} + let(:folders_automount) { [{:name=>"folder", + :hostpath=>"/Users/brian/vagrant-folder", + :transient=>false, + :automount=>true, + :SharedFoldersEnableSymlinksCreate=>true}]} + let(:folders_disabled) { [{:name=>"folder", :hostpath=>"/Users/brian/vagrant-folder", :transient=>false, @@ -32,6 +38,19 @@ describe VagrantPlugins::ProviderVirtualBox::Driver::Version_5_0 do end + it "enables automount if option is 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", "--automount", {:notify=>[:stdout, :stderr]}). + and_return(subprocess_result(exit_code: 0)) + subject.share_folders(folders_automount) + + 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]}). diff --git a/test/unit/plugins/providers/virtualbox/synced_folder_test.rb b/test/unit/plugins/providers/virtualbox/synced_folder_test.rb index 1eb3d77c3..a5b121581 100644 --- a/test/unit/plugins/providers/virtualbox/synced_folder_test.rb +++ b/test/unit/plugins/providers/virtualbox/synced_folder_test.rb @@ -43,6 +43,7 @@ describe VagrantPlugins::ProviderVirtualBox::SyncedFolder do {:SharedFoldersEnableSymlinksCreate=>true, :guestpath=>"/folder", :hostpath=>"/Users/brian/vagrant-folder", + :automount=>false, :disabled=>false, :__vagrantfile=>true}} } @@ -50,12 +51,23 @@ describe VagrantPlugins::ProviderVirtualBox::SyncedFolder do {:SharedFoldersEnableSymlinksCreate=>false, :guestpath=>"/folder", :hostpath=>"/Users/brian/vagrant-folder", + :automount=>false, :disabled=>false, :__vagrantfile=>true}} } + + let(:folders_automount) { {"/folder"=> + {:SharedFoldersEnableSymlinksCreate=>true, + :guestpath=>"/folder", + :hostpath=>"/Users/brian/vagrant-folder", + :disabled=>false, + :automount=>true, + :__vagrantfile=>true}} } + let(:folders_nosymvar) { {"/folder"=> {:guestpath=>"/folder", :hostpath=>"/Users/brian/vagrant-folder", + :automount=>false, :disabled=>false, :__vagrantfile=>true}} } @@ -66,28 +78,33 @@ describe VagrantPlugins::ProviderVirtualBox::SyncedFolder do end 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}]) + expect(driver).to receive(:share_folders).with([{:name=>"folder", :hostpath=>"/Users/brian/vagrant-folder", :transient=>false, :automount=>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}]) + expect(driver).to receive(:share_folders).with([{:name=>"folder", :hostpath=>"/Users/brian/vagrant-folder", :transient=>false, :automount=>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}]) + expect(driver).to receive(:share_folders).with([{:name=>"folder", :hostpath=>"/Users/brian/vagrant-folder", :transient=>false, :automount=>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}]) + expect(driver).to receive(:share_folders).with([{:name=>"folder", :hostpath=>"/Users/brian/vagrant-folder", :transient=>false, :automount=>false, :SharedFoldersEnableSymlinksCreate=>true}]) subject.prepare(machine, folders, nil) end + + it "should prepare and share the folders with automount enabled" do + expect(driver).to receive(:share_folders).with([{:name=>"folder", :hostpath=>"/Users/brian/vagrant-folder", :transient=>false, :SharedFoldersEnableSymlinksCreate=>true, :automount=>true}]) + subject.prepare(machine, folders_automount, nil) + end end describe "#os_friendly_id" do diff --git a/website/source/docs/synced-folders/virtualbox.html.md b/website/source/docs/synced-folders/virtualbox.html.md index 86f9b8beb..8cef10488 100644 --- a/website/source/docs/synced-folders/virtualbox.html.md +++ b/website/source/docs/synced-folders/virtualbox.html.md @@ -18,6 +18,10 @@ the guest to the host and vice versa. ## Options +* `automount` (boolean) - If true, the `--automount` flag will be used when +using the VirtualBox tools to share the folder with the guest vm. Defaults to false +if not present. + * `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.