hosts/linux: don't use sudo to write NFS if writable [GH-2643]

This commit is contained in:
Mitchell Hashimoto 2014-10-23 22:25:38 -07:00
parent fbd568a03e
commit cc01f01684
1 changed files with 10 additions and 2 deletions

View File

@ -38,9 +38,13 @@ module VagrantPlugins
nfs_cleanup(id)
# Only use "sudo" if we can't write to /etc/exports directly
sudo_command = ""
sudo_command = "sudo " if !File.writable?("/etc/exports")
output.split("\n").each do |line|
line = Vagrant::Util::ShellQuote.escape(line, "'")
system(%Q[echo '#{line}' | sudo tee -a /etc/exports >/dev/null])
system(%Q[echo '#{line}' | #{sudo_command}tee -a /etc/exports >/dev/null])
end
if nfs_running?(nfs_check_command)
@ -92,9 +96,13 @@ module VagrantPlugins
user = Regexp.escape(Process.uid.to_s)
id = Regexp.escape(id.to_s)
# Only use "sudo" if we can't write to /etc/exports directly
sudo_command = ""
sudo_command = "sudo " if !File.writable?("/etc/exports")
# Use sed to just strip out the block of code which was inserted
# by Vagrant
system("sudo sed -r -e '\\\x01^# VAGRANT-BEGIN:( #{user})? #{id}\x01,\\\x01^# VAGRANT-END:( #{user})? #{id}\x01 d' -ibak /etc/exports")
system("#{sudo_command}sed -r -e '\\\x01^# VAGRANT-BEGIN:( #{user})? #{id}\x01,\\\x01^# VAGRANT-END:( #{user})? #{id}\x01 d' -ibak /etc/exports")
end
def self.nfs_opts_setup(folders)