From 84b402c26a0d53e6d60655ce0c959e984d4ee660 Mon Sep 17 00:00:00 2001 From: Joey Chagnon Date: Thu, 19 May 2016 16:28:48 -0400 Subject: [PATCH] Fix permissions error when local hosts is on nfs. If hosts.local is served via NFS with root_squash enabled then the copy fails with a permission denied error. --- lib/vagrant-hostmanager/hosts_file/updater.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/vagrant-hostmanager/hosts_file/updater.rb b/lib/vagrant-hostmanager/hosts_file/updater.rb index 97d412c..8df2585 100644 --- a/lib/vagrant-hostmanager/hosts_file/updater.rb +++ b/lib/vagrant-hostmanager/hosts_file/updater.rb @@ -56,7 +56,12 @@ class << self copy_proc = Proc.new { windows_copy_file(file, hosts_location) } else hosts_location = '/etc/hosts' - copy_proc = Proc.new { `sudo cp #{file} #{hosts_location}` } + copy_proc = Proc.new { + tmp = Tempfile.new('hosts.local') + FileUtils.cp(file, tmp.path()) + `sudo cp #{tmp.path()} #{hosts_location}` + tmp.close! + } end FileUtils.cp(hosts_location, file)