lib/hx.rb in hx-0.7.1 vs lib/hx.rb in hx-0.7.2

- old
+ new

@@ -23,10 +23,11 @@ require 'rubygems' require 'thread' require 'set' require 'pathname' +require 'tempfile' require 'yaml' module Hx VERSION = (Pathname.new(__FILE__).parent.parent + 'VERSION').read.strip @@ -562,11 +563,18 @@ write_file(pathname, content) true end def self.write_file(pathname, content) - pathname.parent.mkpath() - pathname.open("wb") { |stream| stream << content.to_s } + parent = pathname.parent + parent.mkpath() + tempfile = Tempfile.new('.hx-out', parent.to_s) + begin + File.open(tempfile.path, "wb") { |stream| stream << content.to_s } + File.rename(tempfile.path, pathname.to_s) + ensure + tempfile.unlink + end nil end class LazyContent def initialize(&block)