diff --git a/plugins/hosts/arch/host.rb b/plugins/hosts/arch/host.rb index d6aec2b74..d6b496610 100644 --- a/plugins/hosts/arch/host.rb +++ b/plugins/hosts/arch/host.rb @@ -27,7 +27,8 @@ module VagrantPlugins output = TemplateRenderer.render('nfs/exports_linux', :uuid => id, :ip => ip, - :folders => folders) + :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 0aee78f48..6c19ea3a4 100644 --- a/plugins/hosts/bsd/host.rb +++ b/plugins/hosts/bsd/host.rb @@ -38,7 +38,8 @@ module VagrantPlugins output = TemplateRenderer.render(@nfs_exports_template, :uuid => id, :ip => ip, - :folders => folders) + :folders => folders, + :user => Process.uid) # The sleep ensures that the output is truly flushed before any `sudo` # commands are issued. @@ -65,9 +66,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 @@ -93,9 +95,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 265992389..554097f08 100644 --- a/plugins/hosts/linux/host.rb +++ b/plugins/hosts/linux/host.rb @@ -38,7 +38,8 @@ module VagrantPlugins output = TemplateRenderer.render('nfs/exports_linux', :uuid => id, :ip => ip, - :folders => folders) + :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 5bc241f5b..b33b64d06 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 |name, opts| %> "<%= opts[:hostpath] %>" <%= ip %><% 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 59dbd83be..65fd9ab2c 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 |name, opts| %> <%= opts[:hostpath] %> <%= ip %><% 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 60b632812..7de9eb8d9 100644 --- a/templates/nfs/exports_linux.erb +++ b/templates/nfs/exports_linux.erb @@ -1,5 +1,5 @@ -# VAGRANT-BEGIN: <%= uuid %> +# VAGRANT-BEGIN: <%= user %> <%= uuid %> <% 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 %> -# VAGRANT-END: <%= uuid %> +# VAGRANT-END: <%= user %> <%= uuid %>