diff --git a/plugins/hosts/arch/host.rb b/plugins/hosts/arch/host.rb index fd3911293..be4f21c30 100644 --- a/plugins/hosts/arch/host.rb +++ b/plugins/hosts/arch/host.rb @@ -26,8 +26,9 @@ module VagrantPlugins def nfs_export(id, ips, folders) output = TemplateRenderer.render('nfs/exports_linux', :uuid => id, - :ips => ips, - :folders => folders) + :ip => ips, + :folders => folders, + :user => Process.uid) @ui.info I18n.t("vagrant.hosts.arch.nfs_export.prepare") sleep 0.5 diff --git a/plugins/hosts/bsd/host.rb b/plugins/hosts/bsd/host.rb index ea72ff9d0..d9f6860ca 100644 --- a/plugins/hosts/bsd/host.rb +++ b/plugins/hosts/bsd/host.rb @@ -84,7 +84,8 @@ module VagrantPlugins output = TemplateRenderer.render(@nfs_exports_template, :uuid => id, :ips => ips, - :folders => dirmap) + :folders => dirmap, + :user => Process.uid) # The sleep ensures that the output is truly flushed before any `sudo` # commands are issued. @@ -112,9 +113,10 @@ module VagrantPlugins @logger.info("Pruning invalid NFS entries...") output = false + user = Process.uid File.read("/etc/exports").lines.each do |line| - if id = line[/^# VAGRANT-BEGIN: (.+?)$/, 1] + if id = line[/^# VAGRANT-BEGIN:( #{user})? ([A-Za-z0-9-]+?)$/, 2] if valid_ids.include?(id) @logger.debug("Valid ID: #{id}") else @@ -142,9 +144,11 @@ module VagrantPlugins id = id.gsub("/", "\\/") id = id.gsub(".", "\\.") + user = Process.uid + # Use sed to just strip out the block of code which was inserted # by Vagrant, and restart NFS. - system("sudo sed -e '/^# VAGRANT-BEGIN: #{id}/,/^# VAGRANT-END: #{id}/ d' -ibak /etc/exports") + system("sudo sed -e '/^# VAGRANT-BEGIN:\\( #{user}\\)\\? #{id}/,/^# VAGRANT-END:\\( #{user}\\)\\? #{id}/ d' -ibak /etc/exports") end end end diff --git a/plugins/hosts/linux/host.rb b/plugins/hosts/linux/host.rb index 042f51db3..76288eec5 100644 --- a/plugins/hosts/linux/host.rb +++ b/plugins/hosts/linux/host.rb @@ -37,8 +37,9 @@ module VagrantPlugins def nfs_export(id, ips, folders) output = TemplateRenderer.render('nfs/exports_linux', :uuid => id, - :ips => ips, - :folders => folders) + :ip => ip, + :folders => folders, + :user => Process.uid) @ui.info I18n.t("vagrant.hosts.linux.nfs_export") sleep 0.5 @@ -62,9 +63,10 @@ module VagrantPlugins @logger.info("Pruning invalid NFS entries...") output = false + user = Process.uid File.read("/etc/exports").lines.each do |line| - if id = line[/^# VAGRANT-BEGIN: (.+?)$/, 1] + if id = line[/^# VAGRANT-BEGIN:( #{user})? ([A-Za-z0-9-]+?)$/, 2] if valid_ids.include?(id) @logger.debug("Valid ID: #{id}") else @@ -86,9 +88,10 @@ module VagrantPlugins def nfs_cleanup(id) return if !File.exist?("/etc/exports") + user = Process.uid # Use sed to just strip out the block of code which was inserted # by Vagrant - system("sudo sed -e '/^# VAGRANT-BEGIN: #{id}/,/^# VAGRANT-END: #{id}/ d' -ibak /etc/exports") + system("sudo sed -e '/^# VAGRANT-BEGIN:\\( #{user}\\)\\? #{id}/,/^# VAGRANT-END:\\( #{user}\\)\\? #{id}/ d' -ibak /etc/exports") end end end diff --git a/templates/nfs/exports.erb b/templates/nfs/exports.erb index ee22a960e..f0f0494a8 100644 --- a/templates/nfs/exports.erb +++ b/templates/nfs/exports.erb @@ -1,5 +1,5 @@ -# VAGRANT-BEGIN: <%= uuid %> +# VAGRANT-BEGIN: <%= user %> <%= uuid %> <% folders.each do |dirs, opts| %> <%= dirs.map { |d| "\"#{d}\"" }.join(" ") %> <%= ips.join(" ") %><% if opts[:map_uid] -%> -mapall=<%= [opts[:map_uid],opts[:map_gid]].compact.join(":") %><% end -%> <% end %> -# VAGRANT-END: <%= uuid %> +# VAGRANT-END: <%= user %> <%= uuid %> diff --git a/templates/nfs/exports_freebsd.erb b/templates/nfs/exports_freebsd.erb index 46f6e6d90..ef07829b6 100644 --- a/templates/nfs/exports_freebsd.erb +++ b/templates/nfs/exports_freebsd.erb @@ -1,5 +1,5 @@ -# VAGRANT-BEGIN: <%= uuid %> +# VAGRANT-BEGIN: <%= user %> <%= uuid %> <% folders.each do |dirs, opts| %> <%= dirs.map { |d| "\"#{d}\"" }.join(" ") %> <%= ips.join(" ") %><% if opts[:map_uid] -%> -alldirs -mapall=<%= [opts[:map_uid],opts[:map_gid]].compact.join(":") %><% end -%> <% end %> -# VAGRANT-END: <%= uuid %> +# VAGRANT-END: <%= user %> <%= uuid %> diff --git a/templates/nfs/exports_linux.erb b/templates/nfs/exports_linux.erb index 112bb4aa4..f9e17ba15 100644 --- a/templates/nfs/exports_linux.erb +++ b/templates/nfs/exports_linux.erb @@ -1,7 +1,7 @@ -# VAGRANT-BEGIN: <%= uuid %> +# VAGRANT-BEGIN: <%= user %> <%= uuid %> <% ips.each do |ip| %> <% folders.each do |name, opts| %> "<%= opts[:hostpath] %>" <%= ip %>(rw,no_subtree_check,all_squash<% if opts[:map_uid] %>,anonuid=<%= opts[:map_uid] %><% end %><% if opts[:map_gid] %>,anongid=<%= opts[:map_gid] %><% end %>,fsid=<%= opts[:uuid] %>) <% end %> <% end %> -# VAGRANT-END: <%= uuid %> +# VAGRANT-END: <%= user %> <%= uuid %>