From 30ade2991b6922cce3bb68c543ea2020f1ad0e23 Mon Sep 17 00:00:00 2001 From: sophia Date: Wed, 8 Apr 2020 15:13:15 -0400 Subject: [PATCH] Emit warning message if using mfsymlink --- .../linux/cap/mount_smb_shared_folder.rb | 13 +++++++ templates/locales/en.yml | 11 ++++++ .../linux/cap/mount_smb_shared_folder.rb | 34 ++++++++++++++++--- 3 files changed, 54 insertions(+), 4 deletions(-) diff --git a/plugins/guests/linux/cap/mount_smb_shared_folder.rb b/plugins/guests/linux/cap/mount_smb_shared_folder.rb index 0b793d1e3..d97e58116 100644 --- a/plugins/guests/linux/cap/mount_smb_shared_folder.rb +++ b/plugins/guests/linux/cap/mount_smb_shared_folder.rb @@ -1,3 +1,4 @@ +require "fileutils" require "shellwords" require_relative "../../../synced_folders/unix_mount_helpers" @@ -41,6 +42,10 @@ module VagrantPlugins 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 @@ -97,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 diff --git a/templates/locales/en.yml b/templates/locales/en.yml index 4557a54e2..39700ffa1 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -2410,7 +2410,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: |- diff --git a/test/unit/plugins/guests/linux/cap/mount_smb_shared_folder.rb b/test/unit/plugins/guests/linux/cap/mount_smb_shared_folder.rb index f87ba0088..f20bb86bb 100644 --- a/test/unit/plugins/guests/linux/cap/mount_smb_shared_folder.rb +++ b/test/unit/plugins/guests/linux/cap/mount_smb_shared_folder.rb @@ -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,13 +79,13 @@ describe "VagrantPlugins::GuestLinux::Cap::MountSMBSharedFolder" do cap.mount_smb_shared_folder(machine, mount_name, mount_guest_path, folder_options) end - it "it adds mfsymlinks option by default" do + 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 "it does not add mfsymlinks option if env var VAGRANT_DISABLE_SMBMFSYMLINKS exists" do - ENV['VAGRANT_DISABLE_SMBMFSYMLINKS'] = "1" + 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 @@ -139,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