aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorMax Howell2012-03-16 12:58:39 +0000
committerMax Howell2012-03-16 21:06:17 +0000
commite6cb8cbee92693c96bfcd939f4de55e0875eb507 (patch)
treed844f5d067b1bb3ab9cc61cd4302ddf3c37cedf0 /Library
parent2ace9422bc4c19be2d6a77e21e66c6dbd4c6bd52 (diff)
downloadbrew-e6cb8cbee92693c96bfcd939f4de55e0875eb507.tar.bz2
Pathname.atomic_write
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/cmd/tap.rb6
-rw-r--r--Library/Homebrew/cmd/untap.rb8
-rw-r--r--Library/Homebrew/extend/pathname.rb9
3 files changed, 12 insertions, 11 deletions
diff --git a/Library/Homebrew/cmd/tap.rb b/Library/Homebrew/cmd/tap.rb
index 13d9290e3..6d1a596a6 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 @@ module Homebrew extend self
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 80d38934b..92faf3069 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 @@ module Homebrew extend self
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 bc58c885f..da195e5a8 100644
--- a/Library/Homebrew/extend/pathname.rb
+++ b/Library/Homebrew/extend/pathname.rb
@@ -90,6 +90,15 @@ class Pathname
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