aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/extend
diff options
context:
space:
mode:
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