aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/extend
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/Homebrew/extend
parent2ace9422bc4c19be2d6a77e21e66c6dbd4c6bd52 (diff)
downloadbrew-e6cb8cbee92693c96bfcd939f4de55e0875eb507.tar.bz2
Pathname.atomic_write
Diffstat (limited to 'Library/Homebrew/extend')
-rw-r--r--Library/Homebrew/extend/pathname.rb9
1 files changed, 9 insertions, 0 deletions
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