aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/utils.rb
diff options
context:
space:
mode:
authorMax Howell2009-10-23 19:01:05 +0100
committerMax Howell2009-10-23 19:22:51 +0100
commite289164adc985e364f4c3fcb198534321e4aa481 (patch)
tree2647605ac667cfe0dbb124a031e8030b25bed52e /Library/Homebrew/utils.rb
parent7375758c9aed688541eab90a2053dacd22c2a478 (diff)
downloadbrew-e289164adc985e364f4c3fcb198534321e4aa481.tar.bz2
Implement inreplace natively in Ruby
I found yet another instance where the escaping wasn't perfect, so got fed up and just did it in Ruby. I hope this works for all existing usage. It should. The bonus here is that you can use RegExps now.
Diffstat (limited to 'Library/Homebrew/utils.rb')
-rw-r--r--Library/Homebrew/utils.rb13
1 files changed, 4 insertions, 9 deletions
diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb
index e9a480ed2..398119945 100644
--- a/Library/Homebrew/utils.rb
+++ b/Library/Homebrew/utils.rb
@@ -149,13 +149,8 @@ end
# replaces before with after for the file path
def inreplace path, before, after
- before=Regexp.escape before.to_s
- before.gsub! "/", "\\/" # I guess not escaped as delimiter varies
- after=after.to_s
- after.gsub! "\\", "\\\\"
- after.gsub! "/", "\\/"
- after.gsub! "$", "\\$"
-
- # FIXME use proper Ruby for teh exceptions!
- safe_system "/usr/bin/perl", "-pi", "-e", "s/#{before}/#{after}/g", path
+ f = File.open(path, 'r')
+ o = f.read.gsub(before, after)
+ f.reopen(path, 'w').write(o)
+ f.close
end