Persist synced folders in action
This commit is contained in:
parent
1a3136b9fe
commit
7577c11eb6
@ -37,7 +37,7 @@ module Vagrant
|
|||||||
|
|
||||||
# Find the proper implementation
|
# Find the proper implementation
|
||||||
ordered.each do |_, key, impl|
|
ordered.each do |_, key, impl|
|
||||||
return key if impl.new.usable?(machine, raise_error=false)
|
return key if impl.new.usable?(machine)
|
||||||
end
|
end
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@ -128,6 +128,16 @@ module Vagrant
|
|||||||
# Save the synced folders
|
# Save the synced folders
|
||||||
save_synced_folders(env[:machine], original_folders, **save_opts)
|
save_synced_folders(env[:machine], original_folders, **save_opts)
|
||||||
end
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -14,23 +14,30 @@ module VagrantPlugins
|
|||||||
#
|
#
|
||||||
# @param [Machine] machine The machine to run the action on
|
# @param [Machine] machine The machine to run the action on
|
||||||
# @param [Map<String, Map>] A map of folders to add to fstab
|
# @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, folders)
|
||||||
def self.persist_mount_shared_folder(machine, fstab_folders, mount_type)
|
if folders.nil?
|
||||||
if fstab_folders.empty?
|
|
||||||
self.remove_vagrant_managed_fstab(machine)
|
self.remove_vagrant_managed_fstab(machine)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
export_folders = fstab_folders.map do |name, data|
|
|
||||||
guest_path = Shellwords.escape(data[:guestpath])
|
ssh_info = machine.ssh_info
|
||||||
mount_options, _, _ = machine.synced_folders.types[:virtualbox].capability(:mount_options, name, guest_path, data)
|
export_folders = folders.map { |type, folder|
|
||||||
mount_options = "#{mount_options},nofail"
|
folder.map { |name, data|
|
||||||
{
|
data[:owner] ||= ssh_info[:username]
|
||||||
name: name,
|
data[:group] ||= ssh_info[:username]
|
||||||
mount_point: guest_path,
|
guest_path = Shellwords.escape(data[:guestpath])
|
||||||
mount_type: mount_type,
|
mount_options, _, _ = machine.synced_folders.types[type].capability(
|
||||||
mount_options: mount_options,
|
: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)
|
fstab_entry = Vagrant::Util::TemplateRenderer.render('guests/linux/etc_fstab', folders: export_folders)
|
||||||
self.remove_vagrant_managed_fstab(machine)
|
self.remove_vagrant_managed_fstab(machine)
|
||||||
|
|||||||
@ -47,7 +47,6 @@ module VagrantPlugins
|
|||||||
args += rdp_info[:extra_args] if rdp_info[:extra_args]
|
args += rdp_info[:extra_args] if rdp_info[:extra_args]
|
||||||
end
|
end
|
||||||
|
|
||||||
# require "pry-byebug"; binding.pry
|
|
||||||
# Finally, run the client.
|
# Finally, run the client.
|
||||||
Vagrant::Util::Subprocess.execute(rdp_client, *args, {:detach => true})
|
Vagrant::Util::Subprocess.execute(rdp_client, *args, {:detach => true})
|
||||||
end
|
end
|
||||||
|
|||||||
@ -53,20 +53,12 @@ module VagrantPlugins
|
|||||||
machine.guest.capability(
|
machine.guest.capability(
|
||||||
:mount_virtualbox_shared_folder,
|
:mount_virtualbox_shared_folder,
|
||||||
os_friendly_id(id), data[:guestpath], data)
|
os_friendly_id(id), data[:guestpath], data)
|
||||||
fstab_folders << [os_friendly_id(id), data]
|
|
||||||
else
|
else
|
||||||
# If no guest path is specified, then automounting is disabled
|
# If no guest path is specified, then automounting is disabled
|
||||||
machine.ui.detail(I18n.t("vagrant.actions.vm.share_folders.nomount_entry",
|
machine.ui.detail(I18n.t("vagrant.actions.vm.share_folders.nomount_entry",
|
||||||
hostpath: data[:hostpath]))
|
hostpath: data[:hostpath]))
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
||||||
def disable(machine, folders, _opts)
|
def disable(machine, folders, _opts)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user