Introduce flag for SharedFoldersEnableSymlinksCreate
Prior to this commit, the virtualbox synced folder option `SharedFoldersEnableSymlinksCreate` was always enabled. This commit introduces a config option and an environment variable which allows users to configure the option globally or per synced_folder in their Vagrantfile.
This commit is contained in:
parent
885d66e9c3
commit
b16ca2e384
|
@ -584,8 +584,10 @@ module VagrantPlugins
|
||||||
folder[:hostpath]]
|
folder[:hostpath]]
|
||||||
args << "--transient" if folder.key?(:transient) && folder[:transient]
|
args << "--transient" if folder.key?(:transient) && folder[:transient]
|
||||||
|
|
||||||
# Enable symlinks on the shared folder
|
if folder[:SharedFoldersEnableSymlinksCreate]
|
||||||
execute("setextradata", @uuid, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/#{folder[:name]}", "1")
|
# Enable symlinks on the shared folder
|
||||||
|
execute("setextradata", @uuid, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/#{folder[:name]}", "1")
|
||||||
|
end
|
||||||
|
|
||||||
# Add the shared folder
|
# Add the shared folder
|
||||||
execute("sharedfolder", "add", @uuid, *args)
|
execute("sharedfolder", "add", @uuid, *args)
|
||||||
|
|
|
@ -517,8 +517,10 @@ module VagrantPlugins
|
||||||
folder[:hostpath]]
|
folder[:hostpath]]
|
||||||
args << "--transient" if folder.key?(:transient) && folder[:transient]
|
args << "--transient" if folder.key?(:transient) && folder[:transient]
|
||||||
|
|
||||||
# Enable symlinks on the shared folder
|
if folder[:SharedFoldersEnableSymlinksCreate]
|
||||||
execute("setextradata", @uuid, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/#{folder[:name]}", "1")
|
# Enable symlinks on the shared folder
|
||||||
|
execute("setextradata", @uuid, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/#{folder[:name]}", "1")
|
||||||
|
end
|
||||||
|
|
||||||
# Add the shared folder
|
# Add the shared folder
|
||||||
execute("sharedfolder", "add", @uuid, *args)
|
execute("sharedfolder", "add", @uuid, *args)
|
||||||
|
|
|
@ -639,8 +639,10 @@ module VagrantPlugins
|
||||||
hostpath]
|
hostpath]
|
||||||
args << "--transient" if folder.key?(:transient) && folder[:transient]
|
args << "--transient" if folder.key?(:transient) && folder[:transient]
|
||||||
|
|
||||||
# Enable symlinks on the shared folder
|
if folder[:SharedFoldersEnableSymlinksCreate]
|
||||||
execute("setextradata", @uuid, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/#{folder[:name]}", "1")
|
# Enable symlinks on the shared folder
|
||||||
|
execute("setextradata", @uuid, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/#{folder[:name]}", "1")
|
||||||
|
end
|
||||||
|
|
||||||
# Add the shared folder
|
# Add the shared folder
|
||||||
execute("sharedfolder", "add", @uuid, *args)
|
execute("sharedfolder", "add", @uuid, *args)
|
||||||
|
|
|
@ -673,8 +673,10 @@ module VagrantPlugins
|
||||||
hostpath]
|
hostpath]
|
||||||
args << "--transient" if folder.key?(:transient) && folder[:transient]
|
args << "--transient" if folder.key?(:transient) && folder[:transient]
|
||||||
|
|
||||||
# Enable symlinks on the shared folder
|
if folder[:SharedFoldersEnableSymlinksCreate]
|
||||||
execute("setextradata", @uuid, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/#{folder[:name]}", "1", retryable: true)
|
# Enable symlinks on the shared folder
|
||||||
|
execute("setextradata", @uuid, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/#{folder[:name]}", "1", retryable: true)
|
||||||
|
end
|
||||||
|
|
||||||
# Add the shared folder
|
# Add the shared folder
|
||||||
execute("sharedfolder", "add", @uuid, *args, retryable: true)
|
execute("sharedfolder", "add", @uuid, *args, retryable: true)
|
||||||
|
|
|
@ -103,12 +103,23 @@ module VagrantPlugins
|
||||||
hostpath = Vagrant::Util::Platform.cygwin_windows_path(hostpath)
|
hostpath = Vagrant::Util::Platform.cygwin_windows_path(hostpath)
|
||||||
end
|
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
|
# Only setup the shared folders that match our transient level
|
||||||
if (!!data[:transient]) == transient
|
if (!!data[:transient]) == transient
|
||||||
defs << {
|
defs << {
|
||||||
name: os_friendly_id(id),
|
name: os_friendly_id(id),
|
||||||
hostpath: hostpath.to_s,
|
hostpath: hostpath.to_s,
|
||||||
transient: transient,
|
transient: transient,
|
||||||
|
SharedFoldersEnableSymlinksCreate: sharefoldersenablesymlinkscreate
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -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
|
|
@ -5,6 +5,7 @@ require Vagrant.source_root.join("plugins/providers/virtualbox/config")
|
||||||
require Vagrant.source_root.join("plugins/providers/virtualbox/synced_folder")
|
require Vagrant.source_root.join("plugins/providers/virtualbox/synced_folder")
|
||||||
|
|
||||||
describe VagrantPlugins::ProviderVirtualBox::SyncedFolder do
|
describe VagrantPlugins::ProviderVirtualBox::SyncedFolder do
|
||||||
|
include_context "unit"
|
||||||
let(:machine) do
|
let(:machine) do
|
||||||
double("machine").tap do |m|
|
double("machine").tap do |m|
|
||||||
allow(m).to receive(:provider_config).and_return(VagrantPlugins::ProviderVirtualBox::Config.new)
|
allow(m).to receive(:provider_config).and_return(VagrantPlugins::ProviderVirtualBox::Config.new)
|
||||||
|
@ -37,12 +38,54 @@ describe VagrantPlugins::ProviderVirtualBox::SyncedFolder do
|
||||||
|
|
||||||
describe "prepare" do
|
describe "prepare" do
|
||||||
let(:driver) { double("driver") }
|
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
|
before do
|
||||||
allow(machine).to receive(:driver).and_return(driver)
|
allow(machine).to receive(:provider).and_return(provider)
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
describe "os_friendly_id" do
|
describe "os_friendly_id" do
|
||||||
|
|
|
@ -211,3 +211,10 @@ but just a filename.
|
||||||
This environmental variable is commonly used in scripting environments
|
This environmental variable is commonly used in scripting environments
|
||||||
where a single folder may contain multiple Vagrantfiles representing
|
where a single folder may contain multiple Vagrantfiles representing
|
||||||
different configurations.
|
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.
|
||||||
|
|
|
@ -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
|
folders use the VirtualBox shared folder system to sync file changes from
|
||||||
the guest to the host and vice versa.
|
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
|
## Caveats
|
||||||
|
|
||||||
There is a [VirtualBox bug][sendfile bug] related to `sendfile` which can result
|
There is a [VirtualBox bug][sendfile bug] related to `sendfile` which can result
|
||||||
|
|
Loading…
Reference in New Issue