From 7577c11eb6e1406fe7c9a8ec258967b97ca32848 Mon Sep 17 00:00:00 2001 From: sophia Date: Wed, 12 Aug 2020 14:14:20 -0500 Subject: [PATCH] Persist synced folders in action --- .../action/builtin/mixin_synced_folders.rb | 2 +- lib/vagrant/action/builtin/synced_folders.rb | 10 ++++++ .../linux/cap/persist_mount_shared_folder.rb | 33 +++++++++++-------- plugins/hosts/linux/cap/rdp.rb | 1 - plugins/providers/virtualbox/synced_folder.rb | 8 ----- 5 files changed, 31 insertions(+), 23 deletions(-) diff --git a/lib/vagrant/action/builtin/mixin_synced_folders.rb b/lib/vagrant/action/builtin/mixin_synced_folders.rb index bd4367c0f..81c238fc8 100644 --- a/lib/vagrant/action/builtin/mixin_synced_folders.rb +++ b/lib/vagrant/action/builtin/mixin_synced_folders.rb @@ -37,7 +37,7 @@ module Vagrant # Find the proper implementation ordered.each do |_, key, impl| - return key if impl.new.usable?(machine, raise_error=false) + return key if impl.new.usable?(machine) end return nil diff --git a/lib/vagrant/action/builtin/synced_folders.rb b/lib/vagrant/action/builtin/synced_folders.rb index b56c212db..f799d2560 100644 --- a/lib/vagrant/action/builtin/synced_folders.rb +++ b/lib/vagrant/action/builtin/synced_folders.rb @@ -128,6 +128,16 @@ module Vagrant # Save the synced folders save_synced_folders(env[:machine], original_folders, **save_opts) end + + # Persist the mounts by adding them to fstab + if env[:machine].guest.capability?(:persist_mount_shared_folder) + if env[:machine].config.vm.allow_fstab_modification + fstab_folders = original_folders + else + fstab_folders = nil + end + env[:machine].guest.capability(:persist_mount_shared_folder, fstab_folders) + end end end end diff --git a/plugins/guests/linux/cap/persist_mount_shared_folder.rb b/plugins/guests/linux/cap/persist_mount_shared_folder.rb index b7a239874..3a0445f97 100644 --- a/plugins/guests/linux/cap/persist_mount_shared_folder.rb +++ b/plugins/guests/linux/cap/persist_mount_shared_folder.rb @@ -14,23 +14,30 @@ module VagrantPlugins # # @param [Machine] machine The machine to run the action on # @param [Map] A map of folders to add to fstab - # @param [String] mount type, ex. vboxfs, cifs, etc - def self.persist_mount_shared_folder(machine, fstab_folders, mount_type) - if fstab_folders.empty? + def self.persist_mount_shared_folder(machine, folders) + if folders.nil? self.remove_vagrant_managed_fstab(machine) return end - export_folders = fstab_folders.map do |name, data| - guest_path = Shellwords.escape(data[:guestpath]) - mount_options, _, _ = machine.synced_folders.types[:virtualbox].capability(:mount_options, name, guest_path, data) - mount_options = "#{mount_options},nofail" - { - name: name, - mount_point: guest_path, - mount_type: mount_type, - mount_options: mount_options, + + ssh_info = machine.ssh_info + export_folders = folders.map { |type, folder| + folder.map { |name, data| + data[:owner] ||= ssh_info[:username] + data[:group] ||= ssh_info[:username] + guest_path = Shellwords.escape(data[:guestpath]) + mount_options, _, _ = machine.synced_folders.types[type].capability( + :mount_options, name, guest_path, data) + mount_options = "#{mount_options},nofail" + { + name: name, + mount_point: guest_path, + mount_type: type, + mount_options: mount_options, + } } - end + }.flatten.compact + fstab_entry = Vagrant::Util::TemplateRenderer.render('guests/linux/etc_fstab', folders: export_folders) self.remove_vagrant_managed_fstab(machine) diff --git a/plugins/hosts/linux/cap/rdp.rb b/plugins/hosts/linux/cap/rdp.rb index a31b92077..3a2229bc6 100644 --- a/plugins/hosts/linux/cap/rdp.rb +++ b/plugins/hosts/linux/cap/rdp.rb @@ -47,7 +47,6 @@ module VagrantPlugins args += rdp_info[:extra_args] if rdp_info[:extra_args] end - # require "pry-byebug"; binding.pry # Finally, run the client. Vagrant::Util::Subprocess.execute(rdp_client, *args, {:detach => true}) end diff --git a/plugins/providers/virtualbox/synced_folder.rb b/plugins/providers/virtualbox/synced_folder.rb index fd0b8f4b8..c983f18ff 100644 --- a/plugins/providers/virtualbox/synced_folder.rb +++ b/plugins/providers/virtualbox/synced_folder.rb @@ -53,20 +53,12 @@ module VagrantPlugins machine.guest.capability( :mount_virtualbox_shared_folder, os_friendly_id(id), data[:guestpath], data) - fstab_folders << [os_friendly_id(id), data] else # If no guest path is specified, then automounting is disabled machine.ui.detail(I18n.t("vagrant.actions.vm.share_folders.nomount_entry", hostpath: data[:hostpath])) end end - if machine.guest.capability?(:persist_mount_shared_folder) - # If Vagrant has been configured to not allow fstab modification, then - # execute the guest capability with an empty list in order to ensure - # there is no Vagrant managed fstab entries. - fstab_folders = [] if !machine.config.vm.allow_fstab_modification - machine.guest.capability(:persist_mount_shared_folder, fstab_folders, "vboxsf") - end end def disable(machine, folders, _opts)