diff --git a/lib/vagrant/action/builtin/mixin_synced_folders.rb b/lib/vagrant/action/builtin/mixin_synced_folders.rb index ad7c4d528..725a062cf 100644 --- a/lib/vagrant/action/builtin/mixin_synced_folders.rb +++ b/lib/vagrant/action/builtin/mixin_synced_folders.rb @@ -2,6 +2,7 @@ require "json" require "set" require 'vagrant/util/scoped_hash_override' +require 'vagrant/util/typed_hash' module Vagrant module Action @@ -36,11 +37,7 @@ module Vagrant # Find the proper implementation ordered.each do |_, key, impl| - begin - return key if impl.new.usable?(machine) - rescue - # Don't do anything. If an error is raised, the impl is not usable - end + return key if impl.new.usable?(machine) end return nil @@ -128,7 +125,7 @@ module Vagrant end config_folders = config.synced_folders - folders = {} + folders = Vagrant::Util::TypedHash.new() # Determine all the synced folders as well as the implementation # they're going to use. @@ -194,6 +191,12 @@ module Vagrant folders[impl_name] = new_fs end + + folders.types = folders.map { |type, folders| + impl = plugins[type][0].new() + impl._initialize(machine, type) + [type, impl] + }.to_h return folders end diff --git a/lib/vagrant/machine.rb b/lib/vagrant/machine.rb index 7f57c8309..c92ceb52f 100644 --- a/lib/vagrant/machine.rb +++ b/lib/vagrant/machine.rb @@ -628,20 +628,6 @@ module Vagrant self.class.synced_folders(self) end - # Returns the SyncedFolder object associated with this machine. - # - # @return [List] - def synced_folder_types - return @synced_folder_types if defined?(@synced_folder_types) - plugins = Vagrant.plugin("2").manager.synced_folders - @synced_folder_types = synced_folders.map { |type, folders| - impl = plugins[type][0].new() - impl._initialize(self, type) - [type, impl] - }.to_h - @synced_folder_types - end - protected # Returns the path to the file that stores the UID. diff --git a/lib/vagrant/util/typed_hash.rb b/lib/vagrant/util/typed_hash.rb new file mode 100644 index 000000000..14360f1aa --- /dev/null +++ b/lib/vagrant/util/typed_hash.rb @@ -0,0 +1,10 @@ +module Vagrant + module Util + class TypedHash < Hash + + # Types available in the Hash + attr_accessor :types + + end + end +end diff --git a/plugins/guests/linux/cap/mount_virtualbox_shared_folder.rb b/plugins/guests/linux/cap/mount_virtualbox_shared_folder.rb index fcc4b0343..87efb8c82 100644 --- a/plugins/guests/linux/cap/mount_virtualbox_shared_folder.rb +++ b/plugins/guests/linux/cap/mount_virtualbox_shared_folder.rb @@ -16,7 +16,7 @@ module VagrantPlugins builtin_mount_type = "-cit #{VB_MOUNT_TYPE}" addon_mount_type = "-t #{VB_MOUNT_TYPE}" - mount_options, mount_uid, mount_gid = machine.synced_folder_types[:virtualbox].capability(:mount_options, name, guestpath, options) + mount_options, mount_uid, mount_gid = machine.synced_folders.types[:virtualbox].capability(:mount_options, name, guest_path, options) mount_command = "mount #{addon_mount_type} -o #{mount_options} #{name} #{guest_path}" # Create the guest path if it doesn't exist diff --git a/plugins/guests/linux/cap/persist_mount_shared_folder.rb b/plugins/guests/linux/cap/persist_mount_shared_folder.rb index 9e7dda16d..b7a239874 100644 --- a/plugins/guests/linux/cap/persist_mount_shared_folder.rb +++ b/plugins/guests/linux/cap/persist_mount_shared_folder.rb @@ -22,7 +22,7 @@ module VagrantPlugins end export_folders = fstab_folders.map do |name, data| guest_path = Shellwords.escape(data[:guestpath]) - mount_options, mount_uid, mount_gid = machine.synced_folder_types[:virtualbox].capability(:mount_options, name, guest_path, data) + mount_options, _, _ = machine.synced_folders.types[:virtualbox].capability(:mount_options, name, guest_path, data) mount_options = "#{mount_options},nofail" { name: name, diff --git a/plugins/kernel_v2/config/vm.rb b/plugins/kernel_v2/config/vm.rb index 451fa77c6..6415f58a8 100644 --- a/plugins/kernel_v2/config/vm.rb +++ b/plugins/kernel_v2/config/vm.rb @@ -727,7 +727,7 @@ module VagrantPlugins if @allow_fstab_modification == UNSET_VALUE plugins = Vagrant.plugin("2").manager.synced_folders - machine.synced_folder_types.each do |_, inst| + machine.synced_folders.types.each do |_, inst| if inst.capability?(:default_fstab_modification) if inst.capability(:default_fstab_modification) == false @allow_fstab_modification = false