Skip to content

Commit

Permalink
Ensure permissions on /etc/hosts stay intact
Browse files Browse the repository at this point in the history
  • Loading branch information
Tony Lambiris committed Jan 29, 2016
1 parent 11677f2 commit dd43278
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions lib/vagrant-hostmanager/hosts_file/updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,14 @@ def update_guest(machine)

if (machine.communicate.test("uname -s | grep SunOS"))
realhostfile = '/etc/inet/hosts'
move_cmd = 'mv'
elsif (machine.communicate.test("test -d $Env:SystemRoot"))
windir = ""
machine.communicate.execute("echo %SYSTEMROOT%", {:shell => :cmd}) do |type, contents|
windir << contents.gsub("\r\n", '') if type == :stdout
end
realhostfile = "#{windir}\\System32\\drivers\\etc\\hosts"
move_cmd = 'mv -force'
else
realhostfile = '/etc/hosts'
move_cmd = 'mv -f'
end
# download and modify file with Vagrant-managed entries
file = @global_env.tmp_path.join("hosts.#{machine.name}")
Expand All @@ -37,11 +34,9 @@ def update_guest(machine)
# upload modified file and remove temporary file
machine.communicate.upload(file, '/tmp/hosts')
if windir
machine.communicate.sudo("#{move_cmd} /tmp/hosts/hosts.#{machine.name} #{realhostfile}")
elsif machine.communicate.test('test -f /.dockerinit')
machine.communicate.sudo("cat /tmp/hosts > #{realhostfile}")
machine.communicate.sudo("mv -force /tmp/hosts/hosts.#{machine.name} #{realhostfile}")
else
machine.communicate.sudo("#{move_cmd} /tmp/hosts #{realhostfile}")
machine.communicate.sudo("cat /tmp/hosts > #{realhostfile}")
end
end

Expand Down

0 comments on commit dd43278

Please sign in to comment.