From 1d161d05824ce71f406f4d90f2d512330bdeea42 Mon Sep 17 00:00:00 2001 From: itaymendel Date: Wed, 28 Aug 2013 08:58:46 +0300 Subject: [PATCH] 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. --- lib/vagrant-hostmanager/hosts_file.rb | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/vagrant-hostmanager/hosts_file.rb b/lib/vagrant-hostmanager/hosts_file.rb index 662a9bc..29466ea 100644 --- a/lib/vagrant-hostmanager/hosts_file.rb +++ b/lib/vagrant-hostmanager/hosts_file.rb @@ -14,17 +14,29 @@ module VagrantPlugins # upload modified file and remove temporary file machine.communicate.upload(file, '/tmp/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 def update_host # copy and modify hosts file on host with Vagrant-managed entries 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) # copy modified file using sudo for permission - `sudo cp #{file} /etc/hosts` + `#{copy_cmd} #{file} #{hosts_location}` end private