diff --git a/Library/Homebrew/cmd/tap.rb b/Library/Homebrew/cmd/tap.rb index 13d9290e368d..6d1a596a6087 100644 --- a/Library/Homebrew/cmd/tap.rb +++ b/Library/Homebrew/cmd/tap.rb @@ -1,4 +1,3 @@ -require 'tempfile' HOMEBREW_LIBRARY = HOMEBREW_REPOSITORY/"Library" @@ -43,10 +42,7 @@ def link_tap_formula formulae end end - tf = Tempfile.new("brew-tap") - tf.write(ignores.uniq.join("\n")) - tf.close - mv tf.path, "#{HOMEBREW_LIBRARY}/Formula/.gitignore" + HOMEBREW_LIBRARY.join("Formula/.gitignore").atomic_write(ignores.uniq.join("\n")) end private diff --git a/Library/Homebrew/cmd/untap.rb b/Library/Homebrew/cmd/untap.rb index 80d38934b000..92faf3069db8 100644 --- a/Library/Homebrew/cmd/untap.rb +++ b/Library/Homebrew/cmd/untap.rb @@ -1,5 +1,4 @@ -require 'cmd/tap' # for Pathname.recursive_formula -require 'tempfile' +require 'cmd/tap' # for tap_args module Homebrew extend self def untap @@ -18,9 +17,6 @@ def untap end rm_rf tapd - tf = Tempfile.new("brew-untap") - tf.write(gitignores.join("\n")) - tf.close - mv tf.path, "#{HOMEBREW_PREFIX}/Library/Formula/.gitignore" + HOMEBREW_REPOSITORY.join("Library/Formula/.gitignore").atomic_write(gitignores * "\n") end end diff --git a/Library/Homebrew/extend/pathname.rb b/Library/Homebrew/extend/pathname.rb index bc58c885fd4a..da195e5a86bc 100644 --- a/Library/Homebrew/extend/pathname.rb +++ b/Library/Homebrew/extend/pathname.rb @@ -90,6 +90,15 @@ def write content File.open(self, 'w') {|f| f.write content } end + # NOTE always overwrites + def atomic_write content + require 'tempfile' + tf = Tempfile.new(self.basename.to_s) + tf.write(content) + tf.close + FileUtils.mv tf.path, self.to_s + end + def cp dst if file? FileUtils.cp to_s, dst