aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorMax Howell2009-10-23 19:01:05 +0100
committerMax Howell2009-10-23 19:22:51 +0100
commita49c87d4b73d10c92a6ee7485c8190ae9694c1fc (patch)
treee5e42d44d7169072176002d5490ffb85d164571f /Library
parent66e4570c40b80cc79662f45a8a9be81665cfaa5e (diff)
downloadhomebrew-a49c87d4b73d10c92a6ee7485c8190ae9694c1fc.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')
-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