Allow overriding the inferred name from `config.vm.synced_folder`

If a `name` is specified as an option, it will be used as the id instead
of inferring it from the `guestpath`. If `guestpath` is nil, the `name`
needs to be specified so the folder can be mounted with a name.

This also fixes the synced folder code to allow `guestpath` to be nil.
It was allowed in a previous version for the purpose of preventing a
directory from being auto mounted (#936), but seems to have become an
error at some point after that.

An example of modifying the default /vagrant folder so it doesn't
auto-mount anymore:

    config.vm.synced_folder ".", nil, name: "/vagrant"

An example of sharing another folder, but not auto-mounting it:

    config.vm.synced_folder ".", nil, name: "foobar"

Fixes #6835.
This commit is contained in:
Jonathan A. Sternberg 2016-01-09 11:15:25 -05:00 committed by Chris Roberts
parent dbbd2d8e36
commit c3438ff8f6
1 changed files with 3 additions and 2 deletions

View File

@ -201,6 +201,7 @@ module VagrantPlugins
# folder. # folder.
# @param [Hash] options Additional options. # @param [Hash] options Additional options.
def synced_folder(hostpath, guestpath, options=nil) def synced_folder(hostpath, guestpath, options=nil)
name = (options && options.delete(:name)) || guestpath
if Vagrant::Util::Platform.windows? if Vagrant::Util::Platform.windows?
# On Windows, Ruby just uses normal '/' for path seps, so # On Windows, Ruby just uses normal '/' for path seps, so
# just replace normal Windows style seps with Unix ones. # just replace normal Windows style seps with Unix ones.
@ -217,7 +218,7 @@ module VagrantPlugins
# Make sure the type is a symbol # Make sure the type is a symbol
options[:type] = options[:type].to_sym if options[:type] options[:type] = options[:type].to_sym if options[:type]
@__synced_folders[options[:guestpath]] = options @__synced_folders[name] = options
end end
# Define a way to access the machine via a network. This exposes a # Define a way to access the machine via a network. This exposes a
@ -626,7 +627,7 @@ module VagrantPlugins
# If the shared folder is disabled then don't worry about validating it # If the shared folder is disabled then don't worry about validating it
next if options[:disabled] next if options[:disabled]
guestpath = Pathname.new(options[:guestpath]) guestpath = Pathname.new(options[:guestpath]) if options[:guestpath]
hostpath = Pathname.new(options[:hostpath]).expand_path(machine.env.root_path) hostpath = Pathname.new(options[:hostpath]).expand_path(machine.env.root_path)
if guestpath.to_s != "" if guestpath.to_s != ""