mxcl/homebrew — pull request #22830 by glvnst (2013-09-25 22:56:28+00:00)
Title: Update inreplace search term to avoid error

# Problem

$ brew install djbdns
==> Downloading http://cr.yp.to/djbdns/djbdns-1.05.tar.gz
Already downloaded: /Library/Caches/Homebrew/djbdns-1.05.tar.gz
Warning: inreplace in 'dnscache-conf.c' failed
Expected replacement of '([" ])/etc/dnsroots' with '$1/usr/local/etc/dnsroots'
==> echo gcc -O2 -include /usr/include/errno.h > conf-cc
==> echo /usr/local/Cellar/djbdns/1.05 > conf-home
==> echo gcc > conf-ld
==> make setup check
(beer emoji deleted) /usr/local/Cellar/djbdns/1.05: 34 files, 1.0M, built in 13 seconds

This means dnscache and dnscache-conf won't be using the proper directory by default. We can see this here:

$ strings /usr/local/Cellar/djbdns/1.05/bin/dnscache-conf | grep dnsroot
/etc/dnsroots.local
unable to open /etc/dnsroots.local:
/etc/dnsroots.global
unable to open /etc/dnsroots.global:

# Proposed Change

The search argument in the inreplace for dnscache-conf.c is a string, so I don't think it gets regexy treatment (I'm currently weak in the ruby).

inreplace 'dnscache-conf.c', '([" ])/etc/dnsroots', "$1#{etc}/dnsroots"

You could make it a regex, and change the unnecessary find/replace with word boundary anchors

inreplace 'dnscache-conf.c', /\B\/etc\/dnsroots\b/, "#{etc}/dnsroots"

**I'm proposing just making it a simple string find/replace**

inreplace 'dnscache-conf.c', '/etc/dnsroots', "#{etc}/dnsroots"

# Verification

The simple string find/replace appears to be safe:

$ grep '/etc/dnsroots' dnscache-conf.c
fdrootservers = open_read("/etc/dnsroots.local");
strerr_die2sys(111,FATAL,"unable to open /etc/dnsroots.local: ");
fdrootservers = open_read("/etc/dnsroots.global");
strerr_die2sys(111,FATAL,"unable to open /etc/dnsroots.global: ");

To verify that the proposed change works, installing djbdns with this patch and repeating the test above:

$ strings /usr/local/Cellar/djbdns/1.05/bin/dnscache-conf | grep dnsroot
/usr/local/etc/dnsroots.local
unable to open /usr/local/etc/dnsroots.local:
/usr/local/etc/dnsroots.global
unable to open /usr/local/etc/dnsroots.global: