Merge pull request #264 from jalandis/feature/fix-duplication-of-windows-records
Prevents duplicate host file records in Windows
This commit is contained in:
commit
7281daec1b
|
@ -88,8 +88,8 @@ module VagrantPlugins
|
||||||
|
|
||||||
def update_content(file_content, resolving_machine, include_id, line_endings)
|
def update_content(file_content, resolving_machine, include_id, line_endings)
|
||||||
id = include_id ? " id: #{read_or_create_id}" : ""
|
id = include_id ? " id: #{read_or_create_id}" : ""
|
||||||
header = "## vagrant-hostmanager-start#{id}\n"
|
header = "## vagrant-hostmanager-start#{id}"
|
||||||
footer = "## vagrant-hostmanager-end\n"
|
footer = "## vagrant-hostmanager-end"
|
||||||
body = get_machines
|
body = get_machines
|
||||||
.map { |machine| get_hosts_file_entry(machine, resolving_machine) }
|
.map { |machine| get_hosts_file_entry(machine, resolving_machine) }
|
||||||
.join
|
.join
|
||||||
|
@ -146,12 +146,12 @@ module VagrantPlugins
|
||||||
if body.empty?
|
if body.empty?
|
||||||
block = "\n"
|
block = "\n"
|
||||||
else
|
else
|
||||||
block = "\n\n" + header + body + footer + "\n"
|
block = "\n\n" + header + "\n" + body + footer + "\n\n"
|
||||||
end
|
end
|
||||||
# Pattern for finding existing block
|
# Pattern for finding existing block
|
||||||
header_pattern = Regexp.quote(header)
|
header_pattern = Regexp.quote(header)
|
||||||
footer_pattern = Regexp.quote(footer)
|
footer_pattern = Regexp.quote(footer)
|
||||||
pattern = Regexp.new("\n*#{header_pattern}.*?#{footer_pattern}\n*", Regexp::MULTILINE)
|
pattern = Regexp.new("[\r\n]*#{header_pattern}.*?#{footer_pattern}[\r\n]*", Regexp::MULTILINE)
|
||||||
# Replace existing block or append
|
# Replace existing block or append
|
||||||
content = old_content.match(pattern) ? old_content.sub(pattern, block) : old_content.rstrip + block
|
content = old_content.match(pattern) ? old_content.sub(pattern, block) : old_content.rstrip + block
|
||||||
if line_endings == "crlf"
|
if line_endings == "crlf"
|
||||||
|
|
Loading…
Reference in New Issue