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
commitfa215d34e91d9271debd2e4418562adabbb19eb8 (patch)
tree9a75d69fe1a5147934ac868007d9a6d6f85f6a19 /Library/Homebrew/extend
parent0ec3aefcfeb2a2912ef479a502089bd16df3fa7a (diff)
downloadhomebrew-fa215d34e91d9271debd2e4418562adabbb19eb8.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