diff options
| author | Jack Nagel | 2014-03-26 16:07:49 -0500 |
|---|---|---|
| committer | Jack Nagel | 2014-03-26 16:07:49 -0500 |
| commit | 7b389fbfed442fda8a013af9bdf5b65a4f5934dd (patch) | |
| tree | d07da489c2369fe80f858092aa96d5bc8b0af8c3 | |
| parent | 4fe0be37c0311c24aa2df6287dabb7505b587f27 (diff) | |
| download | brew-7b389fbfed442fda8a013af9bdf5b65a4f5934dd.tar.bz2 | |
Replace files atomically in inreplace
| -rw-r--r-- | Library/Homebrew/utils/inreplace.rb | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/Library/Homebrew/utils/inreplace.rb b/Library/Homebrew/utils/inreplace.rb index 4fa2fbe7c..a6451c49f 100644 --- a/Library/Homebrew/utils/inreplace.rb +++ b/Library/Homebrew/utils/inreplace.rb @@ -2,12 +2,10 @@ module Utils module Inreplace def inreplace paths, before=nil, after=nil Array(paths).each do |path| - f = File.open(path, 'rb') - s = f.read + s = File.open(path, "rb", &:read) if before.nil? && after.nil? - s.extend(StringInreplaceExtension) - yield s + yield s.extend(StringInreplaceExtension) else after = after.to_s if Symbol === after unless s.gsub!(before, after) @@ -19,8 +17,7 @@ module Utils end end - f.reopen(path, 'wb').write(s) - f.close + Pathname(path).atomic_write(s) end end end |
