Merge pull request #11503 from soapy1/smb-symlinks

Smb symlinks
This commit is contained in:
Sophia Castellarin 2020-04-20 12:35:38 -04:00 committed by GitHub
commit bc4368f739
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 69 additions and 1 deletions

View File

@ -1,3 +1,4 @@
require "fileutils"
require "shellwords"
require_relative "../../../synced_folders/unix_mount_helpers"
@ -34,10 +35,17 @@ module VagrantPlugins
mnt_opts << "credentials=/etc/smb_creds_#{name}"
mnt_opts << "uid=#{mount_uid}"
mnt_opts << "gid=#{mount_gid}"
if !ENV['VAGRANT_DISABLE_SMBMFSYMLINKS']
mnt_opts << "mfsymlinks"
end
mnt_opts = merge_mount_options(mnt_opts, options[:mount_options] || [])
mount_options = "-o #{mnt_opts.join(",")}"
if mount_options.include?("mfsymlinks")
display_mfsymlinks_warning(machine.env)
end
mount_command = "mount -t cifs #{mount_options} #{mount_device} #{expanded_guest_path}"
# Create the guest path if it doesn't exist
@ -94,6 +102,14 @@ SCRIPT
[key, value].compact.join("=")
end
end
def self.display_mfsymlinks_warning(env)
d_file = env.data_dir.join("mfsymlinks_warning")
if !d_file.exist?
FileUtils.touch(d_file.to_path)
env.ui.warn(I18n.t("vagrant.actions.vm.smb.mfsymlink_warning"))
end
end
end
end
end

View File

@ -2424,7 +2424,18 @@ en:
For more information see:
RFC5661: https://tools.ietf.org/html/rfc5661#section-2.9.1
RFC7530: https://tools.ietf.org/html/rfc7530#section-3.1
smb:
mfsymlink_warning: |-
Vagrant is currently configured to mount SMB folders with the
`mfsymlink` option enabled. This is equivalent to adding the
following to your Vagrantfile:
config.vm.synced_folder '/host/path', '/guest/path', type: "smb", mount_options: ['mfsymlink']
This option may be globally disabled with an environment variable:
VAGRANT_DISABLE_SMBMFSYMLINKS=1
provision:
beginning: "Running provisioner: %{provisioner}..."
disabled_by_config: |-

View File

@ -8,7 +8,7 @@ describe "VagrantPlugins::GuestLinux::Cap::MountSMBSharedFolder" do
end
let(:machine) { double("machine", env: env) }
let(:env) { double("env", host: host) }
let(:env) { double("env", host: host, ui: double("ui"), data_dir: double("data_dir")) }
let(:host) { double("host") }
let(:guest) { double("guest") }
let(:comm) { VagrantTests::DummyCommunicator::Communicator.new(machine) }
@ -44,6 +44,9 @@ describe "VagrantPlugins::GuestLinux::Cap::MountSMBSharedFolder" do
allow(comm).to receive(:execute).with(any_args)
allow(machine).to receive(:guest).and_return(guest)
allow(guest).to receive(:capability).with(:shell_expand_guest_path, mount_guest_path).and_return(mount_guest_path)
allow(ENV).to receive(:[]).with("VAGRANT_DISABLE_SMBMFSYMLINKS").and_return(false)
allow(ENV).to receive(:[]).with("GEM_SKIP").and_return(false)
allow(cap).to receive(:display_mfsymlinks_warning)
end
it "generates the expected default mount command" do
@ -76,6 +79,17 @@ describe "VagrantPlugins::GuestLinux::Cap::MountSMBSharedFolder" do
cap.mount_smb_shared_folder(machine, mount_name, mount_guest_path, folder_options)
end
it "adds mfsymlinks option by default" do
expect(comm).to receive(:sudo).with(/mfsymlinks/, any_args)
cap.mount_smb_shared_folder(machine, mount_name, mount_guest_path, folder_options)
end
it "does not add mfsymlinks option if env var VAGRANT_DISABLE_SMBMFSYMLINKS exists" do
expect(ENV).to receive(:[]).with("VAGRANT_DISABLE_SMBMFSYMLINKS").and_return(true)
expect(comm).not_to receive(:sudo).with(/mfsymlinks/, any_args)
cap.mount_smb_shared_folder(machine, mount_name, mount_guest_path, folder_options)
end
context "with custom mount options" do
let(:folder_options) do
{
@ -128,4 +142,27 @@ describe "VagrantPlugins::GuestLinux::Cap::MountSMBSharedFolder" do
end
end
end
describe ".display_mfsymlinks_warning" do
let(:gate_file){ double("gate") }
before do
allow(env.data_dir).to receive(:join).and_return(gate_file)
allow(gate_file).to receive(:exist?).and_return(false)
allow(gate_file).to receive(:to_path).and_return("PATH")
allow(FileUtils).to receive(:touch)
end
it "should output warning message" do
expect(env.ui).to receive(:warn).with(/VAGRANT_DISABLE_SMBMFSYMLINKS=1/)
cap.display_mfsymlinks_warning(env)
end
it "should not output warning message if gate file exists" do
allow(gate_file).to receive(:exist?).and_return(true)
expect(env.ui).not_to receive(:warn)
cap.display_mfsymlinks_warning(env)
end
end
end

View File

@ -143,6 +143,10 @@ do not wish to completely disable this feature for all VirtualBox guests.
More information on the option can be read in the [VirtualBox synced folders docs page.](/docs/synced-folders/virtualbox.html#sharedfoldersenablesymlinkscreate)
## `VAGRANT_DISABLE_SMBMFSYMLINKS`
If set, this will disable the `mfsymlinks` option for mounting SMB filesystems. If not set, then the `mfsymlinks` option will be enabled by default. This option can be overriden on a pre-folder basis with your Vagrantfile by setting `mount_options: ['mfsymlinks']`.
## `VAGRANT_DOTFILE_PATH`
`VAGRANT_DOTFILE_PATH` can be set to change the directory where Vagrant stores