From 7dc5f8ca80f120a3f7ccbc5c21092b6e2893a4ab Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 12 Jan 2012 18:23:30 -0800 Subject: [PATCH] Revert "Always clear NFS exports for the VM booting [GH-529]" This reverts commit 70705d28616e30d75ac70cc41565a616a2b03325. --- lib/vagrant/action/vm/nfs.rb | 14 +++++++------- lib/vagrant/hosts/bsd.rb | 12 ++++++++---- lib/vagrant/hosts/linux.rb | 9 ++++++--- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/lib/vagrant/action/vm/nfs.rb b/lib/vagrant/action/vm/nfs.rb index 861c3ef3e..0bb171e45 100644 --- a/lib/vagrant/action/vm/nfs.rb +++ b/lib/vagrant/action/vm/nfs.rb @@ -60,19 +60,19 @@ module Vagrant # task. def extract_folders # Load the NFS enabled shared folders - @folders = {} - @env[:vm].config.vm.shared_folders.each do |name, opts| + @folders = @env[:vm].config.vm.shared_folders.inject({}) do |acc, data| + key, opts = data + if opts[:nfs] # Duplicate the options, set the hostpath, and set disabled on the original # options so the ShareFolders middleware doesn't try to mount it. - opts = opts.dup - opts[:hostpath] = File.expand_path(opts[:hostpath], @env[:root_path]) + acc[key] = opts.dup + acc[key][:hostpath] = File.expand_path(opts[:hostpath], @env[:root_path]) opts[:disabled] = true - @folders[key] = opts end - end - @folders + acc + end end # Prepares the settings for the NFS folders, such as setting the diff --git a/lib/vagrant/hosts/bsd.rb b/lib/vagrant/hosts/bsd.rb index da79a3422..0e8c85800 100644 --- a/lib/vagrant/hosts/bsd.rb +++ b/lib/vagrant/hosts/bsd.rb @@ -56,10 +56,14 @@ module Vagrant return if !File.exist?("/etc/exports") retryable(:tries => 10, :on => TypeError) do - # 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(@nfs_restart_command) + system("cat /etc/exports | grep 'VAGRANT-BEGIN: #{id}' > /dev/null 2>&1") + + if $?.to_i == 0 + # 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(@nfs_restart_command) + end end end end diff --git a/lib/vagrant/hosts/linux.rb b/lib/vagrant/hosts/linux.rb index c6e4a755d..f7107d2cf 100644 --- a/lib/vagrant/hosts/linux.rb +++ b/lib/vagrant/hosts/linux.rb @@ -52,10 +52,13 @@ module Vagrant def nfs_cleanup(id) return if !File.exist?("/etc/exports") + system("cat /etc/exports | grep 'VAGRANT-BEGIN: #{id}' > /dev/null 2>&1") - # 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") + if $?.to_i == 0 + # 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") + end end end end