Persist synced folders in action

This commit is contained in:
sophia 2020-08-12 14:14:20 -05:00
parent 1a3136b9fe
commit 7577c11eb6
5 changed files with 31 additions and 23 deletions

View File

@ -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

View File

@ -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

View File

@ -14,23 +14,30 @@ module VagrantPlugins
#
# @param [Machine] machine The machine to run the action on
# @param [Map<String, 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)

View File

@ -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

View File

@ -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)