From e6cb8cbee92693c96bfcd939f4de55e0875eb507 Mon Sep 17 00:00:00 2001 From: Max Howell Date: Fri, 16 Mar 2012 12:58:39 +0000 Subject: Pathname.atomic_write --- Library/Homebrew/extend/pathname.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'Library/Homebrew/extend') 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 -- cgit v1.2.3