Exported sub-directories of exported NFS dirs works on BSD [GH-785]

This commit is contained in:
Mitchell Hashimoto 2013-07-10 14:19:57 -07:00
parent abd22dfe72
commit 2657364921
4 changed files with 53 additions and 5 deletions

View File

@ -1,6 +1,9 @@
## 1.2.4 (unreleased)
BUG FIXES:
- core/nfs: Exporting sub-directories of other exported folders now
works properly. [GH-785]
## 1.2.3 (July 9, 2013)

View File

@ -35,10 +35,55 @@ module VagrantPlugins
end
def nfs_export(id, ip, folders)
# We need to build up mapping of directories that are enclosed
# within each other because the exports file has to have subdirectories
# of an exported directory on the same line. e.g.:
#
# "/foo" "/foo/bar" ...
# "/bar"
#
# We build up this mapping within the following hash.
@logger.debug("Compiling map of sub-directories for NFS exports...")
dirmap = {}
folders.each do |_, opts|
hostpath = opts[:hostpath]
found = false
dirmap.each do |dirs, diropts|
dirs.each do |dir|
if dir.start_with?(hostpath) || hostpath.start_with?(dir)
# TODO: verify opts and diropts are _identical_, raise an error
# if not. NFS mandates subdirectories have identical options.
dirs << hostpath
found = true
break
end
end
break if found
end
if !found
dirmap[[hostpath]] = opts.dup
end
end
# Sort all the keys by length so that the directory closest to
# the root is exported first.
dirmap.each do |dirs, _|
dirs.sort_by! { |d| d.length }
end
@logger.info("Exporting the following for NFS...")
dirmap.each do |dirs, opts|
@logger.info("NFS DIR: #{dirs.inspect}")
@logger.info("NFS OPTS: #{opts.inspect}")
end
output = TemplateRenderer.render(@nfs_exports_template,
:uuid => id,
:ip => ip,
:folders => folders)
:folders => dirmap)
# The sleep ensures that the output is truly flushed before any `sudo`
# commands are issued.

View File

@ -1,5 +1,5 @@
# VAGRANT-BEGIN: <%= uuid %>
<% folders.each do |name, opts| %>
"<%= opts[:hostpath] %>" <%= ip %><% if opts[:map_uid] -%> -mapall=<%= [opts[:map_uid],opts[:map_gid]].compact.join(":") %><% end -%>
<% folders.each do |dirs, opts| %>
<%= dirs.map { |d| "\"#{d}\"" }.join(" ") %> <%= ip %><% if opts[:map_uid] -%> -mapall=<%= [opts[:map_uid],opts[:map_gid]].compact.join(":") %><% end -%>
<% end %>
# VAGRANT-END: <%= uuid %>

View File

@ -1,5 +1,5 @@
# VAGRANT-BEGIN: <%= uuid %>
<% folders.each do |name, opts| %>
<%= opts[:hostpath] %> <%= ip %><% if opts[:map_uid] -%> -alldirs -mapall=<%= [opts[:map_uid],opts[:map_gid]].compact.join(":") %><% end -%>
<% folders.each do |dirs, opts| %>
<%= dirs.map { |d| "\"#{d}\"" }.join(" ") %> <%= ip %><% if opts[:map_uid] -%> -alldirs -mapall=<%= [opts[:map_uid],opts[:map_gid]].compact.join(":") %><% end -%>
<% end %>
# VAGRANT-END: <%= uuid %>