fixed windows compatibility issues for the hosts file
i have added a 'if windows' for the update_host method, to deal with a windows host machine. sometimes i had an error on line 17, because the file was no longer there (maybe mv removed it?), so i just added a exception block to catch it. it does nothing, but now it is working for me.
This commit is contained in:
parent
436b171f53
commit
1d161d0582
|
@ -14,17 +14,29 @@ module VagrantPlugins
|
||||||
# upload modified file and remove temporary file
|
# upload modified file and remove temporary file
|
||||||
machine.communicate.upload(file, '/tmp/hosts')
|
machine.communicate.upload(file, '/tmp/hosts')
|
||||||
machine.communicate.sudo('mv /tmp/hosts /etc/hosts')
|
machine.communicate.sudo('mv /tmp/hosts /etc/hosts')
|
||||||
FileUtils.rm(file)
|
# i have no idea if this is a windows competibility issue or not, but sometimes it dosen't work on my machine
|
||||||
|
begin
|
||||||
|
FileUtils.rm(file)
|
||||||
|
rescue Exception => e
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_host
|
def update_host
|
||||||
# copy and modify hosts file on host with Vagrant-managed entries
|
# copy and modify hosts file on host with Vagrant-managed entries
|
||||||
file = @global_env.tmp_path.join('hosts.local')
|
file = @global_env.tmp_path.join('hosts.local')
|
||||||
FileUtils.cp('/etc/hosts', file)
|
# add a "if windows..."
|
||||||
|
hosts_location = '/etc/hosts'
|
||||||
|
copy_cmd = 'sudo cp'
|
||||||
|
# handles the windows hosts file...
|
||||||
|
if ENV['OS'] == 'Windows_NT'
|
||||||
|
hosts_location = "#{ENV['WINDIR']}\\System32\\drivers\\etc\\hosts"
|
||||||
|
copy_cmd = 'cp'
|
||||||
|
end
|
||||||
|
FileUtils.cp(hosts_location, file)
|
||||||
update_file(file)
|
update_file(file)
|
||||||
|
|
||||||
# copy modified file using sudo for permission
|
# copy modified file using sudo for permission
|
||||||
`sudo cp #{file} /etc/hosts`
|
`#{copy_cmd} #{file} #{hosts_location}`
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
Loading…
Reference in New Issue