Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix resolving windows hosts file in unix EOL #165

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Uses now powershellv3 since its much more reliable.
  • Loading branch information
la-magra committed Sep 26, 2015
commit 9b531b2004cc4152cdb614373a41a2e464ea81ae
10 changes: 5 additions & 5 deletions lib/vagrant-hostmanager/hosts_file/updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,10 @@ class << self
include WindowsSupport unless include? WindowsSupport
end
crlf_file = @global_env.tmp_path.join('hosts.local.crlf')
windows_convert_to_crlf(file, crlf_file)
hosts_location = "#{ENV['WINDIR']}\\System32\\drivers\\etc\\hosts"
copy_proc = Proc.new { windows_copy_file(crlf_file, hosts_location) }
FileUtils.cp(hosts_location, crlf_file)
if update_file(crlf_file)
if update_file(file)
windows_convert_to_crlf(file, crlf_file)
copy_proc.call
end
else
Expand Down Expand Up @@ -173,9 +172,10 @@ def self.windows?

require 'win32ole' if windows?

# Converts a file(source) to windows default EOL, needs Powershell v3
def windows_convert_to_crlf(source, dest)
convert_cmd = "type \"#{source.to_s.gsub('/', '\\')}\" | more /P > \"#{dest.to_s.gsub('/', '\\')}\""
WIN32OLE.new('Shell.Application').ShellExecute('cmd', "/C #{convert_cmd}", nil, nil, 7)
convert_with_powershell = "Get-Content \"#{source.to_s.gsub(/\//, '\\')}\" | Set-Content \"#{dest.to_s.gsub(/\//, '\\')}\""
WIN32OLE.new('Shell.Application').ShellExecute('powershell', "-Command #{convert_with_powershell}", nil, nil, 7)
end

def windows_copy_file(source, dest)
Expand Down