aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/utils
diff options
context:
space:
mode:
authorJack Nagel2014-09-28 01:08:31 -0500
committerJack Nagel2014-09-28 01:11:31 -0500
commitaaaab946eca5b53e7ea9508348634ec280e00b62 (patch)
tree562e4a5b37e857363edd702c9201767c7adfe193 /Library/Homebrew/utils
parent1c71fb42870556c13ab2c5bf04a4bdb47d35ed67 (diff)
downloadbrew-aaaab946eca5b53e7ea9508348634ec280e00b62.tar.bz2
Make inreplace errors fatal
Closes Homebrew/homebrew#32649. Closes Homebrew/homebrew#32703.
Diffstat (limited to 'Library/Homebrew/utils')
-rw-r--r--Library/Homebrew/utils/inreplace.rb26
1 files changed, 17 insertions, 9 deletions
diff --git a/Library/Homebrew/utils/inreplace.rb b/Library/Homebrew/utils/inreplace.rb
index 52a43ece9..02372d214 100644
--- a/Library/Homebrew/utils/inreplace.rb
+++ b/Library/Homebrew/utils/inreplace.rb
@@ -1,24 +1,32 @@
module Utils
+ class InreplaceError < RuntimeError
+ def initialize(errors)
+ super errors.inject("inreplace failed\n") { |s, (path, errs)|
+ s << "#{path}:\n" << errs.map { |e| " #{e}\n" }.join
+ }
+ end
+ end
+
module Inreplace
def inreplace paths, before=nil, after=nil
+ errors = {}
+
Array(paths).each do |path|
- s = File.open(path, "rb", &:read)
+ s = File.open(path, "rb", &:read).extend(StringInreplaceExtension)
if before.nil? && after.nil?
- yield s.extend(StringInreplaceExtension)
+ yield s
else
after = after.to_s if Symbol === after
- unless s.gsub!(before, after)
- message = <<-EOS.undent
- inreplace in '#{path}' failed
- Expected replacement of '#{before}' with '#{after}'
- EOS
- ARGV.homebrew_developer? ? odie(message) : opoo(message)
- end
+ s.gsub!(before, after)
end
+ errors[path] = s.errors if s.errors.any?
+
Pathname(path).atomic_write(s)
end
+
+ raise InreplaceError.new(errors) if errors.any?
end
module_function :inreplace
end