Skip to content

Commit 5597482

Browse files
authored
Merge pull request #194 from bendoh/check-hosts-writability
If hosts file is writable without sudo, don't use sudo
2 parents dcbcd44 + 50b34b9 commit 5597482

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

lib/vagrant-hostmanager/hosts_file/updater.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class << self
5656
copy_proc = Proc.new { windows_copy_file(file, hosts_location) }
5757
else
5858
hosts_location = '/etc/hosts'
59-
copy_proc = Proc.new { `sudo cp #{file} #{hosts_location}` }
59+
copy_proc = Proc.new { `[ -w #{hosts_location} ] && cat #{file} > #{hosts_location} || sudo cp #{file} #{hosts_location}` }
6060
end
6161

6262
FileUtils.cp(hosts_location, file)

0 commit comments

Comments
 (0)