module Sprockets::PathUtils

def atomic_write(filename)

Returns nothing.

end
file.write('hello')
Utils.atomic_write('important.file') do |file|

don't want other processes or threads to see half-written files.
Public: Write to a file atomically. Useful for situations where you
def atomic_write(filename)
  dirname, basename = File.split(filename)
  basename = [
    basename,
    Thread.current.object_id,
    Process.pid,
    rand(1000000)
  ].join('.')
  tmpname = File.join(dirname, basename)
  File.open(tmpname, 'wb+') do |f|
    yield f
  end
  FileUtils.mv(tmpname, filename)
ensure
  FileUtils.rm(tmpname) if File.exist?(tmpname)
end