From 50b34b96590fb1ec9f88238d6256757224e0a636 Mon Sep 17 00:00:00 2001 From: Ben Doherty Date: Fri, 3 Jun 2016 10:06:23 -0400 Subject: [PATCH] If hosts file is writable without sudo, don't use sudo --- lib/vagrant-hostmanager/hosts_file/updater.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vagrant-hostmanager/hosts_file/updater.rb b/lib/vagrant-hostmanager/hosts_file/updater.rb index 97d412c..a49df67 100644 --- a/lib/vagrant-hostmanager/hosts_file/updater.rb +++ b/lib/vagrant-hostmanager/hosts_file/updater.rb @@ -56,7 +56,7 @@ module VagrantPlugins 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 { `[ -w #{hosts_location} ] && cat #{file} > #{hosts_location} || sudo cp #{file} #{hosts_location}` } end FileUtils.cp(hosts_location, file)