diff --git a/plugins/guests/linux/cap/mount_virtualbox_shared_folder.rb b/plugins/guests/linux/cap/mount_virtualbox_shared_folder.rb index 2c19ee1c8..d24877242 100644 --- a/plugins/guests/linux/cap/mount_virtualbox_shared_folder.rb +++ b/plugins/guests/linux/cap/mount_virtualbox_shared_folder.rb @@ -21,6 +21,11 @@ module VagrantPlugins @@logger.debug("Mounting #{name} (#{options[:hostpath]} to #{guestpath})") + if mounted?(machine, guest_path) + @@logger.info("Skipping mount: #{guest_path} is already mounted") + return + end + builtin_mount_type = "-cit #{mount_type}" addon_mount_type = "-t #{mount_type}" @@ -72,6 +77,10 @@ module VagrantPlugins machine.communicate.sudo("rmdir #{guest_path}", error_check: false) end end + + def self.mounted?(machine, guest_path) + machine.communicate.test("mountpoint -q #{guest_path}") + end end end end diff --git a/test/unit/plugins/guests/linux/cap/mount_virtual_box_shared_folder_test.rb b/test/unit/plugins/guests/linux/cap/mount_virtual_box_shared_folder_test.rb index 75d3073ea..8ef668842 100644 --- a/test/unit/plugins/guests/linux/cap/mount_virtual_box_shared_folder_test.rb +++ b/test/unit/plugins/guests/linux/cap/mount_virtual_box_shared_folder_test.rb @@ -94,6 +94,16 @@ EOF cap.mount_virtualbox_shared_folder(machine, mount_name, mount_guest_path, folder_options) end end + + context "already mounted" do + it "skips mounting if already mounted" do + expect(folder_plugin).to receive(:capability).with(:mount_type).and_return("vboxsf") + expect(comm).to receive(:test).with("mountpoint -q #{mount_guest_path}").and_return(true) + expect(comm).not_to receive(:sudo).with(/mount/) + + cap.mount_virtualbox_shared_folder(machine, mount_name, mount_guest_path, folder_options) + end + end end describe ".unmount_virtualbox_shared_folder" do