diff options
| author | Jack Nagel | 2014-03-26 16:07:49 -0500 |
|---|---|---|
| committer | Jack Nagel | 2014-03-26 16:07:49 -0500 |
| commit | 4ae9cc42734217e7ff8bf409879a4a3857e86199 (patch) | |
| tree | 5337ac070d93c2400b081acfd0a0be498abaf4eb /Library/Homebrew/utils/inreplace.rb | |
| parent | 670128354dcae2ce7405c4c106cceb5585973dc9 (diff) | |
| download | homebrew-4ae9cc42734217e7ff8bf409879a4a3857e86199.tar.bz2 | |
Replace files atomically in inreplace
Diffstat (limited to 'Library/Homebrew/utils/inreplace.rb')
| -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 |
