Skip to content

Commit dd43278

Browse files
author
Tony Lambiris
committed
Ensure permissions on /etc/hosts stay intact
1 parent 11677f2 commit dd43278

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

lib/vagrant-hostmanager/hosts_file/updater.rb

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,14 @@ def update_guest(machine)
1717

1818
if (machine.communicate.test("uname -s | grep SunOS"))
1919
realhostfile = '/etc/inet/hosts'
20-
move_cmd = 'mv'
2120
elsif (machine.communicate.test("test -d $Env:SystemRoot"))
2221
windir = ""
2322
machine.communicate.execute("echo %SYSTEMROOT%", {:shell => :cmd}) do |type, contents|
2423
windir << contents.gsub("\r\n", '') if type == :stdout
2524
end
2625
realhostfile = "#{windir}\\System32\\drivers\\etc\\hosts"
27-
move_cmd = 'mv -force'
2826
else
2927
realhostfile = '/etc/hosts'
30-
move_cmd = 'mv -f'
3128
end
3229
# download and modify file with Vagrant-managed entries
3330
file = @global_env.tmp_path.join("hosts.#{machine.name}")
@@ -37,11 +34,9 @@ def update_guest(machine)
3734
# upload modified file and remove temporary file
3835
machine.communicate.upload(file, '/tmp/hosts')
3936
if windir
40-
machine.communicate.sudo("#{move_cmd} /tmp/hosts/hosts.#{machine.name} #{realhostfile}")
41-
elsif machine.communicate.test('test -f /.dockerinit')
42-
machine.communicate.sudo("cat /tmp/hosts > #{realhostfile}")
37+
machine.communicate.sudo("mv -force /tmp/hosts/hosts.#{machine.name} #{realhostfile}")
4338
else
44-
machine.communicate.sudo("#{move_cmd} /tmp/hosts #{realhostfile}")
39+
machine.communicate.sudo("cat /tmp/hosts > #{realhostfile}")
4540
end
4641
end
4742

0 commit comments

Comments
 (0)